-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
159 lines (121 loc) · 5.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const botconfig = require("./botconfig.json");
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client({disableEveryone: true});
var Jimp = require("jimp");
const SQLite = require("better-sqlite3");
const sql = new SQLite('./profile.sqlite');
bot.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0){
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});
});
fs.readdir("./others/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0){
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) =>{
let props = require(`./others/${f}`);
console.log(`${f} loaded!`);
});
});
bot.on("ready", async () => {
const profile = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'profile';").get();
if (!profile['count(*)']) {
sql.prepare("CREATE TABLE profile (UserID TEXT PRIMARY KEY, GuildID TEXT, xp INTEGER, lvl INTEGER, coins INTEGER, bg INTEGER, note TEXT, likes INTEGER, rep INTEGER, w0 INTEGER, w1 INTEGER, w2 INTEGER, w3 INTEGER, w4 INTEGER, w5 INTEGER);").run();
}
const rep = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'rep';").get();
if (!rep['count(*)']) {
sql.prepare("CREATE TABLE rep (UserID, LikedUser TEXT PRIMARY KEY, GuildID TEXT, Time TEXT);").run();
}
const liked = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'liked';").get();
if (!liked['count(*)']) {
sql.prepare("CREATE TABLE liked (UserID, LikedUser TEXT PRIMARY KEY, GuildID TEXT, Time TEXT);").run();
}
const about = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'about';").get();
if (!about['count(*)']) {
sql.prepare("CREATE TABLE about (UserID TEXT PRIMARY KEY, career TEXT, age TEXT, club TEXT, model TEXT, study TEXT, future TEXT, life TEXT, words TEXT);").run();
}
bot.setInterval(() =>{
let d = Date.now()
let rep = sql.prepare(`SELECT * FROM rep`).all()
if(!rep)return;
for (var i = 0; i < rep.length ; i++){
if(rep[i].Time < d){
sql.prepare(`DELETE FROM rep WHERE UserID = '${rep[i].UserID}' AND Time = ${rep[i].Time}`).run();
}
}
}, 5000)
});
function generateXp() {
let min = 2
let max = 7
return Math.floor(Math.random() * (max - min + 1)) + min;
}
bot.on("message", async message => {
if (message.author.bot) return;
if (message.channel.type ==="dm") return;
let coinAmt = Math.floor(Math.random() * 3) + 1;
let baseAmt = Math.floor(Math.random() * 3) + 1;
let profile = sql.prepare(`SELECT * FROM profile WHERE UserID = '${message.author.id}'`).get()
let sqlstr;
if(!profile){
sqlstr = `INSERT INTO profile (UserID, GuildID, xp, lvl, coins, bg, note, likes, rep, w0, w1, w2, w3, w4, w5) VALUES ('${message.author.id}', '${message.guild.id}', ${generateXp()}, '1', '0', '1', 'لايوجد', '0', '0', '1', '0', '0', '0', '0', '0')`
}
else if(coinAmt === baseAmt){
let coins = profile.coins
let xp = profile.xp
sqlstr = `UPDATE profile SET coins = ${coins + coinAmt}, xp = ${xp + generateXp()} WHERE UserID = '${message.author.id}'`;
sql.prepare(sqlstr).run();
}
else{
let xp = profile.xp
sqlstr = `UPDATE profile SET xp = ${xp + generateXp()} WHERE UserID = '${message.author.id}'`;
sql.prepare(sqlstr).run();
let curlvl = profile.lvl;
let nxtLvl = profile.lvl * 1000;
if(nxtLvl <= profile.xp){
sqlstr = `UPDATE profile SET lvl = ${curlvl + 1} WHERE UserID = '${message.author.id}'`;
sql.prepare(sqlstr).run();
let lvlico = message.author.displayAvatarURL;
let lvlup = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.displayAvatarURL)
.setThumbnail(lvlico)
.setTitle("LEVEL UP.")
.setColor("#6E0A51")
.addField("Your LEVEL: ", curlvl + 1);
message.channel.send(lvlup).then(msg => {msg.delete(5000)});
}
}
sql.prepare(sqlstr).run();
let about = sql.prepare(`SELECT * FROM about WHERE UserID = '${message.author.id}'`).get()
if(!about){
sqlstr = `INSERT INTO about (UserID, career, age, club, model, study, future, life, words) VALUES ('${message.author.id}', '#منصبي', '#عمري', '#نادي', '#قدوتي', '#تخصصي', '#طموحي', '#حكمتي', '#خاطري')`
sql.prepare(sqlstr).run();
}
let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
//if (message.content.startsWith("Turki Pasha")) return message.reply({files: ["https://cdn.discordapp.com/attachments/417087715444523010/430350204168962050/image.png"]});
//if (message.content.toString()== ".") return message.channel.send("y");
if (!message.content.startsWith(prefix)) return;
let cmd = messageArray[0];
let args = messageArray.slice(1);
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if(commandfile) commandfile.run(bot,message,args, sql);
});
bot.on("ready", () => {
console.log(bot.user.tag)
})
bot.login(botconfig.token);