Skip to content

Commit

Permalink
refactor: many bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Dec 28, 2023
1 parent 0c78438 commit 59cc44a
Show file tree
Hide file tree
Showing 34 changed files with 360 additions and 301 deletions.
3 changes: 1 addition & 2 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
module.exports = require('./dist/lib/database/database.config').config;
export default (await import('./dist/lib/database/database.config.js')).AppDataConfig;
10 changes: 0 additions & 10 deletions src/.env.development
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
CLIENT_NAME='Skyra'
CLIENT_VERSION='6.3.0-dev [Sapphire Edition]'
CLIENT_PREFIX='sd!'
CLIENT_REGEX_PREFIX=''
CLIENT_OWNERS=''
CLIENT_ID=''
SHARDS='"auto"'

CLIENT_PRESENCE_NAME='sd!help'
CLIENT_PRESENCE_TYPE='LISTENING'

API_ENABLED=true
API_ORIGIN='http://127.0.0.1:3000'
API_PREFIX='/'
API_PORT=8282

OAUTH_COOKIE='SKYRA_AUTH'
OAUTH_DOMAIN_OVERWRITE='127.0.0.1'
OAUTH_REDIRECT_URI='http://127.0.0.1:3000/oauth/callback'
OAUTH_SCOPE='identify guilds'
OAUTH_SECRET=''

TWITCH_CALLBACK='http://localhost/twitch/event_sub_verify/'
Expand All @@ -38,8 +30,6 @@ INFLUX_ORG_ANALYTICS_BUCKET='analytics'
WEBHOOK_ERROR_ID='648663047615021058'
WEBHOOK_ERROR_TOKEN=''

WORKER_COUNT=2

