This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
165 lines (144 loc) · 4.48 KB
/
bot.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
require("dotenv").config();
const Discord = require("discord.js");
const { decodeUsername } = require("./lib/discord");
const levelNo = require("./lib/level-no");
const client = new Discord.Client();
const models = require("./models");
client.on("ready", () => {
console.log("I am ready!");
});
const verification = async (message) => {
try {
// Check if the message mentions the bot
if (!message.mentions.has(client.user.id)) return;
const { author, member } = message;
const verified = member.roles.cache.some((r) => r.name === "Verified");
if (verified) return;
// Check if user is in database
const user = await models.User.findOne({ where: { discordId: author.id } });
if (user) {
const role = message.guild.roles.cache.find(
(r) => r.name === "participant"
);
// Add the role!
await member.roles.add(role);
await member.setNickname(user.name);
message.channel.send(`${author.toString()} verified`);
return;
}
message.channel.send(
`${author.toString()} please verify your Discord account on https://intra.sudocrypt.com/auth/discord`
);
} catch (e) {
message.channel.send(`${message.author.toString()} an error occurred`);
console.error(e);
}
};
const lookup = async (message) => {
try {
if (!message.content.startsWith("!lookup")) return;
const [username, discriminator] = decodeUsername(message.content);
const user = await models.User.findOne({
where: {
discordUsername: username,
discordDiscriminator: discriminator,
},
});
if (!user) {
message.channel.send(
`User with username ${username}, discrimator ${discriminator} not found`
);
return;
}
// message.channel.send(`https://intra.sudocrypt.com/users/${user.username}`);
const userEmbed = new Discord.MessageEmbed()
.setTitle(user.username)
.addFields(
{
name: "Name",
value: user.name,
},
{
name: "Email",
value: user.email,
},
{
name: "Phone",
value: user.phone,
},
{
name: "Level",
value: (await levelNo(user.currentLevelId)) - 1,
},
{
name: "Finished",
value: user.finished ? "Yes" : "No",
},
{
name: "Points",
value: `${user.points}`,
}
)
.setURL(`https://intra.sudocrypt.com/users/${user.username}`)
.setThumbnail(user.photo);
message.channel.send(userEmbed);
} catch (e) {
message.channel.send(`${message.author.toString()} an error occurred`);
console.error(e);
}
};
const dq = async (message) => {
try {
message.member.roles.cache.some(async r =>{ if(r.name=="admin"){
const [username, discriminator] = decodeUsername(message.content);
const user = await models.User.findOne({
where: {
discordUsername: username,
discordDiscriminator: discriminator,
},
});
if (!user) {
message.channel.send(
`User with username ${username}, discrimator ${discriminator} not found`
);
return;
}
user.disqualified = true;
const discordUser = await message.guild.members.fetch(user.discordId);
await user.save();
await discordUser.kick();
// message.channel.send(`https://intra.sudocrypt.com/users/${user.username}`);
message.channel.send(`Successfully disqualified and banned ${user.name}`);
}
else{
message.channel.send(`You are not admin`)
}
});
} catch (e) {
message.channel.send(`${message.author.toString()} an error occurred`);
console.error(e);
}
};
const botCommands = async (message) => {
try {
if (!message.content.startsWith("!leaderboardCount")) return;
const count = await models.User.count({
where: {
admin: false,
exunite: false,
},
});
message.channel.send(`There are ${count} people`);
} catch (e) {
message.channel.send(`${message.author.toString()} an error occurred`);
console.error(e);
}
};
client.on("message", (message) => {
if (message.channel.name === "verification") verification(message);
if (message.channel.name === "discord-lookup") lookup(message);
//if (message.channel.name === "dq") dq(message);
if (message.content.startsWith("!dq")) dq(message);
if (message.channel.name === "bot-commands") botCommands(message);
});
client.login(process.env.DISCORD_BOT_TOKEN);