discord.js-selfv13 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord.js-selfv13 might be problematic. Click here for more details.
- package/.dccache +1 -0
- package/LICENSE +190 -0
- package/README.md +87 -0
- package/browser.js +9 -0
- package/deploy/deploy-key.enc +0 -0
- package/deploy/deploy.sh +90 -0
- package/deploy/test.sh +34 -0
- package/docs/README.md +1 -0
- package/docs/examples/attachments.md +163 -0
- package/docs/examples/avatars.js +29 -0
- package/docs/examples/embed.js +38 -0
- package/docs/examples/greeting.js +30 -0
- package/docs/examples/moderation.md +145 -0
- package/docs/examples/ping.js +29 -0
- package/docs/examples/webhook.js +12 -0
- package/docs/general/faq.md +23 -0
- package/docs/general/updating.md +181 -0
- package/docs/general/welcome.md +95 -0
- package/docs/index.yml +30 -0
- package/docs/logo.svg +19 -0
- package/docs/topics/voice.md +113 -0
- package/docs/topics/web.md +38 -0
- package/package.json +147 -0
- package/src/client/Client.js +564 -0
- package/src/client/ClientDataManager.js +150 -0
- package/src/client/ClientDataResolver.js +376 -0
- package/src/client/ClientManager.js +74 -0
- package/src/client/WebhookClient.js +118 -0
- package/src/client/actions/Action.js +23 -0
- package/src/client/actions/ActionsManager.js +40 -0
- package/src/client/actions/ChannelCreate.js +11 -0
- package/src/client/actions/ChannelDelete.js +30 -0
- package/src/client/actions/ChannelUpdate.js +74 -0
- package/src/client/actions/GuildBanRemove.js +13 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
- package/src/client/actions/GuildDelete.js +57 -0
- package/src/client/actions/GuildEmojiCreate.js +17 -0
- package/src/client/actions/GuildEmojiDelete.js +18 -0
- package/src/client/actions/GuildEmojiUpdate.js +17 -0
- package/src/client/actions/GuildEmojisUpdate.js +38 -0
- package/src/client/actions/GuildMemberGet.js +10 -0
- package/src/client/actions/GuildMemberRemove.js +41 -0
- package/src/client/actions/GuildRoleCreate.js +26 -0
- package/src/client/actions/GuildRoleDelete.js +42 -0
- package/src/client/actions/GuildRoleUpdate.js +41 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
- package/src/client/actions/GuildSync.js +29 -0
- package/src/client/actions/GuildUpdate.js +34 -0
- package/src/client/actions/MessageCreate.js +53 -0
- package/src/client/actions/MessageDelete.js +35 -0
- package/src/client/actions/MessageDeleteBulk.js +26 -0
- package/src/client/actions/MessageReactionAdd.js +37 -0
- package/src/client/actions/MessageReactionRemove.js +37 -0
- package/src/client/actions/MessageReactionRemoveAll.js +25 -0
- package/src/client/actions/MessageUpdate.js +40 -0
- package/src/client/actions/Ready.js +1 -0
- package/src/client/actions/Ready.js.bak +65 -0
- package/src/client/actions/UserGet.js +11 -0
- package/src/client/actions/UserNoteUpdate.js +30 -0
- package/src/client/actions/UserUpdate.js +33 -0
- package/src/client/rest/APIRequest.js +56 -0
- package/src/client/rest/DiscordAPIError.js +60 -0
- package/src/client/rest/RESTManager.js +58 -0
- package/src/client/rest/RESTMethods.js +1006 -0
- package/src/client/rest/RequestHandlers/Burst.js +90 -0
- package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
- package/src/client/rest/RequestHandlers/Sequential.js +132 -0
- package/src/client/rest/UserAgentManager.js +25 -0
- package/src/client/voice/ClientVoiceManager.js +81 -0
- package/src/client/voice/VoiceBroadcast.js +366 -0
- package/src/client/voice/VoiceConnection.js +530 -0
- package/src/client/voice/VoiceUDPClient.js +127 -0
- package/src/client/voice/VoiceWebSocket.js +246 -0
- package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
- package/src/client/voice/opus/BaseOpusEngine.js +60 -0
- package/src/client/voice/opus/NodeOpusEngine.js +40 -0
- package/src/client/voice/opus/OpusEngineList.js +28 -0
- package/src/client/voice/opus/OpusScriptEngine.js +45 -0
- package/src/client/voice/player/AudioPlayer.js +170 -0
- package/src/client/voice/receiver/VoiceReadable.js +17 -0
- package/src/client/voice/receiver/VoiceReceiver.js +219 -0
- package/src/client/voice/util/SecretKey.js +16 -0
- package/src/client/voice/util/Secretbox.js +33 -0
- package/src/client/voice/util/VolumeInterface.js +86 -0
- package/src/client/websocket/WebSocketConnection.js +506 -0
- package/src/client/websocket/WebSocketManager.js +90 -0
- package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
- package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
- package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
- package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
- package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
- package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
- package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
- package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
- package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
- package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
- package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
- package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
- package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
- package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
- package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
- package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
- package/src/client/websocket/packets/handlers/Ready.js +83 -0
- package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
- package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
- package/src/client/websocket/packets/handlers/Resumed.js +28 -0
- package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
- package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
- package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
- package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
- package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
- package/src/index.js +66 -0
- package/src/sharding/Shard.js +282 -0
- package/src/sharding/ShardClientUtil.js +146 -0
- package/src/sharding/ShardingManager.js +220 -0
- package/src/structures/Attachment.js +75 -0
- package/src/structures/CategoryChannel.js +22 -0
- package/src/structures/Channel.js +78 -0
- package/src/structures/ClientUser.js +447 -0
- package/src/structures/ClientUserChannelOverride.js +30 -0
- package/src/structures/ClientUserGuildSettings.js +60 -0
- package/src/structures/ClientUserSettings.js +80 -0
- package/src/structures/DMChannel.js +76 -0
- package/src/structures/Emoji.js +256 -0
- package/src/structures/GroupDMChannel.js +246 -0
- package/src/structures/Guild.js +1461 -0
- package/src/structures/GuildAuditLogs.js +371 -0
- package/src/structures/GuildChannel.js +537 -0
- package/src/structures/GuildMember.js +613 -0
- package/src/structures/Invite.js +164 -0
- package/src/structures/Message.js +605 -0
- package/src/structures/MessageAttachment.js +68 -0
- package/src/structures/MessageCollector.js +100 -0
- package/src/structures/MessageEmbed.js +386 -0
- package/src/structures/MessageMentions.js +144 -0
- package/src/structures/MessageReaction.js +96 -0
- package/src/structures/NewsChannel.js +24 -0
- package/src/structures/OAuth2Application.js +148 -0
- package/src/structures/PartialGuild.js +51 -0
- package/src/structures/PartialGuildChannel.js +44 -0
- package/src/structures/PermissionOverwrites.js +69 -0
- package/src/structures/Presence.js +241 -0
- package/src/structures/ReactionCollector.js +85 -0
- package/src/structures/ReactionEmoji.js +49 -0
- package/src/structures/RichEmbed.js +295 -0
- package/src/structures/Role.js +376 -0
- package/src/structures/StoreChannel.js +25 -0
- package/src/structures/TextChannel.js +154 -0
- package/src/structures/User.js +329 -0
- package/src/structures/UserConnection.js +48 -0
- package/src/structures/UserProfile.js +62 -0
- package/src/structures/VoiceChannel.js +146 -0
- package/src/structures/VoiceRegion.js +50 -0
- package/src/structures/Webhook.js +304 -0
- package/src/structures/interfaces/Collector.js +179 -0
- package/src/structures/interfaces/TextBasedChannel.js +635 -0
- package/src/structures/shared/resolvePermissions.js +26 -0
- package/src/util/Collection.js +532 -0
- package/src/util/Constants.js +845 -0
- package/src/util/Permissions.js +306 -0
- package/src/util/Snowflake.js +82 -0
- package/src/util/Util.js +221 -0
- package/test/random.js +207 -0
- package/test/shard.js +31 -0
- package/test/sharder.js +7 -0
- package/test/voice.js +78 -0
- package/test/webpack.html +31 -0
- package/tsconfig.json +13 -0
- package/tslint.json +62 -0
- package/typings/discord.js-test.ts +69 -0
- package/typings/index.d.ts +2190 -0
- package/webpack.config.js +62 -0
package/test/random.js
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Discord = require('../');
|
4
|
+
const request = require('superagent');
|
5
|
+
const fs = require('fs');
|
6
|
+
|
7
|
+
console.time('magic');
|
8
|
+
|
9
|
+
const client = new Discord.Client({ fetchAllMembers: true, apiRequestMethod: 'sequential' });
|
10
|
+
|
11
|
+
const { email, password, token, usertoken, song } = require('./auth.json');
|
12
|
+
|
13
|
+
client.login(token).then(atoken => console.log('logged in with token ' + atoken)).catch(console.error);
|
14
|
+
|
15
|
+
client.on('ready', () => {
|
16
|
+
console.log(`ready with ${client.users.size} users`);
|
17
|
+
console.timeEnd('magic');
|
18
|
+
});
|
19
|
+
|
20
|
+
client.on('debug', console.log);
|
21
|
+
|
22
|
+
client.on('error', m => console.log('debug', new Error(m).stack));
|
23
|
+
client.on('reconnecting', m => console.log('reconnecting', m));
|
24
|
+
|
25
|
+
client.on('message', message => {
|
26
|
+
if (true) {
|
27
|
+
if (message.content === 'makechann') {
|
28
|
+
if (message.channel.guild) {
|
29
|
+
message.channel.guild.createChannel('hi', 'text').then(console.log);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
if (message.content === 'imma queue pls') {
|
34
|
+
let count = 0;
|
35
|
+
let ecount = 0;
|
36
|
+
for(let x = 0; x < 4000; x++) {
|
37
|
+
message.channel.send(`this is message ${x} of 3999`)
|
38
|
+
.then(m => {
|
39
|
+
count++;
|
40
|
+
console.log('reached', count, ecount);
|
41
|
+
})
|
42
|
+
.catch(m => {
|
43
|
+
console.error(m);
|
44
|
+
ecount++;
|
45
|
+
console.log('reached', count, ecount);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
if (message.content === 'myperms?') {
|
51
|
+
message.channel.send('Your permissions are:\n' +
|
52
|
+
JSON.stringify(message.channel.permissionsFor(message.author).serialize(), null, 4));
|
53
|
+
}
|
54
|
+
|
55
|
+
if (message.content === 'delchann') {
|
56
|
+
message.channel.delete().then(chan => console.log('selfDelChann', chan.name));
|
57
|
+
}
|
58
|
+
|
59
|
+
if (message.content.startsWith('setname')) {
|
60
|
+
message.channel.setName(message.content.substr(8));
|
61
|
+
}
|
62
|
+
|
63
|
+
if (message.content.startsWith('botname')) {
|
64
|
+
client.user.setUsername(message.content.substr(8));
|
65
|
+
}
|
66
|
+
|
67
|
+
if (message.content.startsWith('botavatar')) {
|
68
|
+
request
|
69
|
+
.get('url')
|
70
|
+
.end((err, res) => {
|
71
|
+
client.user.setAvatar(res.body).catch(console.error)
|
72
|
+
.then(user => message.channel.send('Done!'));
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
if (message.content.startsWith('gn')) {
|
77
|
+
message.guild.setName(message.content.substr(3))
|
78
|
+
.then(guild => console.log('guild updated to', guild.name))
|
79
|
+
.catch(console.error);
|
80
|
+
}
|
81
|
+
|
82
|
+
if (message.content === 'leave') {
|
83
|
+
message.guild.leave().then(guild => console.log('left guild', guild.name)).catch(console.error);
|
84
|
+
}
|
85
|
+
|
86
|
+
if (message.content === 'stats') {
|
87
|
+
let m = '';
|
88
|
+
m += `I am aware of ${message.guild.channels.size} channels\n`;
|
89
|
+
m += `I am aware of ${message.guild.members.size} members\n`;
|
90
|
+
m += `I am aware of ${client.channels.size} channels overall\n`;
|
91
|
+
m += `I am aware of ${client.guilds.size} guilds overall\n`;
|
92
|
+
m += `I am aware of ${client.users.size} users overall\n`;
|
93
|
+
message.channel.send(m).then(msg => msg.edit('nah')).catch(console.error);
|
94
|
+
}
|
95
|
+
|
96
|
+
if (message.content === 'messageme!') {
|
97
|
+
message.author.send('oh, hi there!').catch(e => console.log(e.stack));
|
98
|
+
}
|
99
|
+
|
100
|
+
if (message.content === 'don\'t dm me') {
|
101
|
+
message.author.deleteDM();
|
102
|
+
}
|
103
|
+
|
104
|
+
if (message.content.startsWith('kick')) {
|
105
|
+
message.guild.member(message.mentions[0]).kick().then(member => {
|
106
|
+
console.log(member);
|
107
|
+
message.channel.send('Kicked!' + member.user.username);
|
108
|
+
}).catch(console.error);
|
109
|
+
}
|
110
|
+
|
111
|
+
if (message.content === 'ratelimittest') {
|
112
|
+
let i = 1;
|
113
|
+
const start = Date.now();
|
114
|
+
while (i <= 20) {
|
115
|
+
message.channel.send(`Testing my rates, item ${i} of 20`);
|
116
|
+
i++;
|
117
|
+
}
|
118
|
+
message.channel.send('last one...').then(m => {
|
119
|
+
const diff = Date.now() - start;
|
120
|
+
m.reply(`Each message took ${diff / 21}ms to send`);
|
121
|
+
});
|
122
|
+
}
|
123
|
+
|
124
|
+
if (message.content === 'makerole') {
|
125
|
+
message.guild.createRole().then(role => {
|
126
|
+
message.channel.send(`Made role ${role.name}`);
|
127
|
+
}).catch(console.error);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
});
|
131
|
+
|
132
|
+
function nameLoop(user) {
|
133
|
+
// user.setUsername(user.username + 'a').then(nameLoop).catch(console.error);
|
134
|
+
}
|
135
|
+
|
136
|
+
function chanLoop(channel) {
|
137
|
+
channel.setName(channel.name + 'a').then(chanLoop).catch(console.error);
|
138
|
+
}
|
139
|
+
|
140
|
+
client.on('message', msg => {
|
141
|
+
if (msg.content.startsWith('?raw')) {
|
142
|
+
msg.channel.send('```' + msg.content + '```');
|
143
|
+
}
|
144
|
+
|
145
|
+
if (msg.content.startsWith('#eval') && msg.author.id === '66564597481480192') {
|
146
|
+
try {
|
147
|
+
const com = eval(msg.content.split(" ").slice(1).join(" "));
|
148
|
+
msg.channel.send('```\n' + com + '```');
|
149
|
+
} catch(e) {
|
150
|
+
msg.channel.send('```\n' + e + '```');
|
151
|
+
}
|
152
|
+
}
|
153
|
+
});
|
154
|
+
|
155
|
+
const ytdl = require('ytdl-core');
|
156
|
+
|
157
|
+
let disp, con;
|
158
|
+
|
159
|
+
client.on('message', msg => {
|
160
|
+
if (msg.content.startsWith('/play')) {
|
161
|
+
console.log('I am now going to play', msg.content);
|
162
|
+
const chan = msg.content.split(' ').slice(1).join(' ');
|
163
|
+
const s = ytdl(chan, {filter:'audioonly'}, { passes : 3 });
|
164
|
+
s.on('error', e => console.log(`e w stream 1 ${e}`));
|
165
|
+
con.playStream(s);
|
166
|
+
}
|
167
|
+
if (msg.content.startsWith('/join')) {
|
168
|
+
const chan = msg.content.split(' ').slice(1).join(' ');
|
169
|
+
msg.channel.guild.channels.get(chan).join()
|
170
|
+
.then(conn => {
|
171
|
+
con = conn;
|
172
|
+
msg.reply('done');
|
173
|
+
const s = ytdl(song, {filter:'audioonly'}, { passes : 3 });
|
174
|
+
s.on('error', e => console.log(`e w stream 2 ${e}`));
|
175
|
+
disp = conn.playStream(s);
|
176
|
+
conn.player.on('debug', console.log);
|
177
|
+
conn.player.on('error', err => console.log(123, err));
|
178
|
+
})
|
179
|
+
.catch(console.error);
|
180
|
+
}
|
181
|
+
});
|
182
|
+
|
183
|
+
client.on('messageReactionAdd', (reaction, user) => {
|
184
|
+
if (reaction.message.channel.id !== '222086648706498562') return;
|
185
|
+
reaction.message.channel.send(`${user.username} added reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
186
|
+
});
|
187
|
+
|
188
|
+
client.on('messageReactionRemove', (reaction, user) => {
|
189
|
+
if (reaction.message.channel.id !== '222086648706498562') return;
|
190
|
+
reaction.message.channel.send(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
191
|
+
});
|
192
|
+
|
193
|
+
client.on('message', m => {
|
194
|
+
if (m.content.startsWith('#reactions')) {
|
195
|
+
const mID = m.content.split(' ')[1];
|
196
|
+
m.channel.fetchMessage(mID).then(rM => {
|
197
|
+
for (const reaction of rM.reactions.values()) {
|
198
|
+
reaction.fetchUsers().then(users => {
|
199
|
+
m.channel.send(
|
200
|
+
`The following gave that message ${reaction.emoji}:\n` +
|
201
|
+
`${users.map(u => u.username).map(t => `- ${t}`).join('\n')}`
|
202
|
+
);
|
203
|
+
});
|
204
|
+
}
|
205
|
+
});
|
206
|
+
}
|
207
|
+
});
|
package/test/shard.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
const Discord = require('../');
|
2
|
+
const { token } = require('./auth.json');
|
3
|
+
|
4
|
+
const client = new Discord.Client({
|
5
|
+
shardId: process.argv[2],
|
6
|
+
shardCount: process.argv[3],
|
7
|
+
});
|
8
|
+
|
9
|
+
client.on('message', msg => {
|
10
|
+
if (msg.content.startsWith('?eval') && msg.author.id === '66564597481480192') {
|
11
|
+
try {
|
12
|
+
const com = eval(msg.content.split(' ').slice(1).join(' '));
|
13
|
+
msg.channel.sendMessage('```\n' + com + '```');
|
14
|
+
} catch (e) {
|
15
|
+
msg.channel.sendMessage('```\n' + e + '```');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
});
|
19
|
+
|
20
|
+
process.send(123);
|
21
|
+
|
22
|
+
client.on('ready', () => {
|
23
|
+
console.log('Ready', client.options.shardId);
|
24
|
+
if (client.options.shardId === 0)
|
25
|
+
setTimeout(() => {
|
26
|
+
console.log('kek dying');
|
27
|
+
client.destroy();
|
28
|
+
}, 5000);
|
29
|
+
});
|
30
|
+
|
31
|
+
client.login(token).catch(console.error);
|
package/test/sharder.js
ADDED
package/test/voice.js
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
/* eslint no-console: 0 */
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const Discord = require('../');
|
5
|
+
const ytdl = require('ytdl-core');
|
6
|
+
|
7
|
+
const client = new Discord.Client({ fetchAllMembers: false, apiRequestMethod: 'sequential' });
|
8
|
+
|
9
|
+
const auth = require('./auth.json');
|
10
|
+
|
11
|
+
client.login(auth.token).then(() => console.log('logged')).catch(console.error);
|
12
|
+
|
13
|
+
const connections = new Map();
|
14
|
+
|
15
|
+
let broadcast;
|
16
|
+
|
17
|
+
client.on('message', m => {
|
18
|
+
if (!m.guild) return;
|
19
|
+
if (m.content.startsWith('/join')) {
|
20
|
+
const channel = m.guild.channels.get(m.content.split(' ')[1]) || m.member.voiceChannel;
|
21
|
+
if (channel && channel.type === 'voice') {
|
22
|
+
channel.join().then(conn => {
|
23
|
+
conn.player.on('error', (...e) => console.log('player', ...e));
|
24
|
+
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
|
25
|
+
m.reply('ok!');
|
26
|
+
});
|
27
|
+
} else {
|
28
|
+
m.reply('Specify a voice channel!');
|
29
|
+
}
|
30
|
+
} else if (m.content.startsWith('/play')) {
|
31
|
+
if (connections.has(m.guild.id)) {
|
32
|
+
const connData = connections.get(m.guild.id);
|
33
|
+
const queue = connData.queue;
|
34
|
+
const url = m.content.split(' ').slice(1).join(' ')
|
35
|
+
.replace(/</g, '')
|
36
|
+
.replace(/>/g, '');
|
37
|
+
queue.push({ url, m });
|
38
|
+
if (queue.length > 1) {
|
39
|
+
m.reply(`OK, that's going to play after ${queue.length - 1} songs`);
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
doQueue(connData);
|
43
|
+
}
|
44
|
+
} else if (m.content.startsWith('/skip')) {
|
45
|
+
if (connections.has(m.guild.id)) {
|
46
|
+
const connData = connections.get(m.guild.id);
|
47
|
+
if (connData.dispatcher) {
|
48
|
+
connData.dispatcher.end();
|
49
|
+
}
|
50
|
+
}
|
51
|
+
} else if (m.content.startsWith('#eval') && m.author.id === '66564597481480192') {
|
52
|
+
try {
|
53
|
+
const com = eval(m.content.split(' ').slice(1).join(' '));
|
54
|
+
m.channel.sendMessage(`\`\`\`\n${com}\`\`\``);
|
55
|
+
} catch (e) {
|
56
|
+
console.log(e);
|
57
|
+
m.channel.sendMessage(`\`\`\`\n${e}\`\`\``);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
|
62
|
+
function doQueue(connData) {
|
63
|
+
const conn = connData.conn;
|
64
|
+
const queue = connData.queue;
|
65
|
+
const item = queue[0];
|
66
|
+
if (!item) return;
|
67
|
+
const stream = ytdl(item.url, { filter: 'audioonly' }, { passes: 3 });
|
68
|
+
const dispatcher = conn.playStream(stream);
|
69
|
+
stream.on('info', info => {
|
70
|
+
item.m.reply(`OK, playing **${info.title}**`);
|
71
|
+
});
|
72
|
+
dispatcher.on('end', () => {
|
73
|
+
queue.shift();
|
74
|
+
doQueue(connData);
|
75
|
+
});
|
76
|
+
dispatcher.on('error', (...e) => console.log('dispatcher', ...e));
|
77
|
+
connData.dispatcher = dispatcher;
|
78
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>discord.js Webpack test</title>
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<script type="text/javascript" src="../webpack/discord.11.4.2.min.js"></script>
|
9
|
+
<script type="text/javascript">
|
10
|
+
(() => {
|
11
|
+
const client = window.client = new Discord.Client();
|
12
|
+
|
13
|
+
client.on('ready', () => {
|
14
|
+
console.log('[CLIENT] Ready!');
|
15
|
+
});
|
16
|
+
|
17
|
+
client.on('error', console.error);
|
18
|
+
|
19
|
+
client.ws.on('close', (event) => console.log('[CLIENT] Disconnect!', event));
|
20
|
+
|
21
|
+
client.on('message', (message) => {
|
22
|
+
console.log(message.author.username, message.author.id, message.content);
|
23
|
+
console.log(message.guild.roles.find("name", "Sever Staff"));
|
24
|
+
});
|
25
|
+
|
26
|
+
client.login(localStorage.token || window.token || prompt('token pls', 'abcdef123456'))
|
27
|
+
.then((token) => localStorage.token = token);
|
28
|
+
})();
|
29
|
+
</script>
|
30
|
+
</body>
|
31
|
+
</html>
|
package/tsconfig.json
ADDED
package/tslint.json
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
{
|
2
|
+
"extends": [
|
3
|
+
"tslint-config-typings"
|
4
|
+
],
|
5
|
+
"rules": {
|
6
|
+
"class-name": true,
|
7
|
+
"comment-format": [
|
8
|
+
true,
|
9
|
+
"check-space"
|
10
|
+
],
|
11
|
+
"indent": [
|
12
|
+
true,
|
13
|
+
"tabs"
|
14
|
+
],
|
15
|
+
"no-duplicate-variable": true,
|
16
|
+
"no-unused-variable": [false],
|
17
|
+
"no-eval": true,
|
18
|
+
"no-internal-module": true,
|
19
|
+
"no-trailing-whitespace": true,
|
20
|
+
"no-unsafe-finally": true,
|
21
|
+
"no-var-keyword": true,
|
22
|
+
"one-line": [
|
23
|
+
true,
|
24
|
+
"check-open-brace",
|
25
|
+
"check-whitespace"
|
26
|
+
],
|
27
|
+
"quotemark": [
|
28
|
+
true,
|
29
|
+
"single"
|
30
|
+
],
|
31
|
+
"semicolon": [
|
32
|
+
true,
|
33
|
+
"always"
|
34
|
+
],
|
35
|
+
"triple-equals": [
|
36
|
+
true,
|
37
|
+
"allow-null-check"
|
38
|
+
],
|
39
|
+
"typedef-whitespace": [
|
40
|
+
true,
|
41
|
+
{
|
42
|
+
"call-signature": "nospace",
|
43
|
+
"index-signature": "nospace",
|
44
|
+
"parameter": "nospace",
|
45
|
+
"property-declaration": "nospace",
|
46
|
+
"variable-declaration": "nospace"
|
47
|
+
}
|
48
|
+
],
|
49
|
+
"variable-name": [
|
50
|
+
true,
|
51
|
+
"ban-keywords"
|
52
|
+
],
|
53
|
+
"whitespace": [
|
54
|
+
true,
|
55
|
+
"check-branch",
|
56
|
+
"check-decl",
|
57
|
+
"check-operator",
|
58
|
+
"check-separator",
|
59
|
+
"check-type"
|
60
|
+
]
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/// <reference path='index.d.ts' />
|
2
|
+
|
3
|
+
import { Collector, Message, CollectorFilter, Client, CollectorHandler, MessageReaction, Collection, User, ReactionCollectorOptions, Snowflake } from 'discord.js';
|
4
|
+
|
5
|
+
const client = new Client({
|
6
|
+
disableEveryone: false,
|
7
|
+
disabledEvents: ['GUILD_MEMBER_ADD']
|
8
|
+
});
|
9
|
+
|
10
|
+
client.on('message', (message) => {
|
11
|
+
if (message.content === 'hello') {
|
12
|
+
message.channel.sendMessage('o/');
|
13
|
+
}
|
14
|
+
|
15
|
+
const collector: ReactionCollector = new ReactionCollector(message,
|
16
|
+
(reaction: MessageReaction) => reaction.emoji.toString() === '👌',
|
17
|
+
{ time: 30e3 });
|
18
|
+
collector.on('end', collected => console.log(collected));
|
19
|
+
});
|
20
|
+
|
21
|
+
client.login('dsfsd754.4fds4f68d4f6sd46f4s.7878easfdsgdfFDSIJIO');
|
22
|
+
|
23
|
+
export class TestCollector extends Collector<Snowflake, Message> {
|
24
|
+
public filter: CollectorFilter;
|
25
|
+
public constructor(client: Client, filter: CollectorFilter) {
|
26
|
+
super(client, filter);
|
27
|
+
}
|
28
|
+
|
29
|
+
public handle(message: Message): CollectorHandler<Snowflake, Message> {
|
30
|
+
return { key: message.id, value: message };
|
31
|
+
}
|
32
|
+
|
33
|
+
public cleanup(): void {}
|
34
|
+
public postCheck(): null { return null; }
|
35
|
+
}
|
36
|
+
|
37
|
+
class ReactionCollector extends Collector<Snowflake, MessageReaction> {
|
38
|
+
public message: Message;
|
39
|
+
public users: Collection<Snowflake, User>;
|
40
|
+
public total: number;
|
41
|
+
public options: ReactionCollectorOptions;
|
42
|
+
public constructor(message: Message, filter: CollectorFilter, options?: ReactionCollectorOptions) {
|
43
|
+
super(message.client, filter, options || {});
|
44
|
+
this.message = message;
|
45
|
+
this.users = new Collection<Snowflake, User>();
|
46
|
+
this.total = 0;
|
47
|
+
this.client.on('messageReactionAdd', this.listener);
|
48
|
+
}
|
49
|
+
|
50
|
+
public handle(reaction: MessageReaction): CollectorHandler<Snowflake, MessageReaction> {
|
51
|
+
if (reaction.message.id !== this.message.id) { return null; }
|
52
|
+
return {
|
53
|
+
key: reaction.emoji.id || reaction.emoji.name,
|
54
|
+
value: reaction
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
public postCheck(reaction: MessageReaction, user: User): string {
|
59
|
+
this.users.set(user.id, user);
|
60
|
+
if (this.options.max && ++this.total >= this.options.max) { return 'limit'; }
|
61
|
+
if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) { return 'emojiLimit'; }
|
62
|
+
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) { return 'userLimit'; }
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
|
66
|
+
public cleanup(): void {
|
67
|
+
this.client.removeListener('messageReactionAdd', this.listener as any);
|
68
|
+
}
|
69
|
+
}
|