Skip to content

Commit

Permalink
Make Portal great again
Browse files Browse the repository at this point in the history
  • Loading branch information
keybraker committed Nov 4, 2024
1 parent 9f04cfb commit b57e676
Show file tree
Hide file tree
Showing 22 changed files with 2,461 additions and 1,985 deletions.
3,435 changes: 2,019 additions & 1,416 deletions package-lock.json

Large diffs are not rendered by default.

81 changes: 40 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "portal",
"author": "Ioannis Tsiakkas",
"version": "0.4.0",
"version": "0.7.0",
"private": true,
"main": "src/app.ts",
"scripts": {
Expand All @@ -19,49 +19,48 @@
}
},
"dependencies": {
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.0",
"@types/jsonfile": "^6.1.1",
"cheerio": "^1.0.0-rc.12",
"core-util-is": "^1.0.3",
"dayjs": "^1.11.9",
"discord-ytdl-core": "^5.0.4",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"eslint-config-prettier": "^9.0.0",
"ffmpeg-static": "^5.2.0",
"jest": "^29.6.4",
"jsonfile": "^6.1.0",
"lodash": "^4.17.21",
"mongoose": "^7.4.5",
"optionator": "^0.9.3",
"opusscript": "0.1.0",
"roll": "^1.3.1",
"voca": "^1.4.1",
"winston": "^3.10.0",
"yt-search": "^2.10.4",
"ytdl-core": "^4.11.5"
"@discordjs/opus": "0.9.0",
"@discordjs/voice": "0.17.0",
"@types/jsonfile": "6.1.4",
"cheerio": "1.0.0-rc.12",
"core-util-is": "1.0.3",
"dayjs": "1.11.13",
"discord-ytdl-core": "5.0.4",
"discord.js": "14.16.3",
"dotenv": "16.4.5",
"eslint-config-prettier": "9.1.0",
"ffmpeg-static": "5.2.0",
"jsonfile": "6.1.0",
"lodash": "4.17.21",
"mongoose": "8.8.0",
"optionator": "0.9.4",
"opusscript": "0.1.1",
"roll": "1.3.2",
"voca": "1.4.1",
"winston": "3.16.0",
"yt-search": "2.12.1",
"ytdl-core": "4.11.5"
},
"devDependencies": {
"@types/jest": "^29.5.4",
"@types/lodash": "^4.14.197",
"@types/node": "^20.5.7",
"@types/node-fetch": "2.6.4",
"@types/roll": "^1.2.0",
"@types/voca": "^1.4.2",
"@types/ws": "^8.5.5",
"@types/yt-search": "^2.10.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "^8.48.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"nodemon": "^3.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"@types/jest": "29.5.4",
"@types/lodash": "4.14.197",
"@types/node": "20.5.7",
"@types/node-fetch": "2.6.11",
"@types/roll": "1.2.3",
"@types/voca": "1.4.6",
"@types/ws": "8.5.13",
"@types/yt-search": "2.10.3",
"@typescript-eslint/eslint-plugin": "6.5.0",
"@typescript-eslint/parser": "6.5.0",
"eslint": "8.48.0",
"eslint-plugin-prettier": "5.2.1",
"husky": "8.0.3",
"lint-staged": "14.0.1",
"nodemon": "3.1.7",
"ts-jest": "29.2.5",
"typescript": "5.6.3"
},
"optionalDependencies": {
"fsevents": "^2.3.3"
"fsevents": "2.3.3"
}
}
43 changes: 1 addition & 42 deletions src/commands/auth/announcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SlashCommandBuilder } from '@discordjs/builders';
import { ChatInputCommandInteraction, NewsChannel, TextBasedChannel, VoiceChannel } from 'discord.js';
import {
deleteChannel,
doesChannelHaveUsage,
isAnnouncementChannel,
isMusicChannel,
isUrlOnlyChannel
Expand Down Expand Up @@ -88,45 +89,3 @@ export = {
};
},
} as Command;

