Skip to content

Commit f24c986

Browse files
Merge pull request #2 from IDeletedSystem64/TMC-Software-v5
Merge changes from TMC-Software/TheCodingBot
2 parents a8b6885 + 967ce6d commit f24c986

41 files changed

Lines changed: 2016 additions & 555 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 180 additions & 284 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"ascii-table": "^0.0.9",
2121
"async-queue": "^0.1.0",
2222
"canvas": "^2.8.0",
23-
"cli-progress": "^3.9.0",
24-
"colors": "^1.4.0",
2523
"discord.js": "^13.3.1",
2624
"node-fetch": "^2.6.1",
2725
"node-os-utils": "^1.3.6",

src/app/cfg/app.js

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const app = {
3636
}
3737
},
3838

39+
types: {
40+
channels: {
41+
GUILD_TEXT: "Text Channel",
42+
GUILD_VOICE: "Voice Channel",
43+
GUILD_CATEGORY: "Category",
44+
GUILD_NEWS: "News Channel",
45+
GUILD_STAGE_VOICE: "Stage Channel"
46+
}
47+
},
48+
3949
functions: {
4050
sleep: function(ms) {
4151
return new Promise(resolve => setTimeout(resolve, ms));
@@ -123,6 +133,24 @@ const app = {
123133
app.logger.warn("DB", `Server data for ${id} removed from database!`);
124134

125135
return serverSetting;
136+
},
137+
138+
createVerification: async function(serverID, userID, messageID, codeGenerated) {
139+
const verificationSetting = await app.DBs.verification.create({
140+
serverID: serverID,
141+
userID: userID,
142+
messageID: messageID,
143+
userCode: codeGenerated
144+
});
145+
app.logger.success("DB", `Verification started for ${userID} in ${serverID} with code ${codeGenerated}!`);
146+
147+
return verificationSetting;
148+
},
149+
deleteVerification: async function(serverID, userID) {
150+
const verificationSetting = await app.DBs.verification.destroy({ where: { userID: userID, serverID: serverID } });
151+
app.logger.warn("DB", `Verification data for ${userID} in ${serverID} removed from database!`);
152+
153+
return verificationSetting;
126154
}
127155
},
128156
downloadAttachments: async function(message, attachments) {
@@ -172,7 +200,7 @@ const app = {
172200
command.permissions != "BOT_OWNER" && message.member.permissions.has(command.permissions))
173201
},
174202

175-
missingPerms: function(message, cantdo, command) {
203+
missingPerms: function(message, edit, cantdo, command) { // 0 = Send, 1 = Edit
176204
var lackedPerms = [];
177205
if (command) {
178206
for (var i = 0; i < command.permissions.length; i++) {
@@ -194,16 +222,27 @@ const app = {
194222
title: `${app.config.system.emotes.error} **Missing Permissions**`,
195223
color: app.config.system.embedColors.red,
196224
description: `You're lacking ${lackedPerms} to ${cantdo}.\nSorry about that...`,
197-
footer: { text: app.config.system.footerText }
198225
}]
199-
}, 0, true);
226+
}, edit, true);
200227
},
201228
msgHandler: async function(message, options, action = 0, doReply = false, callback = null) { // action: 0 = Send, 1 = Edit
229+
if (options.embeds) {
230+
if (options["author"] != null) {
231+
var author = options["author"];
232+
if (author.id)
233+
options.embeds[0]["author"] = { name: `Hello, ${author.tag}!`, icon_url: author.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 }) };
234+
delete options["author"];
235+
};
236+
if (!options.embeds[0]["footer"]) options.embeds[0]["footer"] = { text: app.config.system.footerText }; // Install branding.exe
237+
};
238+
202239
if (action == 0) {
203240
if (doReply) options["reply"] = { messageReference: message.id };
204241
message.channel.send(options).then(msg => { if (callback != null) callback(msg); });
205-
} else if (action == 1)
206-
message.edit(options).then(msg => { if (callback != null) callback(msg); });
242+
} else if (action == 1) {
243+
if (message.edit) message.edit(options).then(msg => { if (callback != null) callback(msg); });
244+
else if (message.update) message.update(options).then(msg => { if (callback != null) callback(msg); });
245+
};
207246
},
208247

