-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhispers.js
158 lines (144 loc) · 6.22 KB
/
whispers.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
/*
Module for whispering
- Connects channels (with optional disguises)
- Converts yourself into a bot
*/
module.exports = function() {
/* Handles connection command */
this.cmdConnection = function(message, args) {
// Check subcommand
if(!args[0]) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `connection [add|remove|reset]`");
return;
}
// Find subcommand
switch(args[0]) {
case "add": cmdConnectionAdd(message.channel, args); break;
case "remove": cmdConnectionRemove(message.channel); break;
case "send": cmdConnectionSend(message.channel, args); break;
case "reset": cmdConfirm(message, "connection reset"); break;
default: message.channel.send("⛔ Syntax error. Invalid subcommand `" + args[0] + "`!"); break;
}
}
this.cmdImpersonate = function(message, argsX) {
let author = parseUser(message.channel, argsX.shift());
if(author) cmdWebhook(message.channel, message.guild.members.cache.get(author), argsX);
}
this.cmdWebhookDirect = function(message, argsX) {
if(!message.author.bot) {
cmdWebhook(message.channel, message.member, argsX);
} else {
let msg = ["Leave me alone.", "Please just stop.", "Why are you doing this?","What have I done to deserves this.","No.","Just no.","Seriously, no.","No means no.","Go away.","Why do you hate me?","What have I ever done to you?","I don't want to be part of your evil plots.","I'm a friendly bot, why are you trying to make me do this?","I just want to be nice, not annoying.","Please go away.","Why...","Stop...",":("];
message.channel.send(msg[Math.floor(Math.random() * msg.length)]);
}
}
/* Adds a connection */
this.cmdConnectionAdd = function(channel, args, hidden = false) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
} else if(!args[2]) {
args[2] = "";
}
// Add connection to DB
sql("INSERT INTO connected_channels (channel_id, id, name) VALUES (" + connection.escape(channel.id) + "," + connection.escape(args[1]) + "," + connection.escape(args[2]) + ")", result => {
if(args[2] != "") {
// Connection w/ disguise
if(!hidden) channel.send("✅ Added connection `" + args[1] + "` with disguise `" + toTitleCase(args[2]) + "`!");
log("Whispers > Created connection `" + args[1] + "` with disguise `" + toTitleCase(args[2]) + "`!");
} else {
// Connection w/o disguise
if(!hidden) channel.send("✅ Added connection `" + args[1] + "` with no disguise!");
log("Whispers > Created connection `" + args[1] + "` with no disguise!");
}
}, () => {
// Couldn't add connection
channel.send("⛔ Database error. Couldn't add connection `" + args[1] + "`!");
});
}
/* Removes a connection */
this.cmdConnectionRemove = function(channel) {
// Remove connections from DB
sql("DELETE FROM connected_channels WHERE channel_id = " + connection.escape(channel.id), result => {
channel.send("✅ Removed all connections from this channel!");
log("Whispers > Removed connections from `" + channel.id + "`!");
}, () => {
// Database error
channel.send("⛔ Database error. Couldn't remove connections!");
});
}
/* Rests all connections */
this.cmdConnectionReset = function(channel) {
sql("DELETE FROM connected_channels", result => {
channel.send("✅ Successfully reset connections!");
}, () => {
channel.send("⛔ Database error. Could not reset connections!");
});
}
this.cmdWebhook = function(channel, member, args) {
let webhookMsg = args.join(" ");
webhookMsg = webhookMsg.replace(/:~/g, ":");
if(!(webhookMsg.length > 0)) webhookMsg = "|| ||";
sendMessageDisguiseMember(channel.id, webhookMsg, member);
}
this.getIconFromName = function(name) {
return new Promise(res => {
let roleNameParsed = parseRole(name);
if(!roleNameParsed) return res(false);
var output;
sql("SELECT * FROM roles WHERE name = " + connection.escape(roleNameParsed), async result => {
if(!result[0]) return res(false);
let roleData = await getRoleData(result[0].display_name, result[0].class, result[0].category, result[0].team);
let urlExists = await checkUrlExists(roleData.url);
if(urlExists) res(roleData.url);
else res(false);
});
});
}
/* Copies over messages */
this.connectionExecute = function(message) {
if(connection && !message.author.bot && message.content.indexOf(stats.prefix) !== 0) {
// Find connection id(s)
sql("SELECT id, name FROM connected_channels WHERE channel_id = " + connection.escape(message.channel.id), result => {
// For each connection id, find each connected channel
result.forEach(source => {
sql("SELECT channel_id, name FROM connected_channels WHERE id = " + connection.escape(source.id), result => {
// Write message in each channel
result.forEach(async destination => {
// Ignore if it's same channel as source
if(destination.channel_id != message.channel.id) {
// send message
if(source.name) {
sendMessageDisguise(destination.channel_id, message.content, source.name);
} else {
sendMessageDisguiseMember(destination.channel_id, message.content, message.member);
}
}
});
}, () => {
// Database error
log("⛔ Database error. Could not access connected channels via id!");
});
});
}, () => {
// Database error
log("⛔ Database error. Could not access connected channels via channel!");
});
}
}
/* Send message over a connection */
this.cmdConnectionSend = function(channel, args) {
// Check arguments
if(!args[1] || !args[2] || !args[3]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// set values
let conn = args[1];
let disguise = typeof args[2] === 'string' ? toTitleCase(args[2]) : "";
let text = args[3];
// send message
connectionSend(conn, text, disguise);
}
}