mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
added join and leave voice channel triggers
This commit is contained in:
parent
8445c37f64
commit
03ead92c19
7 changed files with 207 additions and 1 deletions
|
@ -0,0 +1,58 @@
|
|||
import { typedGuildEventListener } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import { noop } from "../../../utils";
|
||||
|
||||
export const RunAutomodOnVoiceStateUpdate = typedGuildEventListener<AutomodPluginType>()({
|
||||
event: "voiceStateUpdate",
|
||||
async listener({ pluginData, args: { newState, oldState } }) {
|
||||
const oldChannel = newState.channel;
|
||||
const { channel: newChannel, guild } = newState;
|
||||
const timestamp = Date.now();
|
||||
|
||||
const member = newState.member ?? oldState.member ?? (await guild.members.fetch(newState.id).catch(noop));
|
||||
if (!member) return;
|
||||
|
||||
if (!oldChannel && newChannel) {
|
||||
const context: AutomodContext = {
|
||||
member,
|
||||
timestamp,
|
||||
voiceChannel: {
|
||||
joined: newChannel,
|
||||
},
|
||||
user: member.user,
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(() => {
|
||||
runAutomod(pluginData, context);
|
||||
});
|
||||
} else if (oldChannel && !newChannel) {
|
||||
const context: AutomodContext = {
|
||||
member,
|
||||
timestamp,
|
||||
voiceChannel: {
|
||||
left: oldChannel,
|
||||
},
|
||||
user: member.user,
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(() => {
|
||||
runAutomod(pluginData, context);
|
||||
});
|
||||
} else if (oldChannel?.id && newChannel?.id && oldChannel.id === newChannel.id) {
|
||||
const context: AutomodContext = {
|
||||
member,
|
||||
timestamp,
|
||||
voiceChannel: {
|
||||
left: oldChannel,
|
||||
joined: newChannel,
|
||||
},
|
||||
user: member.user,
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(() => {
|
||||
runAutomod(pluginData, context);
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue