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
/
index.js
200 lines (184 loc) · 7.79 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
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
const Discord = require('discord.js');
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_BANS, Discord.Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, Discord.Intents.FLAGS.GUILD_INTEGRATIONS, Discord.Intents.FLAGS.GUILD_WEBHOOKS, Discord.Intents.FLAGS.GUILD_PRESENCES, Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Discord.Intents.FLAGS.DIRECT_MESSAGES, Discord.Intents.FLAGS.DIRECT_MESSAGE_REACTIONS] });
const config = require('./config.json');
const swearjar = require('swearjar');
const fs = require('fs');
var startTime = performance.now();
client.commands = new Discord.Collection();
const cooldowns = new Discord.Collection();
const MongoClient = require('mongodb').MongoClient;
const offenses = require('./commands/offenses');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
client.prefix = config.prefix;
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
async function logData(message){
const user = await client.dbInstance.collection("users").findOne({ uuid: message.author.id})
if (user == null){
const china = { uuid: message.author.id, balance: 1000, offenses: 0}
client.dbInstance.collection("users").insertOne(china);
console.log("entry made to ",message.author.id)
}
else{
}
}
async function exeCommand(command, message, args) {
await command.execute(message, args);
}
async function databaseConnect(){
databaseClient = await new MongoClient(config.databaseURL, { useNewUrlParser: true, useUnifiedTopology: true });
await databaseClient.connect(err => {
if(err) return console.log(err)
client.dbInstance = databaseClient.db(config.databaseName);
client.login(config.token)
});
}
databaseConnect()
client.once('ready', async () => {
var endTime = performance.now();
var totalTime=endTime-startTime;
console.log("bot took "+totalTime +"ms to load")
});
let replies = {
"kacper": "sugma" //autoreply system based on keywords
};
client.on("messageCreate", async message => {
if (message.author.bot) {return}; //don't include bots
logData(message)
isBad(message)
//isGood(message)
if (message.content in replies) {
message.reply(replies[message.content]); //seperate client.on for let replies
return;
}
});
// kacper and kaylon, start modifying this
async function isBad(message) {
const userid = message.author.id
let messageString= message.content.toLowerCase();
if (swearjar.profane(messageString) && (messageString.includes("china")||messageString.includes("ccp")||messageString.includes("trash")||messageString.includes("bad"))) {
let user = await message.client.dbInstance.collection('users').findOne({uuid:userid});
let usrOffenses = user.offenses+1; // adds one to include new strike in deduction
const deduct = -Math.abs(10*(usrOffenses > 5 ? 5 : usrOffenses)); // multipler caps at 5 strikes
await message.client.dbInstance.collection('users').updateOne(
{ uuid: userid },
{
$inc: {balance: deduct, offenses: 1}
}
)
console.log(user.balance)
console.log(`deducted 10 from ${userid}`)
message.channel.send(`${deduct} social credit <@!${userid}> | Strikes: ${usrOffenses}`)
try{
console.log("deez")
}
catch{
return
}
}else{
isGood(message)
}
}
async function isGood(message) {
let messageString = message.content.toLowerCase();
if (
((messageString.includes("good") || messageString.includes("awesome") ||messageString.includes("cool") || messageString.includes("love") ) && (messageString.includes("china")))
) {
//score the bitch
const userid = message.author.id;
let user = await message.client.dbInstance.collection('users').findOne({uuid:userid});
const uOffneses = user.offenses
// super fucking scuff code, dont touch unless you know how to make it better | this is real youre just dumb bag
userU = await message.client.dbInstance.collection("users").updateOne(
{ uuid: userid },
{
$inc: {balance: 10 }
}
);
const takeaway = user.offenses*0
userU = await message.client.dbInstance.collection("users").updateOne(
{ uuid: userid },
{
$inc: {offenses: user.offenses > 0 ? -1 : 0} // prevents offenses from going negative
}
);
console.log(`added 10 to ${userid}`);
message.reply(`+10 social credit <@!${userid}>`);
} else {
}
}
client.on('messageCreate', async message => {
if (!(message.content.startsWith(client.prefix) || message.mentions.users.first() == client.user) || message.author.bot) return;
if (message.content.startsWith(client.prefix)) {
args = message.content.slice(client.prefix.length).split(/ +/);
} else {
args = message.content.slice(client.prefix.length).split(/ +/).slice(1);
}
let commandName;
if (args) {
commandName = args.shift().toLowerCase();
}
const command = await client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000;
if (timestamps.has(message.author.id)) {
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`)
.then(msg => {
setTimeout(function () {
try {
msg.delete();
} catch (error) { }
}, 5000);
});
}
timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
}
try {
if (command.guildOnly && message.channel.type !== 'GUILD_TEXT') {
return message.reply('I can\'t execute that command inside DMs or threads!');
}
if (command.args && !args.length) {
const commandhelp = client.commands.get("help");
const argshelp = [command.name];
commandhelp.execute(message, argshelp)
} else {
if (command.needsmod) {
let isMod = false;
modRoles.forEach(element => {
if (currentMember.roles.cache.has(element) || currentMember.permissions.has(['ADMINISTRATOR'])) {
isMod = true;
}
if (isMod) return;
});
if (!isMod) {
return;
} else {
exeCommand(command, message, args);
}
} else if (command.needsadmin) {
if (currentMember.permissions.has(['ADMINISTRATOR']) || message.author.id == ownerID) {
exeCommand(command, message, args);
return;
} else {
}
} else {
exeCommand(command, message, args);
}
}
} catch (error) {
console.error(`Command perms check: ${error}`);
message.reply('there was an error trying to execute that command!');
}
});