Skip to content

Commit

Permalink
V14 (#473)
Browse files Browse the repository at this point in the history
* Update all package.json

* v14 poc

* Update yarn.lock

* Fix typo
  • Loading branch information
KevinBacabac authored May 17, 2023
1 parent a6d4be4 commit ccaa254
Show file tree
Hide file tree
Showing 30 changed files with 647 additions and 478 deletions.
61 changes: 31 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,48 @@
"author": "",
"license": "ISC",
"dependencies": {
"@sapphire/decorators": "^4.2.3",
"@sapphire/framework": "3.0.0-next.8198e94.0",
"@sapphire/plugin-logger": "^2.1.3",
"@sapphire/plugin-subcommands": "^2.1.3",
"@sapphire/utilities": "^3.3.0",
"@types/node-fetch": "^2.6.2",
"@sapphire/decorators": "^4.3.8",
"@sapphire/framework": "4.2.2",
"@sapphire/pieces": "^3.6.1",
"@sapphire/plugin-logger": "^2.2.3",
"@sapphire/plugin-subcommands": "^4.0.0",
"@sapphire/utilities": "^3.11.0",
"@types/node-fetch": "^2.6.3",
"axios": "^0.27.2",
"concurrently": "^6.1.0",
"concurrently": "^6.5.1",
"cron": "^1.8.2",
"discord.js": "^13.15.0",
"dotenv": "^8.2.0",
"discord.js": "14.9.0",
"dotenv": "^8.6.0",
"emoji-regex": "^10.2.1",
"engine-blackjack-ts": "^0.9.11",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"node-fetch": "^2.6.2",
"moment": "^2.29.4",
"node-fetch": "^2.6.9",
"pdf-lib": "^1.17.1",
"pdf2pic": "^2.1.4",
"sqlite": "^4.0.22",
"sqlite3": "^5.0.2",
"sqlite": "^4.1.2",
"sqlite3": "^5.1.6",
"stable-marriage": "^1.0.2",
"turndown": "^7.1.1",
"typescript": "^4.6.3",
"winston": "^3.8.1"
"turndown": "^7.1.2",
"typescript": "^4.9.5",
"winston": "^3.8.2"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.0",
"@types/cron": "^1.7.2",
"@types/js-yaml": "^4.0.1",
"@types/lodash": "^4.14.168",
"@types/node": "^15.0.1",
"@types/sqlite3": "^3.1.7",
"@tsconfig/node14": "^1.0.3",
"@types/cron": "^1.7.3",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.192",
"@types/node": "^15.14.9",
"@types/sqlite3": "^3.1.8",
"@types/turndown": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"nodemon": "^2.0.7",
"prettier": "^2.7.1",
"tsc-watch": "^4.4.0"
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^3.4.1",
"nodemon": "^2.0.22",
"prettier": "^2.8.7",
"tsc-watch": "^4.6.2"
}
}
28 changes: 18 additions & 10 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dotenv from 'dotenv';
dotenv.config();

import { GatewayIntentBits, Partials } from 'discord.js';
import { container, LogLevel, SapphireClient, SapphirePrefix } from '@sapphire/framework';
import '@sapphire/plugin-logger/register';
import * as colorette from 'colorette';
Expand All @@ -27,17 +28,24 @@ const client = new SapphireClient({
},
shards: 'auto',
intents: [
'GUILDS',
'GUILD_MEMBERS',
'GUILD_BANS',
'GUILD_EMOJIS_AND_STICKERS',
'GUILD_VOICE_STATES',
'GUILD_MESSAGES',
'GUILD_MESSAGE_REACTIONS',
'DIRECT_MESSAGES',
'DIRECT_MESSAGE_REACTIONS',
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Channel,
Partials.GuildMember,
Partials.Message,
Partials.Reaction,
Partials.User,
],
partials: ['CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'USER'],
});

