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
|
const fs = require('fs')
const path = require("path");
let db = require("../src/db");
const { parse_inp } = require("../src/util")
const { channel } = require('diagnostics_channel');
const { PermissionsBitField } = require('discord.js');
const { EmbedBuilder } = require("discord.js");
let settings = require('../src/settings')
let config_loc = __filename+".json"
module.exports = {
name : "messageCreate",
config_loc : config_loc,
async main (client,Discord){
let config = JSON.parse(fs.readFileSync(config_loc))
client.on("messageCreate", async (message) => {
if(message.guild==null)
return require("./dm").main(client,Discord,message)
if(!settings["allowed-servers"].includes(message.guild.id)||message.author.bot||message.member==null)
return;
//handle sticky messages
let stickies = await db.Sticky.findAll();
for(let s of stickies){
if(message.channel.id==s.channel && message.author.id!="762561860150362142"){
let m;
if(s.embed){
let embed = new EmbedBuilder()
.setDescription(s.message)
.setColor(s.embed_color)
m = await message.channel.send({embeds:[embed]})
} else {
m = await message.channel.send(s.message)
}
if(s.last_message!='null'){
try{
let msg = await message.channel.messages.fetch(s.last_message)
msg.delete()
} catch(e){}
}
db.Sticky.update({last_message: m.id},{ where: {id: s.id}})
}
}
//done w/ sticky
//handle auto reactions
let a_react = await db.Auto_React.findAll();
for(let a of a_react){
if(message.channel.id==a.channel && message.author.id!="762561860150362142"){
try{
let m = await message.react(a.emote)
} catch(e){}
}
}
//done w/ auto reactions
//deal with commands
let remove = function(msg) {setTimeout(async()=>{try{await msg.delete()}catch(e){}},config["error-timeout"].value)}
let date = new Date()
let uid = message.member.id;
let mod = message.member.permissions!=null&&message.member.permissions?.has(PermissionsBitField.Flags.KickMembers)
if(message.content.startsWith("sns ")&&(!config["restrict-channels"].value.includes(message.channel.id)||(mod))){
let com_string = message.content.split(" ")
com_string.shift()
let found = false;
let com_call = com_string[0].trim()
//keep this as a for loop incase we want to do sequential commands
for(let com of global.commands){
if(com.command.includes(com_call)){
found = true;
if(com.mod_only&&!mod){
message.reply(config["error-message-auth"].value).then((msg)=>{remove(msg)})
break;
}
com_string.shift()
com_string = parse_inp(com_string.join(" "))
try{
if(((!com.config.restrict||com.config.restrict.length==0||com.config.restrict.includes(message.channel))&&
(!com.config.restricted||com.config.restricted.length==0||!com.config.restricted.includes(message.channel)))||mod)
if(mod||com.config.cooldown==null||com.last_command[uid]==null||(date.getTime()-com.last_command[uid].getTime())/1000>com.config.cooldown){
await com.main(client,Discord,message,com_string,com_call)
com.last_command[uid] = new Date()
} else message.reply("this command is on cooldown for "+((date.getTime()-com.last_command[uid].getTime())/1000).toFixed(2)+"/"+com.config.cooldown+"s").then((msg)=>{remove(msg)})
else
message.reply(config["error-message-not-here"].value).then((msg)=>{remove(msg)})
} catch(e) {
message.reply(config["error-message"].value + "\n```"+e.stack+"```").then((msg)=>{remove(msg)})
console.log(e.stack)
}
break;
}
}
if(!found)
message.reply(config["error-message-not-found"].value).then((msg)=>{remove(msg)})
}
//done w/ commands
})
},
}
|