async function doesChannelHaveUsage(textBasedChannelId: TextBasedChannel['id'], pGuild: PGuild) {
if (!textBasedChannelId) {
return {
result: false,
value: 'could not get channel id',
};
}

if (isAnnouncementChannel(textBasedChannelId, pGuild)) {
const response = await updateGuild(pGuild.id, 'announcement', 'null').catch(() => {
return {
result: true,
value: 'failed to remove announcement channel',
};
});

return {
result: true,
value: response ? 'successfully removed announcement channel' : 'failed to remove announcement channel',
};
}

if (isMusicChannel(textBasedChannelId, pGuild)) {
return {
result: true,
value: 'this can\'t be set as an announcement channel for it is the music channel',
};
}

if (isUrlOnlyChannel(textBasedChannelId, pGuild)) {
return {
result: true,
value: 'this can\'t be set as the announcement channel for it is an url channel',
};
}

return {
result: false,
value: '',
};
}
229 changes: 53 additions & 176 deletions src/commands/auth/music.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { ChatInputCommandInteraction, TextChannel, VoiceChannel } from 'discord.js';

import { deleteChannel, doesChannelHaveUsage } from '../../libraries/guild.library';
import { createMusicLyricsMessage, createMusicMessage, messageHelp } from '../../libraries/help.library';
import { Command } from '../../types/Command';
import { PGuild } from '../../types/classes/PGuild.class';
import { ReturnPromise, ScopeLimit } from '../../types/classes/PTypes.interface';
import { PortalChannelType } from '../../types/enums/PortalChannel.enum';

