-
Notifications
You must be signed in to change notification settings - Fork 1
/
Amalgam.js
187 lines (173 loc) · 5.78 KB
/
Amalgam.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
//Node Libraries
const Discord = require('discord.js');
const client = new Discord.Client();
const botConfig = require("./config.json");
//chat command imports
const mshrug = require('./chatCommands/mshrg.js');
const embedMessage = require('./chatCommands/embedMessage.js');
const {CRIfunction, criHelp} = require('./chatCommands/cri.js');
const coin = require('./chatCommands/coin.js');
const {calculator} = require('./chatCommands/calculator.js');
const {time, remind} = require('./chatCommands/remind.js');
const {gatekeepingClap} = require('./chatCommands/gatekeeping.js');
const {mainHelpDialog} = require('./chatCommands/mainHelp.js');
const {maskMessage} = require('./chatCommands/maskMessage.js');
const {uploadImg, deleteImg, listAllKeycodes, randomKeyword, retrieveImg} = require('./chatCommands/img.js');
const {play, pause, resume, skip, stop, getMetaIndex, queue} = require('./chatCommands/VCmusic.js');
const { furiganaize } = require('./chatCommands/furiganaWriter');
//AWS imports
const AWS = require('aws-sdk');
var streamMetadata = [];
//DynamoDB stuff
//const {importToDynamoDB} = require('./dynaDBFunctions/importToDynamo.js');
//Parses the message and figures out what command has been typed by the user
async function parseCommand(message) {
var i;
//Get the message and split it
var messageContent = message.content.substring(botConfig.prefix.length);
var messageSplit = messageContent.split(" ");
console.log("parseCommand function called!");
//Check if the Convert Regional Indicator function should be called.
switch(messageSplit[0]){
case "cri":
(messageSplit[1] === '-embed') ?
CRIfunction(message, true) : CRIfunction(message, false);
break;
case "help":
mainHelpDialog(message, client);
break;
case "command":
mainHelpDialog(message);
break;
case "crihelp":
criHelp(message, client);
break;
case "calchelp":
inputStr = "**" + botConfig.prefix + "calchelp**\n Available operands are as follows: \n Addition: + \n Subtraction: - \n Multiplication: * \n Division: / \n Modulo: % \n Exponent:^"
embedMessage(message, inputStr);
break;
case "number":
console.log("number command called!");
if(isNaN(messageSplit[1])){
message.channel.send("Please input a number after the command.");
}
else{
message.channel.send(Math.floor((Math.random() * messageSplit[1]) + 1));
}
break;
case "clone":
if(isNaN(messageSplit[1])){
message.channel.send("Please input a number after the command.");
}
else{
message.channel.send((messageContent.slice(messageSplit[0].length + messageSplit[1].length + 2) + " ").repeat(messageSplit[1]));
}
break;
case "remind":
(messageSplit[1] === '-noAuthor') ? remind(message, true) : remind(message, false);
(messageSplit[1] === '-noAuthor') ? time(message, true) : time(message, false);
break;
case "coin":
coin(message);
break;
case "calc":
calculator(message, messageContent);
break;
case "mshrg":
mshrug(message);
break;
case "clap":
(messageSplit[1].toLowerCase() === '-embed') ? gatekeepingClap(message, true): gatekeepingClap(message, false);
break;
case "mask":
console.log("mask command called!");
maskMessage(message, messageContent);
break;
case "botCreator":
embedMessage(message, "Bot collaborately created by Ethanol 10(Ethan) and Jelly(Julian).");
console.log("botCreator called");
break;
case "botSourceCode":
embedMessage(message, "Here's how I work. It ain't perfect tho. https://github.com/Ethanol10/Amalgam");
break;
case "upload":
uploadImg(messageSplit[1], message);
break;
case "getimg":
retrieveImg(messageSplit[1], message);
break;
case "deleteimg":
deleteImg(messageSplit[1], message);
break;
case "listkey":
listAllKeycodes(message);
break;
case "randomimg":
randomKeyword(message);
break;
case "play":
play(message, messageContent.substring("play ".length), streamMetadata);
break;
case "pause":
pause(message, streamMetadata);
break;
case "resume":
resume(message, streamMetadata);
break;
case "skip":
skip(message, streamMetadata);
break;
case "stop":
stop(message, streamMetadata);
break;
case "queue":
queue(message, streamMetadata);
break;
case "furiganaize":
furiganaize(message);
}
}
//Inital boot
client.on("ready", () => {
console.log("Amalgam is ready to serve!");
client.user.setActivity(botConfig.prefix + "help");
//db export
//dbExport();
//AWS SETUP
AWS.config.update({region: botConfig.region});
AWS.config.loadFromPath('./config.json');
AWS.config.getCredentials(function(err) {
if (err) console.log(err.stack);
// credentials not loaded
else {
console.log("Access key:", AWS.config.credentials.accessKeyId);
}
});
//db import to DynamoDB
//importToDynamoDB();
});
//Check for message and send it to the parser
client.on("message", (message) => {
//Don't check the message if it does not start with the prefix or is from a bot.
if (message.author.bot || message.content.indexOf(botConfig.prefix) !== 0) return;
console.log("Message Recieved!");
parseCommand(message);
});
//Check if the bot is by itself in the channel, terminate stream for that guild and delete metadata.
client.on("voiceStateUpdate", (oldState, newState) => {
try{
if( newState.guild.me.voice.channel.members.size === 1 ){
var index = getMetaIndex(streamMetadata, newState.guild);
streamMetadata[index].msg.channel.send("Nobody is in the bound voice channel: <#" + streamMetadata[index].vc + ">, terminating the stream.")
streamMetadata.splice(index, 1);
newState.guild.me.voice.channel.leave();
}
}
catch (err){
if(err instanceof TypeError){
console.log("TypeError, but bot is probably not in VC, so no problems here.");
}
}
});
//refer to the JSON config file for the token
client.login(botConfig.token);