209248
RemoveReactions: function(app, msg) {
@@ -212,8 +251,7 @@ const app = {
212251
app.functions.msgHandler(msg, {
213252
embeds: [{
214253
color: app.config.system.embedColors.red,
215-
description: "Failed to remove all reactions! Will attempt to remove my reactions only...",
216-
footer: { text: app.config.system.footerText }
254+
description: "Failed to remove all reactions! Will attempt to remove my reactions only..."
217255
}]
218256
}, 0, true, (async m => {
219257
var myID = app.client.user.id;
@@ -226,7 +264,6 @@ const app = {
226264
embeds: [{
227265
color: app.config.system.embedColors.red,
228266
description: "Failed to remove my reactions! well, that's an F.",
229-
footer: { text: app.config.system.footerText }
230267
}]
231268
}, 1, true);
232269
app.logger.error("DISCORD", "Could not remove my reactions due to " + err);
@@ -247,12 +284,12 @@ const app = {
247284
description: `Command \`${((command.name) ? command.name : command)}\` was not found!`,
248285
fields: [
249286
{ name: "Lost?", value: `You should check out the \`${userSettings.get("prefix")}help\`` }
250-
],
251-
footer: { text: app.config.system.footerText }
287+
]
252288
}]
253289
}
254290
else {
255291
var msg = ((err.message && err.message != "") ? "js\n" + err.message : (err && err != "") ? err : "Unknown Error.");
292+
256293
data = {
257294
embeds: [{
258295
title: embedTitle,
@@ -261,16 +298,14 @@ const app = {
261298
fields: [
262299
{ name: "Error Details", value: "```" + msg + "```" }
263300

264-
],
265-
footer: { text: app.config.system.footerText }
301+
]
266302
}]
267303
};
268304
if (type == "error" && err.stack) {
269305
var stack = err.stack,
270-
maxLength = 2000,
306+
maxLength = 1020,
271307
msg = "(continued)";
272-
if (stack.length > maxLength) stack = stack.match(new RegExp('.{1,' + (maxLength - msg.length) + '}', 'g'))[0] + msg;
273-
data.embeds[0].fields.push({ name: "Stacktrace", value: "```js\n" + err.stack + "```" });
308+
// data.embeds[0].fields.push({ name: "Stacktrace", value: "```js\n" + err.stack + "```" });
274309
userSettings.update({ executedCommands: (userSettings.get('errorCommands') + 1) }, { where: { userID: message.author.id } });
275310
};
276311
};
@@ -280,6 +315,25 @@ const app = {
280315
return;
281316
},
282317

318+
generateRandomCode: function(length, random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") { // random could be set to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"@#$%^&()-=+[{]}"
319+
var code = "";
320+
for (var i = 0; i < length; i++) { code += random.charAt(Math.floor(Math.random() * random.length)); };
321+
return code;
322+
},
323+
getEmoji: function(app, emojiID, full = false) {
324+
var emoji = app.client.emojis.cache.find(e => e.id === emojiID) || null;
325+
326+
var theEmoji = emoji;
327+
if (emoji && full) {
328+
theEmoji = "<";
329+
if (emoji.animated)
330+
emoji += ":a";
331+
theEmoji += ":" + emoji["name"] + ":" + emoji["id"] + ">";
332+
};
333+
return theEmoji || null;
334+
},
335+
getID: function(string) { return string.replace(/[<#@&!>]/g, ''); },
336+
doesArrayStartsWith: function(string, array) { return array.findIndex((item) => { return item.startsWith(string); }, string) != -1; },
283337

284338
clearCache: function(module) {
285339
if (module == null)
@@ -324,6 +378,16 @@ const app = {
324378
else ++i;
325379
return arr;
326380
},
381+
getParameters: function(array, chars) {
382+
if (typeof array != "object" || !array.length) return "gimme a array, not whatever that was!";
383+
else if (typeof chars != "string" || !chars) return "What am I supposed to split?? Gimme a string!";
384+
var parameters = [];
385+
for (var i = 0; i < array.length; i++) {
386+
var parameter = array[i].split(chars)[1];
387+
if (parameter) parameters.push(parameter);
388+
};
389+
return parameters;
390+
},
327391
RPSSystem: function(app, action) {
328392
if (app.client == undefined) { return "RPS failed to attach to client! Create Discord Client first." } else if (app.config == undefined) { return "RPS failed to attach to client: Missing config data."; };
329393

@@ -422,9 +486,9 @@ const app = {
422486
{ name: "node-fetch", required: true },
423487
{ name: "discord.js", required: true },
424488
{ name: "sequelize", required: true },
425-
{ name: "os", required: true},
426-
{ name: "node-os-utils", required: true},
427-
{ name: "canvas", required: false }
489+
{ name: "http", required: false },
490+
{ name: "canvas", required: false },
491+
{ name: "os", required: true }
428492
]
429493
}
430494

src/app/cmds/Fun/8ball.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ module.exports = {
1515
embeds: [{
1616
title: `${app.config.system.emotes.error} Error`,
1717
color: app.config.system.embedColors.red,
18-
description: "You need to ask a question!",
19-
footer: { text: app.config.system.footerText + " | An error occurred." }
18+
description: "You need to ask a question!"
2019
}]
2120
}, 0, true);
2221

@@ -44,8 +43,7 @@ module.exports = {
4443
fields: [
4544
{ name: "Question", value: question },
4645
{ name: "Answer", value: responsePick }
47-
],
48-
footer: { text: app.config.system.footerText }
46+
]
4947
}]
5048
}, 0, true);
5149
}