const COMMAND_NAME = 'music';
const DESCRIPTION = 'set a music channel';
Expand All @@ -25,183 +31,54 @@ export = {
.setDescription('whether or not to delete the previous music channel')
.setRequired(false))
.setDMPermission(false),
async execute(/* interaction: ChatInputCommandInteraction, pGuild: PGuild */): Promise<ReturnPromise> {
async execute(interaction: ChatInputCommandInteraction, pGuild: PGuild): Promise<ReturnPromise> {
const musicChannel = interaction.options.getChannel('music_channel');
const deletePreviousMusicChannel = interaction.options.getChannel('delete_previous');

if (!musicChannel) {
return {
result: false,
value: messageHelp('commands', 'music'),
};
}

if (!(musicChannel instanceof TextChannel)) {
return {
result: false,
value: messageHelp('commands', 'music', 'channel must be text channel'),
};
}

if (!musicChannel.isTextBased) {
return {
result: false,
value: messageHelp('commands', 'music', 'channel must be text channel'),
};
}

const channelHasUsage = await doesChannelHaveUsage(musicChannel.id, pGuild);
if (channelHasUsage.result) {
return {
result: false,
value: channelHasUsage.value,
};
}

if (deletePreviousMusicChannel) {
const music = interaction?.guild?.channels.cache
.find((channel) => channel.id == pGuild.musicData.channelId) as VoiceChannel;

if (music) {
deleteChannel(PortalChannelType.music, music, interaction);
}
}

const musicMessageId = await createMusicMessage(musicChannel, pGuild);
await createMusicLyricsMessage(musicChannel, pGuild, musicMessageId);

return {
result: false,
value: 'not yet implemented',
result: true,
value: 'new music channel set successfully',
};

// const musicChannel = interaction.options.getChannel('music_channel');
// const deletePreviousMusicChannel = interaction.options.getChannel('delete_previous');

// if (!musicChannel) {
// return {
// result: false,
// value: messageHelp('commands', 'music'),
// };
// }

// if (!(musicChannel instanceof NewsChannel)) {
// return {
// result: false,
// value: messageHelp('commands', 'announcement', 'channel must be news channel'),
// };
// }

// if (!musicChannel.isTextBased) {
// return {
// result: false,
// value: messageHelp('commands', 'announcement', 'channel must be text channel'),
// };
// }

// if (!interaction.guild) {
// return {
// result: false,
// value: "message's guild could not be fetched",
// };
// }

// if (!interaction?.channel?.id) {
// return {
// result: false,
// value: "message's channel could not be fetched",
// };
// }

// if (args.length === 0) {
// if (isMusicChannel(interaction.channel.id, pGuild)) {
// const musicData = new MusicData('null', 'null', 'null', [], false);
// const musicDataResponse = await setMusicData(pGuild.id, musicData);

// return {
// result: !!musicDataResponse,
// value: musicDataResponse ? 'successfully removed music channel' : 'failed to remove music channel',
// };
// }

// if (isAnnouncementChannel(interaction.channel.id, pGuild)) {
// return {
// result: false,
// value: "this can't be set as the music channel for it is the announcement channel",
// };
// }

// if (isUrlOnlyChannel(interaction.channel.id, pGuild)) {
// return {
// result: false,
// value: "this can't be set as the Music channel for it is an url channel",
// };
// }
// }

// const musicChannel = interaction.guild.channels.cache.find((channel) => channel.id == pGuild.musicData.channelId);

// if (musicChannel) {
// const deletionResponse = await deleteChannel(PortalChannelTypes.music, <TextChannel>musicChannel, interaction)

// if (!deletionResponse) {
// return {
// result: false,
// value: `failed to delete channel`,
// };
// }
// }

// if (args.length === 0) {
// pGuild.musicData.channelId = interaction.channel.id;
// const newMusic = <TextChannel>(
// interaction.guild.channels.cache.find((channel) => channel.id == pGuild.musicData.channelId)
// );

// if (!newMusic) {
// return {
// result: false,
// value: 'channel could not be fetched',
// };
// }

// const musicMessageId = await createMusicMessage(newMusic, pGuild);

// if (!musicMessageId) {
// logger.log({ level: 'error', type: 'none', message: `failed to send music message` });
// return {
// result: false,
// value: `failed to send music message`,
// };
// }

// logger.log({ level: 'info', type: 'none', message: `created music message ${musicMessageId}` });

// const lyricsMessageId = await createMusicLyricsMessage(newMusic, pGuild, musicMessageId);

// if (!lyricsMessageId) {
// logger.log({
// level: 'error',
// type: 'none',
// message: new Error(`error creating lyrics message`).message,
// });
// return {
// result: false,
// value: `error creating lyrics message`,
// };
// }

// logger.log({
// level: 'info',
// type: 'none',
// message: `created lyrics message ${lyricsMessageId}`,
// });

// return {
// result: true,
// value: 'this is now the Music channel',
// };
// } else if (args.length > 0) {
// const musicChannel = args.join(' ').substring(0, args.join(' ').indexOf('|'));
// const musicCategory = args.join(' ').substring(args.join(' ').indexOf('|') + 1);

// if (musicChannel === '' && musicCategory === '') {
// return {
// result: false,
// value: messageHelp('commands', 'music'),
// };
// }

// if (musicChannel !== '') {
// const newMusicChannel = await createMusicChannel(interaction.guild, musicChannel, musicCategory, pGuild);

// if (!newMusicChannel) {
// return {
// result: false,
// value: `failed to create music channel`,
// };
// }

// return {
// result: true,
// value: 'music channel and category have been created'
// }
// } else if (musicChannel === '' && musicCategory !== '') {
// const newMusicChannel = await createMusicChannel(interaction.guild, musicCategory, null, pGuild)

// if (!newMusicChannel) {
// return {
// result: false,
// value: `failed to create music channel`,
// };
// }

// return {
// result: true,
// value: 'music channel has been created'
// }
// }
// }

// return {
// result: false,
// value: messageHelp('commands', 'music'),
// };
},
} as Command;
Loading

0 comments on commit b57e676

Please sign in to comment.