-
Notifications
You must be signed in to change notification settings - Fork 4
/
HalloweenSniper.js
144 lines (130 loc) · 4.55 KB
/
HalloweenSniper.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
const Eris = require('eris');
const config = require('./config.js');
// Give bot the token and disable certain events
const bot = new Eris.Client(config.token, {
disableEvents: config.disabledEvents,
});
// For slowmode checking
let slowmodeDebounce = false;
// Async slowmode function
const slowDebouncer = async () => {
// If debounce is on, return so as not to add an additional timer
// This is a just-in-case, shouldnt actually happen
if(slowmodeDebounce) {
return;
}
// If debounce is off, start it
else {
slowmodeDebounce = true;
await new Promise(resolve => setTimeout(resolve, config.slowmodeTime));
slowmodeDebounce = false;
}
};
// Asynchronous spam function. Choose a random channel, chooses a message to send from config, then decides whether to deletes it.
const spammer = async (channelList) => {
while(config.spam) {
// Generate delay between minSpamDelay and maxSpamDelay
const spamDelay = (Math.random() * (config.maxSpamDelay - config.minSpamDelay) + config.minSpamDelay);
// Wait for setTimeout of spamDelay
await new Promise(resolve => setTimeout(resolve, spamDelay));
// Generate message from possible messages specified in config
const spamMsg = config.toSpam[Math.floor(Math.random() * config.toSpam.length)];
bot.createMessage(channelList[Math.floor(Math.random() * channelList.length)], spamMsg)
.then(msg => {
// If delete enabled, deleted the message 1 second after sending
if(config.deleteSpam) {
msg.delete(1000);
}
});
}
};
// If config spam is true, enable spam
if(config.spam) {
console.log('Will spam the server.');
bot.once('connect', async () => {
// If channels are specified, only spam in those.
if(config.specChannel) {
spammer(config.channelIds);
}
// If channels are not specified, find out which channels to spam in.
else if(config.specServer) {
// Wait 5 seconds to make sure channels are initialized, then find all channels in server
// that the user has permission to send in.
// This is dumb, but has to be done because of how Eris handles selfbots
setTimeout(function() {
for(let i = 0; i < config.serverIds.length; i++) {
const guild = bot.guilds.get(config.serverIds[i]);
guild.channels.forEach(function(channel) {
if(channel.permissionsOf(bot.user.id).json['sendMessages'] && channel.type == 0) {
config.channelIds.push(channel.id);
}
});
}
spammer(config.channelIds);
}, 5000);
}
// This block is redundant and should be caught by config.js
else {
console.error('Cannot spam server without a server id or channel id.');
process.exit(1);
}
});
}
bot.on('connect', () => {
console.log('Bot connected.');
});
// When a message is created
bot.on('messageCreate', (msg) => {
// If message not sent by Trick'cord Treat bot, abort.
if(msg.author.id != '755580145078632508') {
return;
}
// If server specified, check to see that message is coming from that server.
// If not, abort
if(config.specServer && (!(config.serverIds.indexOf(msg.channel.guild.id) > -1))) {
return;
}
// Check the embed to determine which command is needed
// Then send the command {$waitSet} seconds after message is received
const claimDelay = (Math.random() * (config.maxClaimDelay - config.minClaimDelay) + config.minClaimDelay);
// Check for slowmode. If we're on cooldown, return.
// If not on cooldown, start the debounce function and continue as normal.
if(config.slowmode) {
if(slowmodeDebounce) {
console.log('Can\'t respond, in slowmode');
return;
}
else {
slowDebouncer();
}
}
// Check the title of embed to see if this is a trick or treat message
if(msg.embeds[0].title === 'A trick-or-treater has stopped by!') {
// Determine whether to use h!trick or h!treat
if(msg.embeds[0].description.includes('treat')) {
setTimeout(function() {
bot.createMessage(msg.channel.id, config.treat);
}, claimDelay);
}
else if(msg.embeds[0].description.includes('trick')) {
setTimeout(function() {
bot.createMessage(msg.channel.id, config.trick);
}, claimDelay);
}
}
});
// Basic error checking/handling
bot.on('error', async (err) => {
if(err['errno'] == 'ENOTFOUND') {
console.log('Connection error. Attempting to reconnect...');
// On error disconnect bot, wait 5 seconds, reconnect
bot.disconnect();
await new Promise(resolve => setTimeout(resolve, 5000));
bot.connect();
}
else {
console.log(err);
}
});
// Get the bot to connect to Discord
bot.connect();