src/app/cmds/Fun/cuddle.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ module.exports = {
3333
embeds: [{
3434
color: app.config.system.embedColors.lime,
3535
description: `**${sender}** cuddles **${target}**!`,
36-
image: { url: img },
37-
footer: app.config.system.footerText
36+
image: { url: img }
3837
}]
3938
});
4039

src/app/cmds/Fun/explode.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module.exports = {
2+
name: "explode",
3+
description: "MAKE THAT THING GO KABOOM!",
4+
guildOnly: false,
5+
authorizedGuilds: [],
6+
hidden: false,
7+
permissions: ["DEFAULT"],
8+
cooldown: 3,
9+
aliases: [],
10+
syntax: [],
11+
execute: async(app, message, args) => {
12+
var target = message.mentions.users.first() || args[0],
13+
sender = message.author;
14+
if (!target) return app.functions.msgHandler(message, { content: "You need to add something to explode!!" }, 0, true);
15+
else if (target == sender) return app.functions.msgHandler(message, { content: "Why would you want to send a bomb to yourself???" }, 0, true);
16+
17+
var img = "error";
18+
const res = await app.modules["node-fetch"](app.config.system.imgAPI + "explosion");
19+
20+
if (res.status != 200) {
21+
// In the future, we'll use a "fallback" instance
22+
// where it will send a local image or maybe just the message
23+
// w/o an image.
24+
throw new Error(res.status);
25+
} else {
26+
const body = await res.json();
27+
if (body["url"] != null)
28+
img = body["url"];
29+
else
30+
img = "error";
31+
};
32+
return app.functions.msgHandler(message, {
33+
embeds: [{
34+
author: { name: `Bomb sent by ${sender.tag}`, icon_url: sender.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 }) },
35+
color: app.config.system.embedColors.blue,
36+
fields: [
37+
{ name: "BOOM!", value: `${target} has been kaboom'd!` },
38+
{ name: "But, uh...", value: "That explosion made a huge mess..." }
39+
],
40+
image: { url: img }
41+
}]
42+
});
43+
44+
// TODO:
45+
// write better image detection or something. Yeah. That.
46+
}
47+
}

src/app/cmds/Fun/hug.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ module.exports = {
3333
embeds: [{
3434
color: app.config.system.embedColors.blue,
3535
description: `**${sender}** gave **${target}**, a hug!`,
36-
image: { url: img },
37-
footer: app.config.system.footerText
36+
image: { url: img }
3837
}]
3938
});
4039

src/app/cmds/Fun/kiss.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ module.exports = {
3333
embeds: [{
3434
color: app.config.system.embedColors.red,
3535
description: `**${sender}** kisses **${target}**!`,
36-
image: { url: img },
37-
footer: app.config.system.footerText
36+
image: { url: img }
3837
}]
3938
});
4039

src/app/cmds/Fun/pat.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = {
2+
name: "pat",
3+
description: "There, there! Wholesome pats for everyone!",
4+
guildOnly: false,
5+
authorizedGuilds: [],
6+
hidden: false,
7+
permissions: ["DEFAULT"],
8+
cooldown: 3,
9+
aliases: [],
10+
syntax: [],
11+
execute: async(app, message, args) => {
12+
var target = message.mentions.users.first() || args[0],
13+
sender = message.author;
14+
if (!target) return app.functions.msgHandler(message, { content: "You need to tag someone to pat!" }, 0, true);
15+
else if (target == sender) return app.functions.msgHandler(message, { content: "There there, here's a personal pat. :)" }, 0, true);
16+
17+
var img = "error";
18+
const res = await app.modules["node-fetch"](app.config.system.imgAPI + "pat");
19+
20+
if (res.status != 200) {
21+
// In the future, we'll use a "fallback" instance
22+
// where it will send a local image or maybe just the message
23+
// w/o an image.
24+
throw new Error(res.status);
25+
} else {
26+
const body = await res.json();
27+
if (body["url"] != null)
28+
img = body["url"];
29+
else
30+
img = "error";
31+
};
32+
return app.functions.msgHandler(message, {
33+
embeds: [{
34+
color: app.config.system.embedColors.purple,
35+
description: `**${sender}** pats **${target}**!`,
36+
image: { url: img }
37+
}]
38+
});
39+
40+
// TODO:
41+
// write better image detection or something. Yeah. That.
42+
}
43+
}

0 commit comments

Comments
 (0)