-
Notifications
You must be signed in to change notification settings - Fork 0
/
original-file.js
164 lines (149 loc) · 5.58 KB
/
original-file.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
const Discord = require("discord.js");
const bot = new Discord.Client();
const config = require("./config.json");
bot.on('ready',() => {
console.log('I am ready!');
});
bot.on("guildMemberAdd", member =>{
let guild = member.guild;
guild.defaultChannel.sendMessage(`welcome ${member.user} to the land of coding`).catch(console.error);
});
bot.on("guildMemberRemove", member => {
let guild = member.guild;
guild.defaultChannel.sendMessage(`goodbye ${member.user}.`).catch(console.error);
});
bot.on("guildCreate", guild => {
console.log(`New guild added : ${guild.name}, owned by ${guild.owner.user}`).catch(console.error);
});
bot.on('reconnecting', () => {
console.log(`recconecting at ${new Date()}`);
});
bot.on('message', message => {
if(message.author.bot) return;
if(!message.content.startsWith(config.prefix))return;
let channel = message.channel;
let guild = message.guild;
let text = message.content;
let command = message.content.split(" ")[0];
command = command.slice(config.prefix.length);
let args = message.content.split(" ").slice(1);
if (command == "ping") {
// msg.delete()
startTime = Date.now();
channel.sendMessage("Pinging...").then((msg) => {
endTime = Date.now();
msg.edit("Yes im on and its been **=>** *" + Math.round(endTime - startTime) + "* ms since you had to say ping");
});
}
if (command === 'embed') {
let modRole = message.guild.roles.find("name", "ADMIN");
if(!message.member.roles.has(modRole.id)) {
return message.reply("pleb ur not admin").catch(console.error);
}
let args = message.content.split(" ").slice(1);
let text = args[0];
message.channel.sendEmbed({
color: 0xFFFFFF,
title: args.join(`${text}`),
});
}
if (command === "add") {
let numArray = args.map(n=> parseInt(n));
let total = numArray.reduce( (p, c) => p+c);
message.channel.sendMessage(total).catch(console.error);
}
if (command == "purge") {
var amount = parseInt(args[1]);
msg.channel.fetchMessages({limit: amount})
.then(messages => {
messages.map(msg => msg.delete().catch(console.error) );
}).catch(console.error);
} else if (command == "clear") { //p delets your messages. purge deletes everyones messages.
let delamount = parseInt(args[1]) ? parseInt(args[1]) : 1;
msg.channel.fetchMessages({limit: 100})
.then(messages => {
msgar = messages.array();
msgar = msgar.filter(msg => msg.author.id === bot.user.id);
msgar.length = delamount + 1;
msgar.map(msg => msg.delete().catch(console.error));
});
}
if (command === "addrole") {
let modRole = message.guild.roles.find("name", "ADMIN");
let userToKick = message.mentions.users.first();
if(!message.member.roles.has(modRole.id)) {
return message.reply("pleb ur not admin").catch(console.error);
}
let role = msg.guild.roles.find("name", "Team Mystic");
// Let's pretend you mentioned the user you want to add a role to (!addrole @user Role Name):
let member = msg.guild.member(msg.mentions.users.first());
// or the person who made the command: let member = msg.member;
// Add the role!
member.addRole(role).catch(console.error);
}
if (command === "say"){
message.channel.sendMessage(args.join(" ")).catch(console.error);
}
if (command === "purge") {
let modRole = message.guild.roles.find("name", "ADMIN");
if(!message.member.roles.has(modRole.id)) {
return message.reply("pleb ur not admin").catch(console.error);
}
let messagecount = parseInt(params[0]);
message.channel.fetchMessages({limit: messagecount})
.then(messages => message.channel.bulkDelete(messages));
}
if (command === "kick") {
let modRole = message.guild.roles.find("name", "ADMIN");
if(!message.member.roles.has(modRole.id)) {
return message.reply("pleb ur not admin").catch(console.error);
}
if(message.mention.user.size === 0) {
return message.reply("please mention a user to kick").catch(console.error);
}
let kickMember = message.guild.member(message.mentions.users.first());
if(!kickMember) {
return message.reply("that user dont exist bOi").catch(console.error);
}
if(!message.guild.member(bot.user).hasPermission("KICK_MEMBERS")) {
return message.reply("i dont have the permission (KICK_MEMBER) to do this :sadface:").catch(console.error);
}
kickMember.kick().then(member => {
message.reply(`${member.user.username} was kicked.`).catch(console.error);
}).catch(console.error)
}
if (command === "eval") {
if(message.author.id !== "226003765889597440") return;
try {
var code = args.join(" ");
var evaled = eval(code);
if (typeof evaled !== "string")
evaled = require("util").inspect(evaled);
message.channel.sendCode("xl", clean(evaled));
} catch(err) {
message.channel.sendMessage(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
}
}
if (command === "newrole") {
let modRole = message.guild.roles.find("name", "ADMIN");
let userToKick = message.mentions.users.first();
if(!message.member.roles.has(modRole.id)) {
return message.reply("pleb ur not admin").catch(console.error);
}
let args = message.content.split(" ").slice(1);
let color = args[0];
let hoist = args[1] === "yes" || args[1] === "true" ? true : false; // google "ternary if javascript"
let rolename = args.slice(2).join(" "); // remove first 2 args, then join array with a space
guild.createRole()
.then( newrole => {
newrole.edit({hoist: hoist, name: rolename, color: color})
}).catch(console.error);
}
}); // END message handler
function clean(text) {
if (typeof(text) === "string")
return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
else
return text;
}
bot.login(config.token);