mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 05:43:38 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
34b7bf8f19 | |||
18a03d50ee | |||
6c89770d16 | |||
dc5a9d4e71 | |||
e479e5a82a | |||
6afe6c30f9 | |||
17161b72b9 | |||
3cb54c9470 | |||
751f9989eb | |||
6c860b6b23 | |||
0bfb34c1dd |
643
package-lock.json
generated
643
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eximiabots-radiox",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.4",
|
||||
"description": "Internet Radio to your Discord guild",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -18,7 +18,7 @@
|
||||
"url": "https://github.com/warengroup/eximiabots-radiox/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.5.3",
|
||||
"@discordjs/opus": "^0.6.0",
|
||||
"@discordjs/voice": "^0.6.0",
|
||||
"discord-api-types": "^0.22.0",
|
||||
"discord.js": "^13.1.0",
|
||||
@ -34,12 +34,12 @@
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"eslint-plugin-prettier": "^3.4.1",
|
||||
"nodemon": "^2.0.12",
|
||||
"prettier": "^2.3.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-node": "^10.1.0",
|
||||
"tsc-watch": "^4.4.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"tsc-watch": "^4.5.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"engines": {
|
||||
|
@ -27,8 +27,9 @@ module.exports = {
|
||||
msg.channel.send({ embeds: [embed] });
|
||||
} else {
|
||||
const categories = [];
|
||||
let commandsToArray = Array.from(client.commands.values());
|
||||
for (let i = 0; i < client.commands.size; i++) {
|
||||
if (!categories.includes(client.commands.array()[i].category)) categories.push(client.commands.array()[i].category);
|
||||
if (!categories.includes(commandsToArray[i].category)) categories.push(commandsToArray[i].category);
|
||||
}
|
||||
let commands = '';
|
||||
for (let i = 0; i < categories.length; i++) {
|
||||
|
@ -4,7 +4,6 @@ const {
|
||||
getVoiceConnection,
|
||||
joinVoiceChannel
|
||||
} = require("@discordjs/voice");
|
||||
const { createDiscordJSAdapter } = require("../utils/adapter");
|
||||
|
||||
module.exports = {
|
||||
name: "play",
|
||||
@ -99,7 +98,7 @@ module.exports = {
|
||||
joinVoiceChannel({
|
||||
channelId: voiceChannel.id,
|
||||
guildId: voiceChannel.guild.id,
|
||||
adapterCreator: createDiscordJSAdapter(voiceChannel)
|
||||
adapterCreator: voiceChannel.guild.voiceAdapterCreator
|
||||
});
|
||||
construct.connection = connection;
|
||||
let date = new Date();
|
||||
|
@ -2,7 +2,6 @@ const {
|
||||
getVoiceConnection,
|
||||
joinVoiceChannel
|
||||
} = require("@discordjs/voice");
|
||||
const { createDiscordJSAdapter } = require("../utils/adapter");
|
||||
|
||||
module.exports = {
|
||||
name: "voiceStateUpdate",
|
||||
@ -29,7 +28,7 @@ module.exports = {
|
||||
radio.connection = joinVoiceChannel({
|
||||
channelId: oldState.channel.id,
|
||||
guildId: oldState.channel.guild.id,
|
||||
adapterCreator: createDiscordJSAdapter(oldState.channel)
|
||||
adapterCreator: oldState.channel.guild.voiceAdapterCreator
|
||||
})
|
||||
//radio.connection = await oldState.channel.join()
|
||||
),
|
||||
|
@ -7,7 +7,7 @@ module.exports = {
|
||||
bugTitle: "Found a bug with %client.user.username%?",
|
||||
bugDescription: "Join the support server \n %client.config.supportGuild%",
|
||||
helpTitle: "%client.user.username% help:",
|
||||
helpDescription: "%commands% \n %client.config.prefix%help <command> to see more information about a command.",
|
||||
helpDescription: "%commands%",
|
||||
helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%",
|
||||
helpCommandDescription: "%command.description% \n Command Alias: %command.alias%",
|
||||
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
||||
|
@ -1,70 +0,0 @@
|
||||
import { DiscordGatewayAdapterCreator, DiscordGatewayAdapterLibraryMethods } from '@discordjs/voice';
|
||||
import { VoiceChannel, Snowflake, Client, Constants, WebSocketShard, Guild, StageChannel } from 'discord.js';
|
||||
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v9';
|
||||
|
||||
const adapters = new Map<Snowflake, DiscordGatewayAdapterLibraryMethods>();
|
||||
const trackedClients = new Set<Client>();
|
||||
|
||||
/**
|
||||
* Tracks a Discord.js client, listening to VOICE_SERVER_UPDATE and VOICE_STATE_UPDATE events.
|
||||
* @param client - The Discord.js Client to track
|
||||
*/
|
||||
function trackClient(client: Client) {
|
||||
if (trackedClients.has(client)) return;
|
||||
trackedClients.add(client);
|
||||
client.ws.on(Constants.WSEvents.VOICE_SERVER_UPDATE, (payload: GatewayVoiceServerUpdateDispatchData) => {
|
||||
adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
||||
});
|
||||
client.ws.on(Constants.WSEvents.VOICE_STATE_UPDATE, (payload: GatewayVoiceStateUpdateDispatchData) => {
|
||||
if (payload.guild_id && payload.session_id && payload.user_id === client.user?.id) {
|
||||
adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const trackedGuilds = new Map<WebSocketShard, Set<Snowflake>>();
|
||||
|
||||
function cleanupGuilds(shard: WebSocketShard) {
|
||||
const guilds = trackedGuilds.get(shard);
|
||||
if (guilds) {
|
||||
for (const guildID of guilds.values()) {
|
||||
adapters.get(guildID)?.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function trackGuild(guild: Guild) {
|
||||
let guilds = trackedGuilds.get(guild.shard);
|
||||
if (!guilds) {
|
||||
const cleanup = () => cleanupGuilds(guild.shard);
|
||||
guild.shard.on('close', cleanup);
|
||||
guild.shard.on('destroyed', cleanup);
|
||||
guilds = new Set();
|
||||
trackedGuilds.set(guild.shard, guilds);
|
||||
}
|
||||
guilds.add(guild.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an adapter for a Voice Channel
|
||||
* @param channel - The channel to create the adapter for
|
||||
*/
|
||||
export function createDiscordJSAdapter(channel: VoiceChannel | StageChannel): DiscordGatewayAdapterCreator {
|
||||
return (methods) => {
|
||||
adapters.set(channel.guild.id, methods);
|
||||
trackClient(channel.client);
|
||||
trackGuild(channel.guild);
|
||||
return {
|
||||
sendPayload(data) {
|
||||
if (channel.guild.shard.status === Constants.Status.READY) {
|
||||
channel.guild.shard.send(data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
destroy() {
|
||||
return adapters.delete(channel.guild.id);
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user