Ethan Lane
efb431ef3a
All checks were successful
continuous-integration/drone/push Build is passing
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Fix the nickname changed event not working - This was due to the default value not being set because of a typo - Update the client to allow partials for guild members #353 ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. - This has been tested locally by making sure the nickname change event fires when expected # Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/385 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
95 lines
3.8 KiB
TypeScript
95 lines
3.8 KiB
TypeScript
import { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
|
|
import { EventType } from "../constants/EventType";
|
|
import IEventItem from "../contracts/IEventItem";
|
|
import { CoreClient } from "./client";
|
|
|
|
export class Util {
|
|
public loadSlashCommands(client: Client) {
|
|
const registeredCommands = CoreClient.commandItems;
|
|
|
|
const globalCommands = registeredCommands.filter(x => !x.ServerId);
|
|
const guildCommands = registeredCommands.filter(x => x.ServerId);
|
|
|
|
const globalCommandData: SlashCommandBuilder[] = globalCommands
|
|
.filter(x => x.Command.CommandBuilder)
|
|
.flatMap(x => x.Command.CommandBuilder);
|
|
|
|
const guildIds: string[] = [];
|
|
|
|
for (let command of guildCommands) {
|
|
if (!guildIds.find(x => x == command.ServerId)) {
|
|
guildIds.push(command.ServerId!);
|
|
}
|
|
}
|
|
|
|
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!);
|
|
|
|
rest.put(
|
|
Routes.applicationCommands(process.env.BOT_CLIENTID!),
|
|
{
|
|
body: globalCommandData
|
|
}
|
|
);
|
|
|
|
for (let guild of guildIds) {
|
|
const guildCommandData = guildCommands.filter(x => x.ServerId == guild)
|
|
.filter(x => x.Command.CommandBuilder)
|
|
.flatMap(x => x.Command.CommandBuilder);
|
|
|
|
if (!client.guilds.cache.has(guild)) continue;
|
|
|
|
rest.put(
|
|
Routes.applicationGuildCommands(process.env.BOT_CLIENTID!, guild),
|
|
{
|
|
body: guildCommandData
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
// Load the events
|
|
loadEvents(client: Client, events: IEventItem[]) {
|
|
events.forEach((e) => {
|
|
switch(e.EventType) {
|
|
case EventType.ChannelCreate:
|
|
client.on('channelCreate', (channel) => e.ExecutionFunction(channel));
|
|
break;
|
|
case EventType.ChannelDelete:
|
|
client.on('channelDelete', (channel) => e.ExecutionFunction(channel));
|
|
break;
|
|
case EventType.ChannelUpdate:
|
|
client.on('channelUpdate', (channel) => e.ExecutionFunction(channel));
|
|
break;
|
|
case EventType.GuildBanAdd:
|
|
client.on('guildBanAdd', (ban) => e.ExecutionFunction(ban));
|
|
break;
|
|
case EventType.GuildBanRemove:
|
|
client.on('guildBanRemove', (ban) => e.ExecutionFunction(ban));
|
|
break;
|
|
case EventType.GuildCreate:
|
|
client.on('guildCreate', (guild) => e.ExecutionFunction(guild));
|
|
break;
|
|
case EventType.GuildMemberAdd:
|
|
client.on('guildMemberAdd', (member) => e.ExecutionFunction(member));
|
|
break;
|
|
case EventType.GuildMemberRemove:
|
|
client.on('guildMemberRemove', (member) => e.ExecutionFunction(member));
|
|
break;
|
|
case EventType.GuildMemberUpdate:
|
|
client.on('guildMemberUpdate', (oldMember, newMember) => e.ExecutionFunction(oldMember, newMember));
|
|
break;
|
|
case EventType.MessageCreate:
|
|
client.on('messageCreate', (message) => e.ExecutionFunction(message));
|
|
break;
|
|
case EventType.MessageDelete:
|
|
client.on('messageDelete', (message) => e.ExecutionFunction(message));
|
|
break;
|
|
case EventType.MessageUpdate:
|
|
client.on('messageUpdate', (oldMessage, newMessage) => e.ExecutionFunction(oldMessage, newMessage));
|
|
break;
|
|
default:
|
|
console.error('Event not implemented.');
|
|
}
|
|
});
|
|
}
|
|
}
|