container.botPrefix = client.options.defaultPrefix!;
Expand Down
41 changes: 23 additions & 18 deletions src/codeyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import {
} from '@sapphire/framework';
import { APIMessage, APIApplicationCommandOptionChoice } from 'discord-api-types/v9';
import {
ApplicationCommandOptionType,
BaseMessageOptions,
CommandInteraction,
Message,
MessagePayload,
User,
WebhookEditMessageOptions,
} from 'discord.js';
import { logger } from './logger/default';
import { CodeyUserError } from './codeyUserError';
Expand All @@ -30,7 +31,7 @@ export type SapphireSentMessageType = Message | CommandInteraction;
export type SapphireMessageResponse =
| string
| MessagePayload
| WebhookEditMessageOptions
| BaseMessageOptions
// void when the command handles sending a response on its own
| void;
export class SapphireMessageResponseWithMetadata {
Expand All @@ -45,8 +46,8 @@ export class SapphireMessageResponseWithMetadata {

export type SapphireMessageExecuteType = (
client: SapphireClient<boolean>,
// Message is for normal commands, ChatInputInteraction is for slash commands
messageFromUser: Message | SapphireCommand.ChatInputInteraction,
// Message is for normal commands, ChatInputCommandInteraction is for slash commands
messageFromUser: Message | SapphireCommand.ChatInputCommandInteraction,
// Command arguments
args: CodeyCommandArguments,
) => Promise<SapphireMessageResponse | SapphireMessageResponseWithMetadata>;
Expand All @@ -61,15 +62,15 @@ export type SapphireAfterReplyType = (
// Command options
/** The type of the codey command option */
export enum CodeyCommandOptionType {
STRING = 'string',
INTEGER = 'integer',
BOOLEAN = 'boolean',
USER = 'user',
CHANNEL = 'channel',
ROLE = 'role',
MENTIONABLE = 'mentionable',
NUMBER = 'number',
ATTACHMENT = 'attachment',
STRING = ApplicationCommandOptionType.String,
INTEGER = ApplicationCommandOptionType.Integer,
BOOLEAN = ApplicationCommandOptionType.Boolean,
USER = ApplicationCommandOptionType.User,
CHANNEL = ApplicationCommandOptionType.Channel,
ROLE = ApplicationCommandOptionType.Role,
MENTIONABLE = ApplicationCommandOptionType.Mentionable,
NUMBER = ApplicationCommandOptionType.Number,
ATTACHMENT = ApplicationCommandOptionType.Attachment,
}

/** The codey command option */
Expand Down Expand Up @@ -188,7 +189,7 @@ const setCommandSubcommand = (
* This method helps generalize this process.
* */
export const getUserFromMessage = (
message: Message | SapphireCommand.ChatInputInteraction,
message: Message | SapphireCommand.ChatInputCommandInteraction,
): User => {
if (message instanceof Message) {
return message.author;
Expand Down Expand Up @@ -269,11 +270,15 @@ export class CodeyCommand extends SapphireCommand {
// take all remaining arguments given if this is the last argument option
if (i == commandDetails.options!.length - 1) {
args[commandOption.name] = <CodeyCommandArgumentValueType>(
await commandArgs.rest(<keyof ArgType>commandOption.type)
await commandArgs.rest(
<keyof ArgType>ApplicationCommandOptionType[commandOption.type].toLowerCase(),
)
);
} else {
args[commandOption.name] = <CodeyCommandArgumentValueType>(
await commandArgs.pick(<keyof ArgType>commandOption.type)
await commandArgs.pick(
<keyof ArgType>ApplicationCommandOptionType[commandOption.type].toLowerCase(),
)
);
}
} catch (e) {}
Expand Down Expand Up @@ -314,7 +319,7 @@ export class CodeyCommand extends SapphireCommand {

// Slash command
public async chatInputRun(
interaction: SapphireCommand.ChatInputInteraction,
interaction: SapphireCommand.ChatInputCommandInteraction,
): Promise<APIMessage | Message<boolean> | undefined> {
const { client } = container;

Expand All @@ -337,7 +342,7 @@ export class CodeyCommand extends SapphireCommand {
if (commandInteractionOption) {
const type = commandInteractionOption.type;
switch (type) {
case 'USER':
case ApplicationCommandOptionType.User:
return {
[commandOptionName]: commandInteractionOption.user,
};
Expand Down
4 changes: 2 additions & 2 deletions src/codeyUserError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CacheType, Message } from 'discord.js';
import { Command } from '@sapphire/framework';

export class CodeyUserError {
message: Message | Command.ChatInputInteraction<CacheType> | undefined;
message: Message | Command.ChatInputCommandInteraction<CacheType> | undefined;
errorMessage: string;

constructor(_message: Message | Command.ChatInputInteraction | undefined, _error: string) {
constructor(_message: Message | Command.ChatInputCommandInteraction | undefined, _error: string) {
this.message = _message;
this.errorMessage = _error;
}
Expand Down
8 changes: 6 additions & 2 deletions src/commandDetails/admin/ban.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CodeyUserError } from './../../codeyUserError';
import { container } from '@sapphire/framework';
import { Permissions, User } from 'discord.js';
import { PermissionsBitField, User } from 'discord.js';
import {
CodeyCommandDetails,
CodeyCommandOptionType,
Expand All @@ -12,7 +12,11 @@ import { vars } from '../../config';
// Ban a user
const banExecuteCommand: SapphireMessageExecuteType = async (client, messageFromUser, args) => {
try {
if (!(<Readonly<Permissions>>messageFromUser.member?.permissions).has('BAN_MEMBERS')) {
if (
!(<Readonly<PermissionsBitField>>messageFromUser.member?.permissions).has(
PermissionsBitField.Flags.BanMembers,
)
) {
throw new CodeyUserError(messageFromUser, `You do not have permission to use this command.`);
}
const user = <User>args['user'];
Expand Down
8 changes: 6 additions & 2 deletions src/commandDetails/coin/adjust.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CodeyUserError } from './../../codeyUserError';
import { container } from '@sapphire/framework';
import { Permissions, User } from 'discord.js';
import { PermissionsBitField, User } from 'discord.js';
import {
CodeyCommandDetails,
CodeyCommandOptionType,
Expand All @@ -21,7 +21,11 @@ const coinAdjustExecuteCommand: SapphireMessageExecuteType = async (
messageFromUser,
args,
): Promise<SapphireMessageResponse> => {
if (!(<Readonly<Permissions>>messageFromUser.member?.permissions).has('ADMINISTRATOR')) {
if (
!(<Readonly<PermissionsBitField>>messageFromUser.member?.permissions).has(
PermissionsBitField.Flags.Administrator,
)
) {
throw new CodeyUserError(messageFromUser, `You do not have permission to use this command.`);
}

Expand Down
8 changes: 4 additions & 4 deletions src/commandDetails/coin/info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { container } from '@sapphire/framework';
import { MessageEmbed } from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import {
CodeyCommandDetails,
SapphireMessageExecuteType,
Expand All @@ -15,12 +15,12 @@ const coinInfoExecuteCommand: SapphireMessageExecuteType = async (
): Promise<SapphireMessageResponse> => {
// Get information about coin
const COIN = getCoinEmoji();
const infoEmbed = new MessageEmbed()
const infoEmbed = new EmbedBuilder()
.setColor(DEFAULT_EMBED_COLOUR)
.setTitle(`${COIN} About Codey Coin ${COIN}`)
.setThumbnail('https://cdn.discordapp.com/emojis/937096777180516453.webp')
.setDescription(`Codey coins are rewarded for being active in CSC's events and discord!`)
.addFields(
.addFields([
{
name: `${COIN} How Can I Obtain Codey Coins?`,
value: `Earn Codey coins by:
Expand All @@ -35,7 +35,7 @@ const coinInfoExecuteCommand: SapphireMessageExecuteType = async (
• Play Casino games such as Blackjack
• Buy virtual CSC Swag in the server (more info to come!)`,
},
);
]);
return { embeds: [infoEmbed] };
};

Expand Down
16 changes: 9 additions & 7 deletions src/commandDetails/coin/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { container, SapphireClient } from '@sapphire/framework';
import { MessageEmbed, User } from 'discord.js';
import { EmbedBuilder, User } from 'discord.js';
import {
CodeyCommandDetails,
getUserFromMessage,
Expand All @@ -18,7 +18,7 @@ const LEADERBOARD_LIMIT_FETCH = LEADERBOARD_LIMIT_DISPLAY * 2;
const getCoinLeaderboardEmbed = async (
client: SapphireClient<boolean>,
userId: string,
): Promise<MessageEmbed> => {
): Promise<EmbedBuilder> => {
// Get extra users to filter bots later
let leaderboard = await getCoinLeaderboard(LEADERBOARD_LIMIT_FETCH);
const leaderboardArray: string[] = [];
Expand Down Expand Up @@ -71,14 +71,16 @@ const getCoinLeaderboardEmbed = async (
}
}
const leaderboardText = leaderboardArray.join('\n');
const leaderboardEmbed = new MessageEmbed()
const leaderboardEmbed = new EmbedBuilder()
.setColor(DEFAULT_EMBED_COLOUR)
.setTitle('Codey Coin Leaderboard')
.setDescription(leaderboardText);
leaderboardEmbed.addFields({
name: 'Your Position',
value: `You are currently **#${position}** in the leaderboard with ${userBalance} ${getCoinEmoji()}.`,
});
leaderboardEmbed.addFields([
{
name: 'Your Position',
value: `You are currently **#${position}** in the leaderboard with ${userBalance} ${getCoinEmoji()}.`,
},
]);

return leaderboardEmbed;
};
Expand Down
8 changes: 6 additions & 2 deletions src/commandDetails/coin/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CodeyUserError } from './../../codeyUserError';
import { container } from '@sapphire/framework';
import { Permissions, User } from 'discord.js';
import { PermissionsBitField, User } from 'discord.js';
import {
CodeyCommandDetails,
CodeyCommandOptionType,
Expand All @@ -20,7 +20,11 @@ const coinUpdateExecuteCommand: SapphireMessageExecuteType = async (
messageFromUser,
args,
) => {
if (!(<Readonly<Permissions>>messageFromUser.member?.permissions).has('ADMINISTRATOR')) {
if (
!(<Readonly<PermissionsBitField>>messageFromUser.member?.permissions).has(
PermissionsBitField.Flags.Administrator,
)
) {
throw new CodeyUserError(messageFromUser, `You do not have permission to use this command.`);
}

Expand Down
Loading

0 comments on commit ccaa254

Please sign in to comment.