forked from kriller1612/datbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembeds.js
More file actions
234 lines (222 loc) · 8.84 KB
/
embeds.js
File metadata and controls
234 lines (222 loc) · 8.84 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* help:
* The table of available commands that is to be
* sent via dm to the requesting user with !help
*
* playing:
* The embed that is sent when a song starts playing
*
* queue:
* The embed that is sent when a song is added to the queue
*
* ping:
* The embed that is sent on !ping
*
* remaining
* The embed that is sent on !remaining
*/
module.exports = {
help: link => {
return {
embed: {
color: 3447003,
author: {
name: "Help has arrived"
},
title: "View GitHub repo",
url: link,
description: "Feel free to suggest features or fork and make them yourself!",
fields: [{
name: "!ping",
value: "Test the bot in selected channel. Retrives \"pong\" and some latency data."
},
{
name: "!code, !github, !source",
value: "Retrives a link to the github repo."
},
{
name: "!ermin { optional: integer }",
value: "Retrives a specific quote indexed by an integer value, else return a random Ermin's quote if no integer parameter is specified."
},
{
name: "!react",
value: "React with Ermin's face on the last five messages posted in the channel."
},
{
name: "!play { search query or YouTube link }",
value: "*Experimental:* Searches YouTube for given parameter, then initiates playback of first video found. You must be in a voice channel to use this command. If a song is already playing, the requested song is added to the queue."
},
{
name: "!volume { optional: Integer }",
value: "*Experimental:* Retrieves current playback volume if no parameter is specified. Else, sets volume to specified integer value. This value must be between 1 and 10 inclusive. You must be in the same voice channel as the bot to use this command and music has to be playing."
},
{
name: "!skip",
value: "*Experimental:* Skips the song currently playing. You must be in the same voice channel as the bot to use this command and music has to be playing."
},
{
name: "!pause",
value: "*Experimental:* Pauses playback. You must be in the same voice channel as the bot to use this command and music has to be playing."
},
{
name: "!resume",
value: "*Experimental:* Resumes playback. You must be in the same voice channel as the bot to use this command and music has to be paused."
},
{
name: "!remaining",
value: "*Experimental:* Retrieves the time remaining of the song currently playing and some data on the next song in the queue. A song has to be playing for this command to work."
}/*,
{
name: "!queue, !playlist",
value: "*Experimental:* Retrieves a list of queued songs."
}*/],
timestamp: new Date(),
footer: {
text: "!help @ DatBot :*"
}
}
};
},
playing: (data, playlist) => {
const minutes = Math.floor(data.video.duration / 60);
const seconds = data.video.duration % 60;
const nextTitle = ((playlist.length != 0) ? playlist[0].video.title : "Nothing in queue! Do `!play { search query or YouTube link }` to add to it.");
const nextChannel = ((playlist.length != 0) ? "\nby " + playlist[0].video.owner : "");
const nextUser = ((playlist.length != 0) ? "\nsuggested by " + playlist[0].message.author : "");
// Spaghetti code for inserting periods in view count
// This took way too long to do...
const views_number = data.video.views;
const views_string = views_number.toString();
let views = '';
for (i = 0; 3 + i <= views_string.length;) {
if (i > 0 || views_string.length % 3 == 0) {
views += views_string.slice(i, 3 + i);
i += 3;
}
else {
views += views_string.slice(i, views_string.length % 3)
i += views_string.length % 3;
}
views += '.';
}
views = views.substring(0, views.length - 1);
return {
embed: {
title: data.video.title,
description: data.description,
url: data.video.url,
color: 3447003,
timestamp: data.timestamp,
footer: {
icon_url: data.message.author.avatarURL,
text: "Requested by " + data.message.author.username
},
thumbnail: {
url: data.video.thumbnailUrl
},
author: {
name: data.video.owner
},
fields: [
{
name: "Views",
value: views,
inline: true
},
{
name: "Duration",
value: minutes + ":" + ((seconds < 10) ? "0" + seconds : seconds),
inline: true
},
{
name: "Up next",
value: nextTitle + nextChannel + nextUser
}
]
}
};
},
queue: (data, playlist, time) => {
const left_of_song = Math.floor(time.duration - ((Date.now() - time.timestamp)) / 1000);
let playlist_time = 0;
playlist.forEach( elem => {
playlist_time += elem.video.duration;
});
const queue_time = left_of_song + playlist_time - data.video.duration;
const minutes = Math.floor((queue_time) / 60);
const seconds = (queue_time) % 60;
return {
embed: {
title: data.video.title,
description: `by ${data.video.owner}`,
url: data.video.url,
color: 3447003,
thumbnail: {
url: data.video.thumbnailUrl
},
author: {
name: "Added to queue:"
},
fields: [
{
name: "Place in queue",
value: playlist.length,
inline: true
},
{
name: "Queue time",
value: "~ " + minutes + ":" + ((seconds < 10) ? "0" + seconds : seconds),
inline: true
}
]
}
}
},
ping: client => {
return {
embed: {
color: 3447003,
footer: {
text: "A heatbeat is sent every 45 seconds"
},
fields: [
{
name: "Latest heatbeat",
value: `${client.pings[0]} ms`,
inline: true
},
{
name: "Avarage:",
value: `${Math.round(client.ping)} ms`,
inline: true
}
]
}
}
},
remaining: (time, playlist) => {
const rem = Math.floor(time.duration - (Date.now() - time.timestamp) / 1000);
const minutes = Math.floor((rem) / 60);
const seconds = (rem) % 60;
const nextTitle = ((playlist.length != 0) ? playlist[0].video.title : "Nothing in queue! Do `!play { search query or YouTube link }` to add to it.");
const nextChannel = ((playlist.length != 0) ? "\nby " + playlist[0].video.owner : "");
const nextUser = ((playlist.length != 0) ? "\nsuggested by " + playlist[0].message.author : "");
return {
embed: {
color: 3447003,
fields: [
{
name: "Time remaining",
value: "~ " + minutes + ":" + ((seconds < 10) ? "0" + seconds : seconds),
inline: true
},
{
name: "Up next",
value: nextTitle + nextChannel + nextUser,
inline: true
}
]
}
}
}
}