forked from xela-zone/Discord-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbugbot.js
More file actions
200 lines (173 loc) · 7.67 KB
/
Copy pathbugbot.js
File metadata and controls
200 lines (173 loc) · 7.67 KB
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
"use strict";
const Eris = require('eris');
const config = require('./config');
const customConfig = require('./configEdit');
const commandList = require('./src/commandList')();
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./data/data.sqlite');
const utils = require("./src/utils");
const modUtils = require('./src/modUtils');
const backup = require('./src/backup');
const dateFormat = require('dateformat');
const fs = require('fs');
let Trello = require('node-trello');
var trello = new Trello(customConfig.trelloKey, customConfig.trelloToken);
let bot = new Eris(customConfig.botToken, {
getAllUsers: true
});
bot.on('error', err => {
let newDate = new Date();
let currentTime = dateFormat(newDate, "UTC:mm-dd-yyyy-HH-MM");
console.log("BOT ERROR:\n" + err.stack);
});
let reconnect = false;
bot.on("ready", () => {
console.log('───────────────────────\nReady! PID: ' + process.pid);
db.run("CREATE TABLE IF NOT EXISTS reports (id INTEGER, header TEXT, reportString TEXT, userID TEXT, userTag TEXT, cardID TEXT, reportStatus TEXT, trelloURL TEXT, canRepro INTEGER, cantRepro INTEGER, reportMsgID TEXT, timestamp TEXT)");
db.run("CREATE TABLE IF NOT EXISTS reportQueueInfo (id INTEGER, userID TEXT, userTag TEXT, info TEXT, stance TEXT)");
db.run("CREATE TABLE IF NOT EXISTS reportAttachments (id INTEGER, userID TEXT, userTag TEXT, attachment TEXT)");
db.run("CREATE TABLE IF NOT EXISTS users (userID TEXT, xp INTEGER, windows TEXT, ios TEXT, android TEXT, macOS TEXT, linux TEXT, reproDailyNumb INTEGER, ADdailyNumb INTEGER, hugDailyNumb INTEGER, trackReport BOOLEAN, bhjoindate TEXT)");
bot.createMessage(config.channels.modLogChannel, "I heard there are bugs that needs reporting. I'm online and ready to rumble!");
if(reconnect === false) {
//run loops
backup(bot);
reconnect = true;
}
});
commandList.add('addNote');
commandList.add('addRoles');
commandList.add('adminCommands');
commandList.add('approveDeny');
commandList.add('attachment');
commandList.add('edit');
commandList.add('modCommands');
commandList.add('how_I_Learned_To_Stop_Worrying_And_Love_bot_Commands');
commandList.add('reproductions');
commandList.add('revoke');
commandList.add('storeInfo');
commandList.add('submit');
//commandList.add('utilCommands');
function userHasRole(user, role) {
return user.roles.some(memberRole => memberRole === role);
}
function userHasAuthorityForCommand(user, command) {
if(command.roles.some(role => role == config.roles.everybodyRole)) {
return true;
}
return command.roles.some(role => userHasRole(user, role));
}
function correctChannel(guildChannel, channel){
return guildChannel.id === channel;
}
function correctChannelIsBeingUsed(guild, command) {
if(command.channels.some(channel => channel === config.channels.allChannels)){
return true;
}
return command.channels.some(channel => correctChannel(guild, channel));
}
function checkIfDM(command) {
if(command.acceptFromDM === true) {
return true;
}
}
let delMsgCooldown = false;
bot.on('messageCreate', (msg) => {
let messageSplit = msg.content.split(' ');
let command = messageSplit.shift();
if(!!msg.channel.guild && msg.channel.guild.id !== config.DTserverID) {
return;
}
let userTag = msg.author.username + "#" + msg.author.discriminator;
let userID = msg.author.id;
let channelID = msg.channel.id;
let thisMember = msg.member;
if(!msg.channel.guild) {
let getGuild = bot.guilds.get(config.DTserverID);
let getMember = getGuild.members.get((msg.author.id));
thisMember = getMember;
}
if(command.match(/^!/)) {
let matchingCommand = commandList.find(command);
if(!msg.channel.guild && matchingCommand.acceptFromDM !== true) {
return;
}
//check for roles
if(userHasAuthorityForCommand(thisMember, matchingCommand)) {
//check for channel
if(correctChannelIsBeingUsed(msg.channel, matchingCommand)){
if(!userTag) {
let thisDate = new Date();
let cTime = dateFormat(thisDate, "GMT:mm-dd-yyyy-HH-MM");
console.log(`${cTime} userTag - command\n${userTag} ${command}`);
}
matchingCommand.execute(bot, channelID, userTag, userID, command, msg, trello, db);
} else {
//Tell the user they're posting the command in the wrong channel?
}
}else {
// Add channel check
//Tell the user they don't have permission for that command
if(command === "!attach") {
utils.botReply(bot, userID, channelID, "you do not have access to that command", command, msg.id, true);
}
}
}else {
if(!!msg.channel.guild) {
let isRightChannel = channelID === config.channels.queueChannel || channelID === config.channels.iosChannel || channelID === config.channels.linuxChannel || channelID === config.channels.androidChannel || channelID === config.channels.canaryChannel;
let isNotMod = msg.member.roles.indexOf(config.roles.devRole) && msg.member.roles.indexOf(config.roles.adminRole) && msg.member.roles.indexOf(config.roles.trelloModRole);
let isNotBot = userID !== config.botID;
if(isNotBot && isNotMod === -1 && isRightChannel) {
//Delete and say commands only on delay
bot.deleteMessage(channelID, msg.id);
if(delMsgCooldown === false){
delMsgInReportingChannel(channelID, userID);
}
}
} else {
if(thisMember.roles.indexOf(config.roles.initiateRole) !== -1 && thisMember.roles.indexOf(config.roles.hunterRole) === -1) {
if(msg.content.toLowerCase() === customConfig.BHphrase) {
let getHunterRole = thisMember.roles;
let indexOfInitiateRole = getHunterRole.indexOf(config.roles.initiateRole);
getHunterRole.splice(indexOfInitiateRole, 1);
getHunterRole.push(config.roles.hunterRole);
bot.editGuildMember(config.DTserverID, userID, {
roles: getHunterRole
}).then(() => {
bot.getMessages(config.channels.charterChannel).then((allMsgs) => {
let thisMsg = allMsgs.find(function(msgs) {
return msgs.author.id === config.botID && msgs.content.indexOf(`<@${userID}>`) > -1;
});
if(!!thisMsg) {
bot.deleteMessage(config.channels.charterChannel, thisMsg.id).catch(() => {});
}
});
/*
db.get('SELECT userID FROM users WHEN userID = ?', [userID], function(err, reply) {
if(!!err) {
console.log("BH user add\n" + err);
}
if(!!reply) {
db.run('UPDATE users SET bhjoindate = datetime() WHERE userID = ?', [userID]);
} else {
db.run('INSERT INTO users (userID, bhjoindate) VALUES(?, datetime())', [userID]);
}
}); */
bot.createMessage(config.channels.bugHunterChannel, `Welcome <@${userID}> to the Bug Hunters:tm:!`);
bot.createMessage(config.channels.modLogChannel, `<:evilDabbit:233327051686412288> **${userTag}** just did the do and became a Bug Hunter:tm:!`);
});
}
}
}
}
});
// Tell the user that they can only post commands in the reporting channel
function delMsgInReportingChannel(channelID, userID) {
bot.createMessage(channelID, "<@" + userID + "> only bot-commands are allowed in this channel. Please review <#342060723721207810> if you're unsure of the commands.").then(utils.delay(customConfig.delayInS)).then((msgInfo) => {
bot.deleteMessage(channelID, msgInfo.id);
}); // Needs text for user reply when chatting in bug reporting channel
delMsgCooldown = true;
setTimeout(function () {
delMsgCooldown = false;
}, 8000);
}
bot.connect();