# Tokens
DISCORD_TOKEN=''
BOTLIST_SPACE_TOKEN=''
Expand Down
8 changes: 7 additions & 1 deletion src/commands/Admin/roleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { send } from '@sapphire/plugin-editable-commands';
detailedDescription: LanguageKeys.Commands.Admin.RoleSetExtended,
permissionLevel: PermissionLevels.Administrator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'list' }, { name: 'auto', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'list', messageRun: 'list' },
{ name: 'auto', messageRun: 'auto', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
// This subcommand will always ADD roles in to a existing set OR it will create a new set if that set does not exist
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Fun/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class UserCommand extends SkyraCommand {
private readonly kDice20TrailRegExp = /([+-x*])\s*(\d+)/g;

public override async messageRun(message: Message, args: SkyraCommand.Args) {
const amountOrDice = await args.pick('integer', { minimum: 1, maximum: 1024 }).catch(() => args.rest('string'));
const amountOrDice = args.finished ? 6 : await args.pick('integer', { minimum: 1, maximum: 1024 }).catch(() => args.rest('string'));
const content = args.t(LanguageKeys.Commands.Fun.DiceOutput, { result: this.roll(amountOrDice) });
return send(message, content);
}
Expand Down
30 changes: 15 additions & 15 deletions src/commands/Games/hungergames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class UserCommand extends SkyraCommand {
const events = game.bloodbath
? LanguageKeys.Commands.Games.HungerGamesBloodbath
: game.sun
? LanguageKeys.Commands.Games.HungerGamesDay
: LanguageKeys.Commands.Games.HungerGamesNight;
? LanguageKeys.Commands.Games.HungerGamesDay
: LanguageKeys.Commands.Games.HungerGamesNight;

// Main logic of the game
const { results, deaths } = this.makeResultEvents(
Expand Down Expand Up @@ -168,8 +168,8 @@ export class UserCommand extends SkyraCommand {
const headerKey = game.bloodbath
? LanguageKeys.Commands.Games.HungerGamesResultHeaderBloodbath
: game.sun
? LanguageKeys.Commands.Games.HungerGamesResultHeaderSun
: LanguageKeys.Commands.Games.HungerGamesResultHeaderMoon;
? LanguageKeys.Commands.Games.HungerGamesResultHeaderSun
: LanguageKeys.Commands.Games.HungerGamesResultHeaderMoon;

const header = t(headerKey, { game });
const death = deaths.length
Expand Down Expand Up @@ -251,18 +251,18 @@ export class UserCommand extends SkyraCommand {
// If there are more than 16 tributes, perform a large blood bath
return game.tributes.size >= 16
? // For 16 people, 4 die, 36 -> 6, and so on keeps the game interesting.
// If it's in bloodbath, perform 50% more deaths.
Math.ceil(Math.sqrt(game.tributes.size) * (game.bloodbath ? 1.5 : 1))
// If it's in bloodbath, perform 50% more deaths.
Math.ceil(Math.sqrt(game.tributes.size) * (game.bloodbath ? 1.5 : 1))
: // If there are more than 7 tributes, proceed to kill them in 4 or more.
game.tributes.size > 7
? // If it's a bloodbath, perform mass death (12 -> 7), else eliminate 4.
game.bloodbath
? Math.ceil(Math.min(game.tributes.size - 3, Math.sqrt(game.tributes.size) * 2))
: 4
: // If there are 4 tributes, eliminate 2, else 1 (3 -> 2, 2 -> 1)
game.tributes.size === 4
? 2
: 1;
game.tributes.size > 7
? // If it's a bloodbath, perform mass death (12 -> 7), else eliminate 4.
game.bloodbath
? Math.ceil(Math.min(game.tributes.size - 3, Math.sqrt(game.tributes.size) * 2))
: 4
: // If there are 4 tributes, eliminate 2, else 1 (3 -> 2, 2 -> 1)
game.tributes.size === 4
? 2
: 1;
}
}

Expand Down
46 changes: 23 additions & 23 deletions src/commands/General/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ export class UserCommand extends SkyraCommand {
permissions: shouldNotAddPermissions
? 0n
: PermissionFlagsBits.AddReactions |
PermissionFlagsBits.AttachFiles |
PermissionFlagsBits.BanMembers |
PermissionFlagsBits.ChangeNickname |
PermissionFlagsBits.CreatePrivateThreads |
PermissionFlagsBits.CreatePublicThreads |
PermissionFlagsBits.DeafenMembers |
PermissionFlagsBits.EmbedLinks |
PermissionFlagsBits.KickMembers |
PermissionFlagsBits.ManageChannels |
PermissionFlagsBits.ManageGuildExpressions |
PermissionFlagsBits.ManageGuild |
PermissionFlagsBits.ManageMessages |
PermissionFlagsBits.ManageNicknames |
PermissionFlagsBits.ManageRoles |
PermissionFlagsBits.ManageThreads |
PermissionFlagsBits.MoveMembers |
PermissionFlagsBits.MuteMembers |
PermissionFlagsBits.ReadMessageHistory |
PermissionFlagsBits.SendMessages |
PermissionFlagsBits.SendMessagesInThreads |
PermissionFlagsBits.UseExternalEmojis |
PermissionFlagsBits.UseExternalStickers |
PermissionFlagsBits.ViewChannel
PermissionFlagsBits.AttachFiles |
PermissionFlagsBits.BanMembers |
PermissionFlagsBits.ChangeNickname |
PermissionFlagsBits.CreatePrivateThreads |
PermissionFlagsBits.CreatePublicThreads |
PermissionFlagsBits.DeafenMembers |
PermissionFlagsBits.EmbedLinks |
PermissionFlagsBits.KickMembers |
PermissionFlagsBits.ManageChannels |
PermissionFlagsBits.ManageGuildExpressions |
PermissionFlagsBits.ManageGuild |
PermissionFlagsBits.ManageMessages |
PermissionFlagsBits.ManageNicknames |
PermissionFlagsBits.ManageRoles |
PermissionFlagsBits.ManageThreads |
PermissionFlagsBits.MoveMembers |
PermissionFlagsBits.MuteMembers |
PermissionFlagsBits.ReadMessageHistory |
PermissionFlagsBits.SendMessages |
PermissionFlagsBits.SendMessagesInThreads |
PermissionFlagsBits.UseExternalEmojis |
PermissionFlagsBits.UseExternalStickers |
PermissionFlagsBits.ViewChannel
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { codeBlock } from '@sapphire/utilities';
detailedDescription: LanguageKeys.Commands.Management.ManageCommandAutoDeleteExtended,
permissionLevel: PermissionLevels.Administrator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { send } from '@sapphire/plugin-editable-commands';
detailedDescription: LanguageKeys.Commands.Management.ManageCommandChannelExtended,
permissionLevel: PermissionLevels.Administrator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import { EmbedBuilder, PermissionFlagsBits, type Guild } from 'discord.js';
detailedDescription: LanguageKeys.Commands.Management.ManageReactionRolesExtended,
permissionLevel: PermissionLevels.Administrator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Management/Helpers/guild-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class UserCommand extends SkyraCommand {
? args.t(LanguageKeys.Commands.Management.GuildInfoChannelsAfkChannelText, {
afkChannel: guild.afkChannelId,
afkTime: guild.afkTimeout / 60
})
})
: `**${args.t(LanguageKeys.Globals.None)}**`
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Management/Helpers/role-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class UserCommand extends SkyraCommand {
const permissionsString = PermissionsBits.has(permissions, PermissionFlagsBits.Administrator)
? args.t(LanguageKeys.Commands.Management.RoleInfoAll)
: permissions > 0n
? PermissionsBits.toArray(permissions)
.map((name) => `+ ${args.t(`permissions:${name}`)}`)
.join('\n')
: args.t(LanguageKeys.Commands.Management.RoleInfoNoPermissions);
? PermissionsBits.toArray(permissions)
.map((name) => `+ ${args.t(`permissions:${name}`)}`)
.join('\n')
: args.t(LanguageKeys.Commands.Management.RoleInfoNoPermissions);

const description = args.t(LanguageKeys.Commands.Management.RoleInfoData, {
role,
Expand Down
7 changes: 6 additions & 1 deletion src/commands/Management/Members/stickyRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { PermissionFlagsBits } from 'discord.js';
permissionLevel: PermissionLevels.Administrator,
requiredClientPermissions: [PermissionFlagsBits.ManageRoles],
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
7 changes: 6 additions & 1 deletion src/commands/Management/Message Filters/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { remove as removeConfusables } from 'confusables';
detailedDescription: LanguageKeys.Commands.Management.FilterExtended,
permissionLevel: PermissionLevels.Administrator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
7 changes: 6 additions & 1 deletion src/commands/Management/permissionNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { RESTJSONErrorCodes, Role, type GuildMember } from 'discord.js';
permissionLevel: PermissionLevels.Administrator,
description: LanguageKeys.Commands.Management.PermissionNodesDescription,
detailedDescription: LanguageKeys.Commands.Management.PermissionNodesExtended,
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }],
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
],
runIn: [CommandOptionsRunTypeEnum.GuildAny]
})
export class UserCommand extends SkyraSubcommand {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/Moderation/Management/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const COLORS = [0x80f31f, 0xa5de0b, 0xc7c101, 0xe39e03, 0xf6780f, 0xfe5326, 0xfb
detailedDescription: LanguageKeys.Commands.Moderation.HistoryExtended,
permissionLevel: PermissionLevels.Moderator,
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'details' }, { name: 'overview', default: true }]
subcommands: [
{ name: 'details', messageRun: 'details' },
{ name: 'overview', messageRun: 'overview', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public override messageRun(message: GuildMessage, args: SkyraSubcommand.Args, context: SkyraSubcommand.RunContext) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Moderation/Management/moderations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const enum Type {
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [
{ name: 'mute', messageRun: 'mutes' },
{ name: 'mutes' },
{ name: 'mutes', messageRun: 'mutes' },
{ name: 'warning', messageRun: 'warnings' },
{ name: 'warnings' },
{ name: 'warnings', messageRun: 'warnings' },
{ name: 'warn', messageRun: 'warnings' },
{ name: 'warns', messageRun: 'warnings' },
{ name: 'all', default: true }
{ name: 'all', messageRun: 'all', default: true }
]
})
)
Expand Down
5 changes: 4 additions & 1 deletion src/commands/Moderation/Utilities/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { PermissionFlagsBits } from 'discord.js';
permissionLevel: PermissionLevels.Moderator,
requiredClientPermissions: [PermissionFlagsBits.EmbedLinks],
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'delete' }, { name: 'show', default: true }]
subcommands: [
{ name: 'delete', messageRun: 'delete' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async show(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/Moderation/lockdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import { PermissionFlagsBits, type Role } from 'discord.js';
permissionLevel: PermissionLevels.Moderator,
requiredClientPermissions: [PermissionFlagsBits.ManageChannels, PermissionFlagsBits.ManageRoles],
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'lock' }, { name: 'unlock' }, { name: 'auto', default: true }]
subcommands: [
{ name: 'lock', messageRun: 'lock' },
{ name: 'unlock', messageRun: 'unlock' },
{ name: 'auto', messageRun: 'auto', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public override messageRun(message: GuildMessage, args: SkyraSubcommand.Args, context: SkyraSubcommand.RunContext) {
Expand Down
10 changes: 5 additions & 5 deletions src/commands/System/Admin/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ export class UserCommand extends SkyraCommand {
result instanceof Error
? result.stack
: args.getFlags('json')
? JSON.stringify(result, null, 4)
: inspect(result, {
depth: Number(args.getOption('depth') ?? 0) || 0,
showHidden: args.getFlags('showHidden', 'hidden')
});
? JSON.stringify(result, null, 4)
: inspect(result, {
depth: Number(args.getOption('depth') ?? 0) || 0,
showHidden: args.getFlags('showHidden', 'hidden')
});
}
return {
success,
Expand Down
7 changes: 6 additions & 1 deletion src/commands/Twitch/twitchsubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { EmbedBuilder, PermissionFlagsBits, type Guild } from 'discord.js';
permissionLevel: PermissionLevels.Administrator,
requiredClientPermissions: [PermissionFlagsBits.EmbedLinks],
runIn: [CommandOptionsRunTypeEnum.GuildAny],
subcommands: [{ name: 'add' }, { name: 'remove' }, { name: 'reset' }, { name: 'show', default: true }]
subcommands: [
{ name: 'add', messageRun: 'add' },
{ name: 'remove', messageRun: 'remove' },
{ name: 'reset', messageRun: 'reset' },
{ name: 'show', messageRun: 'show', default: true }
]
})
export class UserCommand extends SkyraSubcommand {
public async add(message: GuildMessage, args: SkyraSubcommand.Args) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function transformGuild(client: Client, userId: string, data: RESTAPIParti
vanityURLCode: null,
verificationLevel: GuildVerificationLevel.None,
verified: false
}
}
: flattenGuild(guild);

return {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/database/database.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Config must be the first to be loaded, as it sets the env:
import '#root/config';

// Import everything else:
import { envParseBoolean, envParseInteger, envParseString } from '@skyra/env-utilities';
import { fileURLToPath } from 'node:url';
import { DataSource, type DataSourceOptions } from 'typeorm';
import { DataSource } from 'typeorm';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';

export const config: DataSourceOptions = {
export const AppDataConfig = new DataSource({
type: 'postgres',
host: envParseString('PGSQL_DATABASE_HOST'),
port: envParseInteger('PGSQL_DATABASE_PORT'),
Expand All @@ -17,6 +18,6 @@ export const config: DataSourceOptions = {
migrations: [fileURLToPath(new URL('migrations/*.js', import.meta.url))],
namingStrategy: new SnakeNamingStrategy(),
logging: envParseBoolean('TYPEORM_DEBUG_LOGS', false)
};
});

export const connect = () => new DataSource(config).initialize();
export const connect = () => AppDataConfig.initialize();
Loading

0 comments on commit 59cc44a

Please sign in to comment.