This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hammylevel.js
256 lines (227 loc) · 9.73 KB
/
hammylevel.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const Discord = require("discord.js");
const util = require('util'); // Loads the util module.
const bot = new Discord.Client();
const fs = require('fs');
let XP = JSON.parse(fs.readFileSync('./XP.json', 'utf8'));
const lynx = "336331925612396547";
const guild2 = "319509297056841728";
const maxlevel = "500";
const DopplerID = "130515926117253122";
const LawlietID = "201848192357236736";
const DarwinID = "307472480627326987";
var cooldownUsers = [];
var cooldownUsers2 = [];
const checkCooldown = ((userId) => {
if(cooldownUsers.indexOf(userId) > -1) {
return true;
} else {
return false;
}
});
const checkCooldown2 = ((userId) => {
if(cooldownUsers2.indexOf(userId) > -1) {
return true;
} else {
return false;
}
});
const removeCooldown = ((userId, timeInSeconds) => {
let index = cooldownUsers.indexOf(userId);
if(index > -1) {
setTimeout(() => {
cooldownUsers = cooldownUsers.splice(index, 0);
}, timeInSeconds * 1000)
}
});
const removeCooldown2 = ((userId, timeInSeconds) => {
let index = cooldownUsers2.indexOf(userId);
if(index > -1) {
setTimeout(() => {
cooldownUsers2 = cooldownUsers2.splice(index, 0);
}, timeInSeconds * 1000)
}
});
bot.on('ready', () => {
console.log("Hamsters level system is online ");
});
bot.on('error', console.error);
bot.on('warn', console.warn);
bot.on('disconnect', event => {
console.log(`[DISCONNECT] Shard ${bot.shard.id}.`);
});
bot.on("message", async (msg) => {
if (msg.channel.type === 'dm') return;
if (msg.author.bot) return;
const fs = require('fs');
let PREF = JSON.parse(fs.readFileSync('./prefix.json', 'utf8'));
if (PREF === undefined) return botcode = "h!"
let prefix = "";
const defaultprefix = "h!";
if (!PREF[msg.guild.id]) PREF[msg.guild.id] = {prefix: defaultprefix}
let botcode = PREF[msg.guild.id].prefix || defaultprefix;
if(!msg.content.startsWith(prefix)) return;
let args = msg.content.split(" ").slice(1);
const Username = msg.author.tag;
let userData = XP[msg.author.id];
if (!userData) userData = {XP: 0, level: 0, Messagecount: 0, User: 0};
//if (Messagecount ) userData = {XP: 0, level: 0, Messagecount: 0};
let userXP = XP[msg.author.id] ? XP[msg.author.id].XP : 0;
let curLevel = Math.floor(0.1 * Math.sqrt(userXP));
if (curLevel > userData.level) {
if (maxlevel < userData.level) return;
userData.level = curLevel;
const embed = new Discord.RichEmbed()
.setColor(0xE69A49)
.setThumbnail("https://vgy.me/3Ge3fL.png")
.setDescription("GG " + msg.author.username + ", you leveled up to **" + curLevel + "**!");
if (msg.guild.id === lynx) return;
if (msg.guild.id === guild2) return;
if (msg.guild.id === "264445053596991498") return;
if (msg.guild.id === "110373943822540800") return;
if (msg.guild.id === "335393678145093642") return;
msg.author.send({embed})
console.log(msg.author.username + "has leveled up to: " + curLevel)
}
if (msg.content.startsWith(botcode + "level")) {
if (msg.guild.id === "335393678145093642") return;
const embed = new Discord.RichEmbed()
.setColor(0xE69A49)
.setTitle(" :hamster: Level Info For: " + msg.author.username + " :hamster: ")
.setThumbnail(msg.author.avatarURL)
.addField("Your Current Level: ", userData.level)
.addField("Total Amount of XP: ", userData.XP + " XP")
.addField("Messages sent: ", userData.Messagecount)
.addField("Awards: ", "None");
let user = msg.mentions.users.first();
if (msg.mentions.users.size < 1) return msg.channel.sendEmbed(embed).catch(console.error);
const embed2 = new Discord.RichEmbed()
.setColor(0xE69A49)
.setTitle(" :hamster: Level Info For: " + user.username + " :hamster: ")
.setThumbnail(user.avatarURL)
.addField(user.username + "'s" + " Current Level: ", XP[user.id].level)
.addField("Total Amount of XP: ", XP[user.id].XP + " XP")
.addField("Messages sent: ", XP[user.id].Messagecount)
.addField("Awards: ", "None");
msg.channel.sendEmbed(embed2)
}
if (msg.content.startsWith(botcode + "awardslevel")) {
const embed2 = new Discord.RichEmbed()
.setColor(0xE69A49)
.setTitle(" :hamster: Awards Info :hamster: ")
.addField(`:tada: - Reach level 50`, "\u200b", true)
.addField(":medal: - Reach level 80", "\u200b", true)
.addField(`:military_medal: - Reach level 250`, "\u200b", true)
.addField(`:trophy: - Reach level 500 (max)`, "\u200b", true)
.addField(`:iphone: - Send a total of 5000 messages`, "\u200b", true)
.addField(`:first_place: - Reach #1 on the leaderboard`, "\u200b", true)
.addField(`:spy::skin-tone-1: - Secret Award`, "\u200b", true)
.addField(`:tophat: - Secret Award`, "\u200b", true)
.addField(`:watch: - Secret Award`, "\u200b", true)
msg.channel.sendEmbed(embed2)
}
if (msg.content.startsWith(botcode + "leaderboard" || botcode + "lb")) {
const embed = new Discord.RichEmbed()
.setColor(0xE69A49)
.setThumbnail(bot.user.avatarURL)
.setTitle(":hamster: Hammys level leaderboard :hamster:")
.addField("#1: ", "Gamer2Master#4879 | level: 64")
.addField("#2: ", "[AquariumFishes] Darwin#0307 | level: 60")
.addField("#3: ", "Ovyerus#2211 | level: 57")
.addField("#4: ", "kek#7783 | level: 55")
.addField("#5: ", "PassTheMayo#1281 | level: 54")
.addField("#6: ", "TripingPC#2094 | level: 53")
.addField("#7: ", "Tolic#5049 | level: 53")
.addField("#8: ", "Roadcrosser#3657 | level: 52")
.addField("#9: ", "[YumiBoat] August#1793 | level: 49")
.addField("#10: ", "ry00001#3487 | level: 49");
msg.channel.send({embed})
}
if (msg.content.startsWith(botcode + "userlevel4534354")) {
let user = message.mentions.users.first();
if (message.mentions.users.size < 1) return message.reply(':x: You must mention someone to ban them. :x:').catch(console.error);
const ID = `${user.id}`
const embed = new Discord.RichEmbed()
.setColor(0xE69A49)
.setTitle(" :hamster: Level Info For: " + user.username + " :hamster: ")
.setThumbnail(user.avatarURL)
.addField("Your Current Level: ", ID.userData.level)
.addField("Total Amount of XP: ", ID.userData.XP + " XP");
//msg.channel.send({embed})
client.users.get(user.id).send(userData.level);
}
if (!XP[msg.author.id]) XP[msg.author.id] = {XP: 0, level: 0, Messagecount: 0, User: 0}
if (msg.content.startsWith("")) {
if(checkCooldown(msg.author.id)) {
return;
}
cooldownUsers.push(msg.author.id);
removeCooldown(msg.author.id, 30);
if (msg.author.bot) return;
if (msg.guild.id === lynx) return;
if (msg.guild.id === guild2) return;
if (msg.guild.id === "264445053596991498") return;
if (msg.guild.id === "110373943822540800") return;
if (msg.guild.id === "335393678145093642") return;
var xpgained = Math.floor(Math.random() * 15) + 1;
userData.XP += xpgained
if (!userData.Messagecount === undefined) userData = {XP: userData.XP, level: userData.level, Messagecount: 0, User: 0}
if (!userData.User === undefined) userData = {XP: userData.XP, level: userData.level, Messagecount: 0, User: 0}
userData.Messagecount += 1
userData.User = msg.author.tag
console.log(msg.author.username + " has gained " + xpgained + "XP");
}
/* if (msg.content.startsWith(botcode + "givexp")) {
if (msg.author.id !== LawlietID || msg.author.id !== DopplerID || msg.author.id !== DarwinID) {
//let user = msg.mentions.users.first();
var xpamount = args.join(' ');
//if (msg.mentions.users.size < 1) return msg.reply(':x: You must mention someone to give xp to them. :x:').catch(console.error);
if (xpamount.length > 5) return msg.channel.send("Can not use more then 5 numbers")
const xpgive = (Math.round(xpamount))
userData.XP += xpgive
msg.channel.send("I have given xp to: " + msg.author.username + " " + xpamount + "XP");
} else {
msg.channel.send("You're not whitelisted to use this cmd")
}
} else
if (msg.content.startsWith(botcode + "takexp")) {
if (msg.author.id === LawlietID) return;
if (msg.author.id === DopplerID) return;
if (!msg.member.hasPermission("ADMINISTRATOR")) {
msg.channel.send("You do not have permission to use this cmd")
} else {
let user = msg.mentions.users.first();
var xpamount2 = args.join(' ');
if (msg.mentions.users.size < 1) return msg.reply(':x: You must mention someone to give xp to them. :x:').catch(console.error);
if (xpamount2.length > 5) return msg.channel.send("Can not use more then 5 numbers")
const xpgive = (Math.round(xpamount2))
XP[user.id] -= xpgive
msg.channel.send("I have given xp to: " + msg.author.username + " " + xpamount2 + "XP");
}
} */
if (msg.content.startsWith(botcode + "dailyxp")) {
if(checkCooldown2(msg.author.id)) {
msg.channel.send("Sorry! You have already claimed your daily free xp please wait 24 hours to claim again.");
return;
}
cooldownUsers2.push(msg.author.id);
removeCooldown2(msg.author.id, 1440);
if (msg.author.bot) return;
userData.XP += 250
msg.channel.send("You have recived your free daily 250 xp, wait another 24 hours to claim!");
}
/* if(msg.content.startsWith(antiinvite)) {
msg.delete();
//const swearWords = ["darn", "shucks", "frak", "shite"];
const embed = new Discord.RichEmbed()
.setColor(0xE69A49)
.addField('Moderated User:', 'Automated violation')
.addField('Moderator:', `${message.author.username}#${message.author.discriminator}`)
.addField('Actions Taken:', 'Invite Block')
.addField('Reason Provided:', 'Sending invites is not allowed in guild')
msg.channel.send({embed})
} */
console.log("Data Writing")
fs.writeFileSync('./XP.json', JSON.stringify(XP), console.error);
console.log("Data Writen")
});
bot.login('your bot token');