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

Commit

Permalink
fix: Fixed most imports and some typescript changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Aug 26, 2023
1 parent 1a7f800 commit 0d9f4bd
Show file tree
Hide file tree
Showing 60 changed files with 486 additions and 263 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"curly": ["error", "all"],
"no-console": ["error"],
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/explicit-module-boundary-types": "off"
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"start-pretty-no-ignore": "node ./dist/index.js | pino-pretty",
"deploy": "node ./dist/utils/deploySlashCommands.js",
"deploy-pretty": "node ./dist/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,shardId,guildId",
"eslint": "eslint ./"
"eslint": "eslint ./src"
},
"dependencies": {
"@discord-player/extractor": "^4.4.2-dev.1",
Expand Down
22 changes: 12 additions & 10 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
require('dotenv').config();
const { registerEventListeners } = require('./utils/registerEventListeners.js');
const { registerClientCommands } = require('./utils/registerClientCommands.js');
const { createClient } = require('./utils/factory/createClient.js');
const { createPlayer } = require('./utils/factory/createPlayer.js');
const { v4: uuidv4 } = require('uuid');
import 'dotenv/config';
import { registerEventListeners } from './utils/registerEventListeners';
import { registerClientCommands } from './utils/registerClientCommands';
import { createClient } from './utils/factory/createClient';
import { createPlayer } from './utils/factory/createPlayer';
import { v4 as uuidv4 } from 'uuid';
import loggerModule from './services/logger';
import { ExtendedClient } from './types/clientTypes';
import { Client } from 'discord.js';

const executionId = uuidv4();

const logger = require('./services/logger').child({
const logger = loggerModule.child({
source: 'bot.js',
module: 'shardingClient',
name: 'shardingClient',
Expand All @@ -16,14 +18,14 @@ const logger = require('./services/logger').child({
});

(async () => {
const client = await createClient({ executionId });
const client: ExtendedClient = await createClient({ executionId });
const player = await createPlayer({ client, executionId });

client.on('allShardsReady', async () => {
client.registerClientCommands = registerClientCommands;
registerEventListeners({ client, player, executionId });
registerClientCommands({ client, executionId });
client.emit('ready', client);
client.emit('ready', client as Client);
});

client.login(process.env.DISCORD_BOT_TOKEN);
Expand Down
8 changes: 5 additions & 3 deletions src/commands/info/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import loggerModule from '../../services/logger';

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -10,7 +12,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, client, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'help.js',
module: 'slashCommand',
name: '/help',
Expand Down
13 changes: 8 additions & 5 deletions src/commands/info/status.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const { getUptimeFormatted } = require('../../utils/system/getUptimeFormatted');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { getUptimeFormatted } from '../../utils/system/getUptimeFormatted';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import osu from 'node-os-utils';
const { version } = require('../../../package.json');
// @ts-ignore
import { version } from '../../../package.json';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -14,7 +17,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, client, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'status.js',
module: 'slashCommand',
name: '/status',
Expand Down
16 changes: 9 additions & 7 deletions src/commands/player/filters.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const ffmpegFilterOptions = config.get('ffmpegFilterOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const {
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import {
SlashCommandBuilder,
EmbedBuilder,
ActionRowBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
ButtonBuilder
} = require('discord.js');
const { useQueue } = require('discord-player');
} from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -22,7 +24,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'filters.js',
module: 'slashCommand',
name: '/filters',
Expand Down
12 changes: 7 additions & 5 deletions src/commands/player/leave.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -13,7 +15,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'leave.js',
module: 'slashCommand',
name: '/leave',
Expand Down
14 changes: 8 additions & 6 deletions src/commands/player/loop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -27,7 +29,7 @@ module.exports = {
)
),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'loop.js',
module: 'slashCommand',
name: '/loop',
Expand Down
20 changes: 11 additions & 9 deletions src/commands/player/lyrics.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useMainPlayer, useQueue, QueryType } = require('discord-player');
const { lyricsExtractor } = require('@discord-player/extractor');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useMainPlayer, useQueue, QueryType } from 'discord-player';
import { lyricsExtractor } from '@discord-player/extractor';
import loggerModule from '../../services/logger';

const recentQueries = new Map();

const loggerTempplate = require('../../services/logger').child({
const loggerTemplate = loggerModule.child({
source: 'lyrics.js',
module: 'slashCommand',
name: '/lyrics'
Expand All @@ -32,7 +34,7 @@ module.exports = {
.setAutocomplete(true)
),
autocomplete: async ({ interaction, executionId }) => {
const logger = loggerTempplate.child({
const logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
Expand Down Expand Up @@ -92,7 +94,7 @@ module.exports = {
return interaction.respond(response);
},
execute: async ({ interaction, executionId }) => {
const logger = loggerTempplate.child({
const logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
Expand Down
14 changes: 8 additions & 6 deletions src/commands/player/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -15,7 +17,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'nowplaying.js',
module: 'slashCommand',
name: '/nowplaying',
Expand Down
14 changes: 8 additions & 6 deletions src/commands/player/pause.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -14,7 +16,7 @@ module.exports = {
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'pause.js',
module: 'slashCommand',
name: '/pause',
Expand Down
24 changes: 13 additions & 11 deletions src/commands/player/play.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions = config.get('botOptions');
const playerOptions = config.get('playerOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { cannotJoinVoiceOrTalk } = require('../../utils/validation/permissionValidator');
const { transformQuery } = require('../../utils/validation/searchQueryValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useMainPlayer, useQueue } = require('discord-player');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { cannotJoinVoiceOrTalk } from '../../utils/validation/permissionValidator';
import { transformQuery } from '../../utils/validation/searchQueryValidator';
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useMainPlayer, useQueue } from 'discord-player';
import loggerModule from '../../services/logger';
import { EmbedOptions } from '../../types/configTypes';

const recentQueries = new Map();

const loggerTempplate = require('../../services/logger').child({
const loggerTemplate = loggerModule.child({
source: 'play.js',
module: 'slashCommand',
name: '/play'
Expand All @@ -34,7 +36,7 @@ module.exports = {
.setAutocomplete(true)
),
autocomplete: async ({ interaction, executionId }) => {
const logger = loggerTempplate.child({
const logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
Expand Down Expand Up @@ -86,7 +88,7 @@ module.exports = {
return interaction.respond(response);
},
execute: async ({ interaction, executionId }) => {
const logger = loggerTempplate.child({
const logger = loggerTemplate.child({
executionId: executionId,
shardId: interaction.guild.shardId,
guildId: interaction.guild.id
Expand Down Expand Up @@ -213,7 +215,7 @@ module.exports = {

if (
(error.type === 'TypeError' &&
(error.message.includes('Cannot read properties of null (reading \'createStream\')') ||
(error.message.includes("Cannot read properties of null (reading 'createStream')") ||
error.message.includes('Failed to fetch resources for ytdl streaming'))) ||
error.message.includes('Could not extract stream for this track')
) {
Expand Down Expand Up @@ -248,7 +250,7 @@ module.exports = {
});
}

if (error.message === 'Cannot read properties of null (reading \'createStream\')') {
if (error.message === "Cannot read properties of null (reading 'createStream')") {
// Can happen if /play then /leave before track starts playing
logger.warn(error, 'Found track but failed to play back audio. Voice connection might be unavailable.');

Expand Down
12 changes: 7 additions & 5 deletions src/commands/player/queue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
const playerOptions = config.get('playerOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -15,7 +17,7 @@ module.exports = {
.setNSFW(false)
.addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'queue.js',
module: 'slashCommand',
name: '/queue',
Expand Down
14 changes: 8 additions & 6 deletions src/commands/player/remove.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import config from 'config';
const embedOptions = config.get('embedOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
import { EmbedOptions } from '../../types/configTypes';
const embedOptions: EmbedOptions = config.get('embedOptions');
import { notInVoiceChannel, notInSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
import{ SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { useQueue } from 'discord-player';
import loggerModule from '../../services/logger';

module.exports = {
isNew: false,
Expand All @@ -21,7 +23,7 @@ module.exports = {
.setRequired(true)
),
execute: async ({ interaction, executionId }) => {
const logger = require('../../services/logger').child({
const logger = loggerModule.child({
source: 'remove.js',
module: 'slashCommand',
name: '/remove',
Expand Down
Loading

0 comments on commit 0d9f4bd

Please sign in to comment.