Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: annotations for events
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Aug 27, 2023
1 parent 39e8182 commit b118ebd
Show file tree
Hide file tree
Showing 26 changed files with 223 additions and 165 deletions.
2 changes: 1 addition & 1 deletion src/commands/info/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const botOptions: BotOptions = config.get('botOptions');
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/filters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions = config.get('ffmpegFilterOptions');
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/loop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const botOptions: BotOptions = config.get('botOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } from 'discord.js';
Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/play.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const playerOptions = config.get('playerOptions');
const botOptions: BotOptions = config.get('botOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { cannotJoinVoiceOrTalk } from '../../utils/validation/permissionValidator';
import { transformQuery } from '../../utils/validation/searchQueryValidator';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions');
const playerOptions: PlayerOptions = config.get('playerOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
Expand Down
2 changes: 1 addition & 1 deletion src/events/client/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
name: Events.Debug,
isDebug: true,
once: false,
execute: async (message) => {
execute: async (message: string) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'debug.js',
Expand Down
19 changes: 11 additions & 8 deletions src/events/client/disconnect.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { v4 as uuidv4 } from 'uuid';
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
import { EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js';
const systemOptions: SystemOptions = config.get('systemOptions');
import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';

module.exports = {
name: 'disconnect',
isDebug: false,
once: false,
execute: async (client) => {
execute: async (client: ExtendedClient) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'disconnect.js',
module: 'event',
name: 'clientDisconnect',
executionId: executionId,
shardId: client.shard.ids[0]
shardId: client.shard?.ids[0]
});

logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`);
logger.warn(`${client.user?.tag} lost connection to Discord APIs. Disconnected.`);

// send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
const channel = (await client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
`${embedOptions.icons.warning} **${client.user?.tag}** is **\`disconnected\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
Expand Down
2 changes: 1 addition & 1 deletion src/events/client/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
name: Events.Error,
isDebug: false,
once: false,
execute: async (error) => {
execute: async (error: Error) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'error.js',
Expand Down
4 changes: 2 additions & 2 deletions src/events/client/guildCreate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Events } from 'discord.js';
import { Events, Guild } from 'discord.js';
import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger';

module.exports = {
name: Events.GuildCreate,
isDebug: false,
once: false,
execute: async (guild) => {
execute: async (guild: Guild) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'guildCreate.js',
Expand Down
4 changes: 2 additions & 2 deletions src/events/client/guildDelete.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Events } from 'discord.js';
import { Events, Guild } from 'discord.js';
import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger';

module.exports = {
name: Events.GuildDelete,
isDebug: false,
once: false,
execute: async (guild) => {
execute: async (guild: Guild) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'guildDelete.js',
Expand Down
25 changes: 13 additions & 12 deletions src/events/client/ready.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
import { EmbedOptions, LoadTestOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions');
const presenceStatusOptions = config.get('presenceStatusOptions');
const loadTestOptions = config.get('loadTestOptions');
const systemOptions: SystemOptions = config.get('systemOptions');
const presenceStatusOptions: PresenceData = config.get('presenceStatusOptions');
const loadTestOptions: LoadTestOptions = config.get('loadTestOptions');
import { postBotStats } from '../../utils/other/postBotStats';
import { startLoadTest } from '../../utils/other/startLoadTest';
import { Events, EmbedBuilder } from 'discord.js';
import { Events, EmbedBuilder, PresenceData, BaseGuildTextChannel } from 'discord.js';
import { v4 as uuidv4 } from 'uuid';
import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';

module.exports = {
name: Events.ClientReady,
isDebug: false,
once: false,
execute: async (client) => {
execute: async (client: ExtendedClient) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'ready.js',
module: 'event',
name: 'clientReady',
executionId: executionId,
shardId: client.shard.ids[0]
shardId: client.shard?.ids[0]
});

logger.debug('Client \'ready\' event received after \'allShardsReady\' event.');
await client.user.setPresence(presenceStatusOptions);
logger.debug("Client 'ready' event received after 'allShardsReady' event.");
await client.user?.setPresence(presenceStatusOptions);

if (loadTestOptions.enabled) {
// Only call function from shard with id 0
// The function uses broadcastEval() to call itself on all shards
if (client.shard.ids[0] === 0) {
if (client.shard?.ids[0] === 0) {
logger.info('Initiating load test for bot client.');
await startLoadTest({ client, executionId });
}
}

const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
const channel = (await client.channels.cache.get(systemOptions.systemMessageChannelId)) as BaseGuildTextChannel;

// Check if the channel exists in curent shard and send a message
if (channel) {
Expand All @@ -45,7 +46,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.success} All shards ready**\n**${client.user.tag}** is now **\`online\`**!`
`**${embedOptions.icons.success} All shards ready**\n**${client.user?.tag}** is now **\`online\`**!`
)
.setColor(embedOptions.colors.success)
]
Expand Down
17 changes: 10 additions & 7 deletions src/events/client/reconnecting.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import { v4 as uuidv4 } from 'uuid';
import config from 'config';
import { EmbedOptions } from '../../types/configTypes';
import { EmbedOptions, SystemOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const systemOptions = config.get('systemOptions');
import { EmbedBuilder } from 'discord.js';
const systemOptions: SystemOptions = config.get('systemOptions');
import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';
import { ExtendedClient } from '../../types/clientTypes';

module.exports = {
name: 'reconnecting',
isDebug: false,
once: false,
execute: async (client) => {
execute: async (client: ExtendedClient) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'reconnecting.js',
module: 'event',
name: 'clientReconnecting',
executionId: executionId,
shardId: client.shard.ids[0]
shardId: client.shard?.ids[0]
});

logger.warn('Client is reconnecting to Discord APIs.');

// send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
const channel = (await client.channels.cache.get(
systemOptions.systemMessageChannelId
)) as BaseGuildTextChannel;
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
`${embedOptions.icons.warning} **${client.user?.tag}** is **\`reconnecting\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
Expand Down
2 changes: 1 addition & 1 deletion src/events/client/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
name: Events.Warn,
isDebug: false,
once: false,
execute: async (warning) => {
execute: async (warning: string) => {
const executionId = uuidv4();
const logger = loggerModule.child({
source: 'warn.js',
Expand Down
Loading

0 comments on commit b118ebd

Please sign in to comment.