-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
178 lines (146 loc) · 5.63 KB
/
app.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
//Packages
const Discord = require("discord.js");
const client = exports.client = new Discord.Client();
const ini = require('ini');
const fs = require('fs');
var token;
exports.loadConf = loadConf = function(){
//Config
let needrs = false;
if(!fs.existsSync('./config/config.ini')){
try{
fs.copyFileSync('./config/example.config.ini','./config/config.ini')
console.log("Copied the example config to 'config/config.ini' Please adjust all config values and restart the program.")
needrs = true;
}
catch(error){
if(error.code == "ENOENT"){
console.log("No config exists, and no example config exists to copy! Please download the config file template from my github. https://github.com/Sheemap/Snazbot")
needrs = true;
}
}
}
if(!fs.existsSync('./config/blacklist.ini')){
try{
fs.copyFileSync('./config/example.blacklist.ini','./config/blacklist.ini')
console.log("Copied the example blacklist to 'config/blacklist.ini'")
}
catch(error){
if(error.code == "ENOENT"){
console.log("No blacklist exists, and no example blacklist exists to copy! Please download the blacklist file template from my github. https://github.com/Sheemap/Snazbot")
needrs = true;
}
}
}
if(needrs)
process.exit();
exports.config = config = ini.parse(fs.readFileSync('./config/config.ini', 'utf-8'))
token = config.general.token;
exports.prefix = prefix = config.general.commandprefix;
exports.autoclean = autoclean = config.general.autoclean;
exports.logdir = logdir = config.general.logdir;
exports.loglevel = loglevel = config.general.loglevel;
exports.admins = admins = config.general.admins.split(',');
//Meme config
exports.memechan = memechan = config.meme.memechan;
exports.buffer = buffer = config.meme.buffer;
exports.maxvote = maxvote = config.meme.maxvote;
exports.startscore = startscore = config.meme.startscore;
exports.rollchan = rollchan = config.meme.rollchan;
exports.albumhash = albumhash = config.meme.albumhash;
//Chungus config
exports.chungusrole = chungusrole = config.chungus.chungusrole;
exports.chunguschan = chunguschan = config.chungus.channel;
exports.chunguscd = chunguscd = config.chungus.maxcd;
//Deceit config
exports.deceitusers = deceitusers = config.deceit.users.split(',');
}
//Load config
loadConf();
//Cusom Packages
const logger = require("./includes/logger.js");
var comm;
var voting;
var meme;
var filter;
//Import DB before most
const DBNAME = "data";
const db = require(`./includes/db.js`);
if (fs.existsSync(`data/${DBNAME}.db`)) {
db.init(DBNAME,dbCallback);
}else{
db.createNew(DBNAME,dbCallback);
}
function dbCallback(){
comm = require("./includes/commandHandle.js");
voting = require("./includes/commands/afk.js");
meme = require("./includes/commands/meme.js");
filter = require("./includes/commands/christianserver.js");
commEvents = comm.events;
if(fs.existsSync('data/christ.txt')){ // The appendix of Snazbot
exports.christ = christ = true; // Test commit plz ignore, no appendix plz
}else{
exports.christ = christ = false;
}
if(autoclean == 'yes'){
logger.log('info','Autocleaning messages is enabled.')
}else{
logger.log('info','Autocleaning messages is disabled.')
}
client.login(token);
}
client.on('ready', () => {
exports.BOTID = BOTID = client.user.id;
logger.log('info',`Logged in as ${client.user.tag}`);
});
client.on('message', msg => {
if(msg.author.id == this.BOTID || typeof(msg.channel.guild) === 'undefined'){
return;
}
db.storeUserData(msg.member, function(err, row){
comm.msg(msg);
if(msg.content.startsWith(prefix)){
comm.parse(msg);
}
if(msg.guild !== null){
if(!msg.content.toLowerCase().includes('jim') && msg.guild.id == '384946871103258626' && msg.author.id != BOTID){
msg.delete();
logger.log('info','Offending Jim message from '+msg.author.username);
}
}
});
});
client.on('messageReactionAdd', (reaction,user) => {
comm.react(reaction,user,true);
})
client.on('messageReactionRemove', (reaction,user) => {
comm.react(reaction,user,false);
})
client.on('messageUpdate', (omsg,nmsg) => {
if(nmsg.guild !== null){
if(!nmsg.content.toLowerCase().includes('jim') && nmsg.guild.id == '384946871103258626' && nmsg.author.id != BOTID){
nmsg.delete();
logger.log('info','Offending Jim edit from '+nmsg.author.username);
}
}
})
client.on('guildMemberAdd', member => {
if(member.guild.id == '384946871103258626'){
let rollid = member.guild.roles.get('384948011106697216');
member.addRole(rollid).catch(logger.log('error',`Failed to Jim ${member.user.username}!`));
member.setNickname('Jim');
logger.log('info',`Successfully Jimmed ${member.user.username}`);
}
});
client.on('voiceStateUpdate', (oldMember, newMember) => {
if(newMember.guild.id == "104981147770990592"){
if(newMember.voiceChannelID == "359575807297060875"){
newMember.addRole('360186010728005652')
logger.log('debug',`Entered ${newMember.user.username} into the spankbank`)
}else{
newMember.removeRole('360186010728005652')
logger.log('debug',`Removed ${newMember.user.username} from the spankbank`)
}
}
});
client.on('error', (err) => logger.log('error', err));