-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
179 lines (140 loc) · 4.24 KB
/
Copy pathbot.js
File metadata and controls
179 lines (140 loc) · 4.24 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
const Discord = require('discord.js');
const client = new Discord.Client();
queue = [];
prefix = "!que";
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
const pinger = message.member.user.tag;
queueRouter(command, args, pinger, message);
message.channel.send(msg);
});
function queueRouter(command, args, pinger, message) {
msg = "";
if ( command === '-join' || command === 'ue-join' ) {
//If someone was tagged, add them. If noone was tagged, add the person that sent the message
if (!args.length) {
tag = pinger;
}
else {
tag = message.mentions.users.first().tag;
}
//If person is already in the queue, don't double dip
if (queue.includes(tag)) {
msg = tag + " is already in the queue - no double dipping!";
msg = msg + "\n" + "Queue:" + "\n" + queue.join('\n');
}
else {
queue.push(tag);
msg = "Queue:" + "\n" + queue.join('\n');
}
}
else if ( command === '-out' || command === '-remove' || command === 'ue-out' || command === 'ue-remove' ) {
if (!args.length) {
tag = pinger;
}
else {
tag = message.mentions.users.first().tag;
}
removeA(queue, tag);
msg = "User " + tag + " hopped out of the queue vent!";
if (queue.length < 1) {
msg = msg + " Queue is now empty.";
}
else {
msg = msg + "\n" + "Queue:" + "\n" + queue.join('\n');
}
}
else if (command === '-reset' || command === 'ue-reset') {
queue = [];
msg = "Queue is now empty!";
}
else if (command === '-show' || command === 'ue-show' ) {
if (queue.length < 1) {
msg = "No one in the queue!";
}
else {
msg = "Queue:" + "\n" + queue.join('\n')
}
}
else if (command === '-help' || command === 'ue-help' ) {
msg = msg + "Queue Bot Commands:"+"\n";
msg = msg + "!que-join or !que-join @user to add a user to the queue"+"\n";
msg = msg + "!que-out or !que-out @user to remove a user from the queue"+"\n";
msg = msg + "!que-reset to remove all users from the queue"+"\n";
msg = msg + "!que-up or !que-up @user to bump a user up one spot in the queue"+"\n";
msg = msg + "!que-down or !que-down @user to move a user down one spot in the queue"+"\n";
msg = msg + "!que-show to show current queue"+"\n";
msg = msg + "!que-help to show commands";
}
else if ( command === '-up' || command === 'ue-up' || command === '-down' || command === 'ue-down' ) {
if (!args.length) {
tag = pinger;
}
else {
tag = message.mentions.users.first().tag;
}
if (!queue.includes(tag)) {
msg = "User " + tag + " is not in the Queue.";
if (queue.length < 1) {
msg = msg + " The queue is empty.";
}
else {
msg = msg + "\n" + "Queue:" + "\n" + queue.join('\n');
}
}
else {
var old_index = queue.indexOf(tag);
if ( command === '-up' || command === 'ue-up' ) {
var new_index = queue.indexOf(tag)-1;
var direction = "up";
}
else {
var new_index = queue.indexOf(tag)+1;
var direction = "down";
}
if (new_index < 0 || new_index > queue.length - 1) {
msg = "User " + tag + " cannot be moved " + direction;
msg = msg + "\n" + "Queue:" + "\n" + queue.join('\n');
}
else {
move(queue, old_index, new_index);
msg = "User " + tag + " has been moved " + direction;
msg = msg + "\n" + "Queue:" + "\n" + queue.join('\n');
}
}
}
else {
msg = "Can't recognize command. Please use !que-help for list of commands";
}
return msg;
}
function removeA(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
}
function move(arr, old_index, new_index) {
while (old_index < 0) {
old_index += arr.length;
}
while (new_index < 0) {
new_index += arr.length;
}
if (new_index >= arr.length) {
var k = new_index - arr.length;
while ((k--) + 1) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr;
}
// THIS MUST BE THIS WAY
client.login(process.env.BOT_TOKEN);//BOT_TOKEN is the Client Secret