Improve VC leave handling, host now lets you get the current session host, swapped skip/sticker alias, updated xm plugin

This commit is contained in:
Essem 2022-08-27 13:27:42 -05:00
parent e8337c40f4
commit 3392c3c89e
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
6 changed files with 64 additions and 37 deletions

View file

@ -26,7 +26,7 @@ lavalink:
#searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing
#retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times
plugins:
- dependency: "com.github.esmBot:lava-xm-plugin:v0.2.0"
- dependency: "com.github.esmBot:lava-xm-plugin:v0.2.1"
repository: "https://jitpack.io"
- dependency: "com.github.Topis-Lavalink-Plugins:Topis-Source-Managers-Plugin:v2.0.7"
repository: "https://jitpack.io"

View file

@ -25,7 +25,7 @@ class StickerCommand extends Command {
}
static description = "Gets a raw sticker image";
static aliases = ["s", "stick"];
static aliases = ["stick"];
static arguments = ["[sticker]"];
}

View file

@ -8,7 +8,7 @@ class HostCommand extends MusicCommand {
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.author.id && !process.env.OWNER.split(",").includes(this.connection.host)) return "Only the current voice session host can choose another host!";
const input = this.options.user ?? this.args.join(" ");
if (!input || !input.trim()) return "You need to provide who you want the host to be!";
if (input?.trim()) {
let user;
if (this.type === "classic") {
const getUser = this.message.mentions.length >= 1 ? this.message.mentions[0] : (await this.ipc.fetchUser(input));
@ -31,22 +31,25 @@ class HostCommand extends MusicCommand {
user = input;
}
if (!user) return "I can't find that user!";
if (user.bot) return "Setting a bot as the session host isn't a very good idea.";
if (user.bot) return "This is illegal, you know.";
const member = this.channel.guild ? this.channel.guild.members.get(user.id) : undefined;
if (!member) return "That user isn't in this server!";
const object = this.connection;
object.host = member.id;
players.set(this.channel.guild.id, object);
return `🔊 ${member.mention} is the new voice channel host.`;
} else {
const member = this.channel.guild ? this.channel.guild.members.get(players.get(this.channel.guild.id).host) : undefined;
return `🔊 The current voice channel host is **${member?.username}#${member?.discriminator}**.`;
}
}
static flags = [{
name: "user",
type: 6,
description: "The user you want the new host to be",
required: true
description: "The user you want the new host to be"
}];
static description = "Changes the host of the current voice session";
static description = "Gets or changes the host of the current voice session";
static aliases = ["sethost"];
}

View file

@ -30,7 +30,7 @@ class SkipCommand extends MusicCommand {
}
static description = "Skips the current song";
static aliases = ["forceskip"];
static aliases = ["forceskip", "s"];
}
export default SkipCommand;

View file

@ -2,19 +2,32 @@ import { players, queues, skipVotes } from "../utils/soundplayer.js";
import AwaitRejoin from "../utils/awaitrejoin.js";
import { random } from "../utils/misc.js";
const isWaiting = new Map();
export default async (client, cluster, worker, ipc, member, oldChannel) => {
if (!oldChannel) return;
const connection = players.get(oldChannel.guild.id);
if (oldChannel.id === connection?.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
if (isWaiting.has(oldChannel.id)) return;
isWaiting.set(oldChannel.id, true);
connection.player.setPaused(true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, true);
awaitRejoin.on("end", async (rejoined, member) => {
const awaitRejoin = new AwaitRejoin(oldChannel, true, member.id);
awaitRejoin.on("end", async (rejoined, newMember) => {
isWaiting.delete(oldChannel.id);
if (rejoined) {
connection.player.setPaused(false);
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
if (member.id !== newMember.id) {
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: newMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
waitMessage.edit(`🔊 ${newMember.mention} is the new voice channel host.`);
} else {
try {
await waitMessage.delete();
} catch {
// no-op
}
}
} else {
try {
if (waitMessage.channel.messages.has(waitMessage.id)) await waitMessage.delete();
@ -33,9 +46,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
}
});
} else if (member.id === connection.host) {
if (isWaiting.has(oldChannel.id)) return;
isWaiting.set(oldChannel.id, true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for the host to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, false, member.id);
awaitRejoin.on("end", async (rejoined) => {
isWaiting.delete(oldChannel.id);
if (rejoined) {
try {
if (waitMessage.channel.messages.has(waitMessage.id)) await waitMessage.delete();
@ -67,6 +83,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
}
});
} else if (member.id === client.user.id) {
isWaiting.delete(oldChannel.id);
try {
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
} catch {

View file

@ -1,5 +1,6 @@
// this is a method to wait for someone to rejoin a voice channel
import { EventEmitter } from "events";
import { random } from "./misc.js";
class AwaitRejoin extends EventEmitter {
constructor(channel, anyone, memberID) {
@ -14,14 +15,19 @@ class AwaitRejoin extends EventEmitter {
this.bot.on("voiceChannelJoin", this.listener);
this.bot.on("voiceChannelSwitch", this.listener);
setTimeout(() => this.stop(), 10000);
this.checkInterval = setInterval(() => this.verify({ id: memberID }, channel, true), 1000);
}
verify(member, channel) {
verify(member, channel, checked) {
if (this.channel.id === channel.id) {
if (this.member === member.id || this.anyone) {
if ((this.member === member.id && this.channel.voiceMembers.has(member.id)) || (this.anyone && !checked)) {
this.rejoined = true;
this.stop(member);
return true;
} else if (this.anyone && (!checked || this.channel.voiceMembers.size > 1)) {
this.rejoined = true;
this.stop(random(this.channel.voiceMembers.filter((i) => i.id !== this.bot.user.id && !i.bot)));
return true;
}
} else {
return false;
@ -31,6 +37,7 @@ class AwaitRejoin extends EventEmitter {
stop(member) {
if (this.ended) return;
this.ended = true;
clearInterval(this.checkInterval);
this.bot.removeListener("voiceChannelJoin", this.listener);
this.bot.removeListener("voiceChannelSwitch", this.listener);
this.emit("end", this.rejoined, member);