This commit is contained in:
parent
7ea9c24e31
commit
1e16644732
40 changed files with 477 additions and 264 deletions
|
@ -9,6 +9,7 @@
|
|||
"start": "node ./dist/bot.js",
|
||||
"test": "jest --passWithNoTests",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
||||
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
||||
"db:create": "typeorm migration:create ./src/database/migrations/app/new",
|
||||
|
|
|
@ -2,12 +2,12 @@ import { readFileSync } from "fs";
|
|||
import path from "path";
|
||||
import Config from "../database/entities/app/Config";
|
||||
import { glob } from "glob";
|
||||
import SeriesMetadata from "../contracts/SeriesMetadata";
|
||||
import { SeriesMetadata } from "../contracts/SeriesMetadata";
|
||||
import { CoreClient } from "../client/client";
|
||||
|
||||
export default class CardMetadataFunction {
|
||||
public static async Execute(overrideSafeMode: boolean = false): Promise<boolean> {
|
||||
if (!overrideSafeMode && await Config.GetValue('safemode') == "true") return false;
|
||||
if (!overrideSafeMode && await Config.GetValue("safemode") == "true") return false;
|
||||
|
||||
try {
|
||||
CoreClient.Cards = await this.FindMetadataJSONs();
|
||||
|
@ -16,7 +16,7 @@ export default class CardMetadataFunction {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
await Config.SetValue('safemode', 'true');
|
||||
await Config.SetValue("safemode", "true");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@ export default class CardMetadataFunction {
|
|||
private static async FindMetadataJSONs(): Promise<SeriesMetadata[]> {
|
||||
const res: SeriesMetadata[] = [];
|
||||
|
||||
const seriesJSONs = await glob(path.join(process.cwd(), 'cards', '/**/*.json'));
|
||||
const seriesJSONs = await glob(path.join(process.cwd(), "cards", "/**/*.json"));
|
||||
|
||||
for (let jsonPath of seriesJSONs) {
|
||||
for (const jsonPath of seriesJSONs) {
|
||||
console.log(`Reading file ${jsonPath}`);
|
||||
const jsonFile = readFileSync(jsonPath);
|
||||
const parsedJson: SeriesMetadata[] = JSON.parse(jsonFile.toString());
|
||||
|
|
|
@ -22,7 +22,7 @@ const requiredConfigs: string[] = [
|
|||
"DB_LOGGING",
|
||||
"EXPRESS_PORT",
|
||||
"GDRIVESYNC_WHITELIST",
|
||||
]
|
||||
];
|
||||
|
||||
requiredConfigs.forEach(config => {
|
||||
if (!process.env[config]) {
|
||||
|
@ -39,7 +39,7 @@ Registry.RegisterCommands();
|
|||
Registry.RegisterEvents();
|
||||
Registry.RegisterButtonEvents();
|
||||
|
||||
if (!existsSync(`${process.cwd()}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == 'true') {
|
||||
if (!existsSync(`${process.cwd()}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") {
|
||||
console.log("Card directory not found, syncing...");
|
||||
|
||||
CoreClient.AllowDrops = false;
|
||||
|
@ -49,7 +49,7 @@ if (!existsSync(`${process.cwd()}/cards`) && process.env.GDRIVESYNC_AUTO && proc
|
|||
console.error(error.code);
|
||||
throw `Error while running sync command. Code: ${error.code}`;
|
||||
} else {
|
||||
console.log('Synced successfully.');
|
||||
console.log("Synced successfully.");
|
||||
CoreClient.AllowDrops = true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,20 +8,20 @@ export default class Claim extends ButtonEvent {
|
|||
public override async execute(interaction: ButtonInteraction) {
|
||||
if (!interaction.guild || !interaction.guildId) return;
|
||||
|
||||
const cardNumber = interaction.customId.split(' ')[1];
|
||||
const claimId = interaction.customId.split(' ')[2];
|
||||
const droppedBy = interaction.customId.split(' ')[3];
|
||||
const cardNumber = interaction.customId.split(" ")[1];
|
||||
const claimId = interaction.customId.split(" ")[2];
|
||||
const droppedBy = interaction.customId.split(" ")[3];
|
||||
const userId = interaction.user.id;
|
||||
|
||||
const claimed = await eClaim.FetchOneByClaimId(claimId);
|
||||
|
||||
if (claimed) {
|
||||
await interaction.reply('This card has already been claimed');
|
||||
await interaction.reply("This card has already been claimed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (claimId == CoreClient.ClaimId && userId != droppedBy) {
|
||||
await interaction.reply('The latest dropped card can only be claimed by the user who dropped it');
|
||||
await interaction.reply("The latest dropped card can only be claimed by the user who dropped it");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import InventoryHelper from "../helpers/InventoryHelper";
|
|||
|
||||
export default class Inventory extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
const userid = interaction.customId.split(' ')[1];
|
||||
const page = interaction.customId.split(' ')[2];
|
||||
const userid = interaction.customId.split(" ")[1];
|
||||
const page = interaction.customId.split(" ")[2];
|
||||
|
||||
try {
|
||||
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page));
|
||||
|
|
|
@ -11,19 +11,19 @@ import path from "path";
|
|||
export default class Reroll extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
if (!CoreClient.AllowDrops) {
|
||||
await interaction.reply('Bot is currently syncing, please wait until its done.');
|
||||
await interaction.reply("Bot is currently syncing, please wait until its done.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (await Config.GetValue('safemode') == "true") {
|
||||
await interaction.reply('Safe Mode has been activated, please resync to continue.');
|
||||
if (await Config.GetValue("safemode") == "true") {
|
||||
await interaction.reply("Safe Mode has been activated, please resync to continue.");
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCard = CardDropHelperMetadata.GetRandomCard();
|
||||
|
||||
if (!randomCard) {
|
||||
await interaction.reply('Unable to fetch card, please try again.');
|
||||
await interaction.reply("Unable to fetch card, please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ export default class Reroll extends ButtonEvent {
|
|||
let image: Buffer;
|
||||
const imageFileName = randomCard.card.path.split("/").pop()!;
|
||||
|
||||
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
|
||||
image = readFileSync(path.join(process.cwd(), "cards", randomCard.card.path));
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Client } from "discord.js";
|
||||
import { Client, DMChannel, Guild, GuildBan, GuildMember, Message, NonThreadGuildBasedChannel, PartialGuildMember, PartialMessage } from "discord.js";
|
||||
import * as dotenv from "dotenv";
|
||||
import { EventType } from "../constants/EventType";
|
||||
import ICommandItem from "../contracts/ICommandItem";
|
||||
import IEventItem from "../contracts/IEventItem";
|
||||
import EventExecutors from "../contracts/EventExecutors";
|
||||
import { Command } from "../type/command";
|
||||
|
||||
import { Events } from "./events";
|
||||
|
@ -13,12 +13,12 @@ import AppDataSource from "../database/dataSources/appDataSource";
|
|||
import { Environment } from "../constants/Environment";
|
||||
import Webhooks from "../webhooks";
|
||||
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
||||
import SeriesMetadata from "../contracts/SeriesMetadata";
|
||||
import { SeriesMetadata } from "../contracts/SeriesMetadata";
|
||||
import InventoryHelper from "../helpers/InventoryHelper";
|
||||
|
||||
export class CoreClient extends Client {
|
||||
private static _commandItems: ICommandItem[];
|
||||
private static _eventItems: IEventItem[];
|
||||
private static _eventExecutors: EventExecutors;
|
||||
private static _buttonEvents: IButtonEventItem[];
|
||||
|
||||
private _events: Events;
|
||||
|
@ -34,8 +34,8 @@ export class CoreClient extends Client {
|
|||
return this._commandItems;
|
||||
}
|
||||
|
||||
public static get eventItems(): IEventItem[] {
|
||||
return this._eventItems;
|
||||
public static get eventExecutors(): EventExecutors {
|
||||
return this._eventExecutors;
|
||||
}
|
||||
|
||||
public static get buttonEvents(): IButtonEventItem[] {
|
||||
|
@ -47,7 +47,6 @@ export class CoreClient extends Client {
|
|||
dotenv.config();
|
||||
|
||||
CoreClient._commandItems = [];
|
||||
CoreClient._eventItems = [];
|
||||
CoreClient._buttonEvents = [];
|
||||
|
||||
this._events = new Events();
|
||||
|
@ -75,15 +74,11 @@ export class CoreClient extends Client {
|
|||
|
||||
await CardMetadataFunction.Execute(true);
|
||||
|
||||
this._util.loadEvents(this, CoreClient._eventItems);
|
||||
this._util.loadEvents(this, CoreClient._eventExecutors);
|
||||
this._util.loadSlashCommands(this);
|
||||
|
||||
this._webhooks.start();
|
||||
|
||||
console.log(`Registered Commands: ${CoreClient._commandItems.flatMap(x => x.Name).join(", ")}`);
|
||||
console.log(`Registered Events: ${CoreClient._eventItems.flatMap(x => x.EventType).join(", ")}`);
|
||||
console.log(`Registered Buttons: ${CoreClient._buttonEvents.flatMap(x => x.ButtonId).join(", ")}`);
|
||||
|
||||
await super.login(process.env.BOT_TOKEN);
|
||||
}
|
||||
|
||||
|
@ -100,15 +95,255 @@ export class CoreClient extends Client {
|
|||
}
|
||||
}
|
||||
|
||||
public static RegisterEvent(eventType: EventType, func: Function, environment: Environment = Environment.All) {
|
||||
const item: IEventItem = {
|
||||
EventType: eventType,
|
||||
ExecutionFunction: func,
|
||||
Environment: environment,
|
||||
public static RegisterChannelCreateEvent(fn: (channel: NonThreadGuildBasedChannel) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.ChannelCreate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [ fn ],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (environment &= CoreClient.Environment) {
|
||||
CoreClient._eventItems.push(item);
|
||||
public static RegisterChannelDeleteEvent(fn: (channel: DMChannel | NonThreadGuildBasedChannel) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.ChannelDelete.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [ fn ],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterChannelUpdateEvent(fn: (channel: DMChannel | NonThreadGuildBasedChannel) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.ChannelCreate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [ fn ],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterGuildBanAddEvent(fn: (ban: GuildBan) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildBanAdd.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [ fn ],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterGuildBanRemoveEvent(fn: (channel: GuildBan) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildBanRemove.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [ fn ],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterGuildCreateEvent(fn: (guild: Guild) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildCreate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [ fn ],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterGuildMemberAddEvent(fn: (member: GuildMember) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildMemberAdd.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [ fn ],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterGuildMemberRemoveEvent(fn: (member: GuildMember | PartialGuildMember) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildMemberRemove.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [ fn ],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static GuildMemebrUpdate(fn: (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.GuildMemebrUpdate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [ fn ],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterMessageCreateEvent(fn: (message: Message<boolean>) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.MessageCreate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [ fn ],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterMessageDeleteEvent(fn: (message: Message<boolean> | PartialMessage) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.MessageDelete.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [ fn ],
|
||||
MessageUpdate: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterMessageUpdateEvent(fn: (oldMessage: Message<boolean> | PartialMessage, newMessage: Message<boolean> | PartialMessage) => void) {
|
||||
if (this._eventExecutors) {
|
||||
this._eventExecutors.MessageUpdate.push(fn);
|
||||
} else {
|
||||
this._eventExecutors = {
|
||||
ChannelCreate: [],
|
||||
ChannelDelete: [],
|
||||
ChannelUpdate: [],
|
||||
GuildBanAdd: [],
|
||||
GuildBanRemove: [],
|
||||
GuildCreate: [],
|
||||
GuildMemberAdd: [],
|
||||
GuildMemberRemove: [],
|
||||
GuildMemebrUpdate: [],
|
||||
MessageCreate: [],
|
||||
MessageDelete: [],
|
||||
MessageUpdate: [ fn ],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ export default class Button {
|
|||
public static async onButtonClicked(interaction: ButtonInteraction) {
|
||||
if (!interaction.isButton) return;
|
||||
|
||||
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(' ')[0]);
|
||||
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(" ")[0]);
|
||||
|
||||
if (!item) {
|
||||
await interaction.reply('Event not found');
|
||||
await interaction.reply("Event not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export default class ChatInputCommand {
|
|||
|
||||
if (!itemForServer) {
|
||||
if (!item) {
|
||||
await interaction.reply('Command not found');
|
||||
await interaction.reply("Command not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
|
||||
import { EventType } from "../constants/EventType";
|
||||
import IEventItem from "../contracts/IEventItem";
|
||||
import EventExecutors from "../contracts/EventExecutors";
|
||||
import { CoreClient } from "./client";
|
||||
|
||||
export class Util {
|
||||
|
@ -10,9 +10,9 @@ export class Util {
|
|||
const globalCommands = registeredCommands.filter(x => !x.ServerId);
|
||||
const guildCommands = registeredCommands.filter(x => x.ServerId);
|
||||
|
||||
const globalCommandData: SlashCommandBuilder[] = [];
|
||||
const globalCommandData: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">[] = [];
|
||||
|
||||
for (let command of globalCommands) {
|
||||
for (const command of globalCommands) {
|
||||
if (!command.Command.CommandBuilder) continue;
|
||||
|
||||
if (command.Environment &= CoreClient.Environment) {
|
||||
|
@ -22,13 +22,13 @@ export class Util {
|
|||
|
||||
const guildIds: string[] = [];
|
||||
|
||||
for (let command of guildCommands) {
|
||||
for (const command of guildCommands) {
|
||||
if (!guildIds.find(x => x == command.ServerId)) {
|
||||
guildIds.push(command.ServerId!);
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!);
|
||||
const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN!);
|
||||
|
||||
rest.put(
|
||||
Routes.applicationCommands(process.env.BOT_CLIENTID!),
|
||||
|
@ -37,10 +37,10 @@ export class Util {
|
|||
}
|
||||
);
|
||||
|
||||
for (let guild of guildIds) {
|
||||
const guildCommandData: SlashCommandBuilder[] = [];
|
||||
for (const guild of guildIds) {
|
||||
const guildCommandData: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">[] = [];
|
||||
|
||||
for (let command of guildCommands.filter(x => x.ServerId == guild)) {
|
||||
for (const command of guildCommands.filter(x => x.ServerId == guild)) {
|
||||
if (!command.Command.CommandBuilder) continue;
|
||||
|
||||
if (command.Environment &= CoreClient.Environment) {
|
||||
|
@ -55,53 +55,23 @@ export class Util {
|
|||
{
|
||||
body: guildCommandData
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the events
|
||||
loadEvents(client: Client, events: IEventItem[]) {
|
||||
events.forEach((e) => {
|
||||
switch(e.EventType) {
|
||||
case EventType.ChannelCreate:
|
||||
client.on('channelCreate', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.ChannelDelete:
|
||||
client.on('channelDelete', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.ChannelUpdate:
|
||||
client.on('channelUpdate', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.GuildBanAdd:
|
||||
client.on('guildBanAdd', (ban) => e.ExecutionFunction(ban));
|
||||
break;
|
||||
case EventType.GuildBanRemove:
|
||||
client.on('guildBanRemove', (ban) => e.ExecutionFunction(ban));
|
||||
break;
|
||||
case EventType.GuildCreate:
|
||||
client.on('guildCreate', (guild) => e.ExecutionFunction(guild));
|
||||
break;
|
||||
case EventType.GuildMemberAdd:
|
||||
client.on('guildMemberAdd', (member) => e.ExecutionFunction(member));
|
||||
break;
|
||||
case EventType.GuildMemberRemove:
|
||||
client.on('guildMemberRemove', (member) => e.ExecutionFunction(member));
|
||||
break;
|
||||
case EventType.GuildMemberUpdate:
|
||||
client.on('guildMemberUpdate', (oldMember, newMember) => e.ExecutionFunction(oldMember, newMember));
|
||||
break;
|
||||
case EventType.MessageCreate:
|
||||
client.on('messageCreate', (message) => e.ExecutionFunction(message));
|
||||
break;
|
||||
case EventType.MessageDelete:
|
||||
client.on('messageDelete', (message) => e.ExecutionFunction(message));
|
||||
break;
|
||||
case EventType.MessageUpdate:
|
||||
client.on('messageUpdate', (oldMessage, newMessage) => e.ExecutionFunction(oldMessage, newMessage));
|
||||
break;
|
||||
default:
|
||||
console.error('Event not implemented.');
|
||||
}
|
||||
});
|
||||
loadEvents(client: Client, events: EventExecutors) {
|
||||
client.on("channelCreate", (channel) => events.ChannelCreate.forEach((fn) => fn(channel)));
|
||||
client.on("channelDelete", (channel) => events.ChannelDelete.forEach((fn) => fn(channel)));
|
||||
client.on("channelUpdate", (channel) => events.ChannelUpdate.forEach((fn) => fn(channel)));
|
||||
client.on("guildBanAdd", (ban) => events.GuildBanAdd.forEach((fn) => fn(ban)));
|
||||
client.on("guildBanRemove", (ban) => events.GuildBanRemove.forEach((fn) => fn(ban)));
|
||||
client.on("guildCreate", (guild) => events.GuildCreate.forEach((fn) => fn(guild)));
|
||||
client.on("guildMemberAdd", (member) => events.GuildMemberAdd.forEach((fn) => fn(member)));
|
||||
client.on("guildMemberRemove", (member) => events.GuildMemberRemove.forEach((fn) => fn(member)));
|
||||
client.on("guildMemberUpdate", (oldMember, newMember) => events.GuildMemebrUpdate.forEach((fn) => fn(oldMember, newMember)));
|
||||
client.on("messageCreate", (message) => events.MessageCreate.forEach((fn) => fn(message)));
|
||||
client.on("messageDelete", (message) => events.MessageDelete.forEach((fn) => fn(message)));
|
||||
client.on("messageUpdate", (oldMessage, newMessage) => events.MessageUpdate.forEach((fn) => fn(oldMessage, newMessage)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ export default class About extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('about')
|
||||
.setDescription('About Bot');
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("about")
|
||||
.setDescription("About Bot");
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
|
|
|
@ -12,26 +12,26 @@ export default class Drop extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('drop')
|
||||
.setDescription('Summon a new card drop');
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("drop")
|
||||
.setDescription("Summon a new card drop");
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
if (!CoreClient.AllowDrops) {
|
||||
await interaction.reply('Bot is currently syncing, please wait until its done.');
|
||||
await interaction.reply("Bot is currently syncing, please wait until its done.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (await Config.GetValue('safemode') == "true") {
|
||||
await interaction.reply('Safe Mode has been activated, please resync to continue.');
|
||||
if (await Config.GetValue("safemode") == "true") {
|
||||
await interaction.reply("Safe Mode has been activated, please resync to continue.");
|
||||
return;
|
||||
}
|
||||
|
||||
const randomCard = CardDropHelperMetadata.GetRandomCard();
|
||||
|
||||
if (!randomCard) {
|
||||
await interaction.reply('Unable to fetch card, please try again.');
|
||||
await interaction.reply("Unable to fetch card, please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ export default class Drop extends Command {
|
|||
let image: Buffer;
|
||||
const imageFileName = randomCard.card.path.split("/").pop()!;
|
||||
|
||||
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
|
||||
image = readFileSync(path.join(process.cwd(), "cards", randomCard.card.path));
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
|
|
|
@ -9,37 +9,37 @@ export default class Gdrivesync extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('gdrivesync')
|
||||
.setDescription('Sync google drive to the bot')
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("gdrivesync")
|
||||
.setDescription("Sync google drive to the bot")
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(',');
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(",");
|
||||
|
||||
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
|
||||
await interaction.reply("Only whitelisted users can use this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.reply('Syncing, this might take a while...');
|
||||
await interaction.reply("Syncing, this might take a while...");
|
||||
|
||||
CoreClient.AllowDrops = false;
|
||||
|
||||
exec(`rclone sync card-drop-gdrive: ${process.cwd()}/cards`, async (error: ExecException | null) => {
|
||||
if (error) {
|
||||
await interaction.editReply(`Error while running sync command. Safe Mode has been activated. Code: ${error.code}`);
|
||||
await Config.SetValue('safemode', 'true');
|
||||
await Config.SetValue("safemode", "true");
|
||||
} else {
|
||||
await CardMetadataFunction.Execute();
|
||||
|
||||
await interaction.editReply('Synced successfully.');
|
||||
await interaction.editReply("Synced successfully.");
|
||||
|
||||
CoreClient.AllowDrops = true;
|
||||
await Config.SetValue('safemode', 'false');
|
||||
await Config.SetValue("safemode", "false");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,16 +7,16 @@ export default class Inventory extends Command {
|
|||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('inventory')
|
||||
.setDescription('View your inventory')
|
||||
.setName("inventory")
|
||||
.setDescription("View your inventory")
|
||||
.addNumberOption(x =>
|
||||
x
|
||||
.setName('page')
|
||||
.setDescription('The page to start with'));
|
||||
.setName("page")
|
||||
.setDescription("The page to start with"));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
const page = interaction.options.get('page');
|
||||
const page = interaction.options.get("page");
|
||||
|
||||
try {
|
||||
let pageNumber = 0;
|
||||
|
|
|
@ -7,27 +7,27 @@ export default class Resync extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('resync')
|
||||
.setDescription('Resync the card database')
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("resync")
|
||||
.setDescription("Resync the card database")
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(',');
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(",");
|
||||
|
||||
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
|
||||
await interaction.reply("Only whitelisted users can use this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
let result = await CardMetadataFunction.Execute(true);
|
||||
const result = await CardMetadataFunction.Execute(true);
|
||||
|
||||
if (result) {
|
||||
if (await Config.GetValue('safemode') == "true") {
|
||||
await Config.SetValue('safemode', 'false');
|
||||
if (await Config.GetValue("safemode") == "true") {
|
||||
await Config.SetValue("safemode", "false");
|
||||
await interaction.reply("Resynced database and disabled safe mode.");
|
||||
|
||||
return;
|
||||
|
|
|
@ -11,23 +11,23 @@ export default class Dropnumber extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('dropnumber')
|
||||
.setDescription('(TEST) Summon a specific card')
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("dropnumber")
|
||||
.setDescription("(TEST) Summon a specific card")
|
||||
.addStringOption(x =>
|
||||
x
|
||||
.setName('cardnumber')
|
||||
.setDescription('The card number to summon')
|
||||
.setName("cardnumber")
|
||||
.setDescription("The card number to summon")
|
||||
.setRequired(true));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const cardNumber = interaction.options.get('cardnumber');
|
||||
const cardNumber = interaction.options.get("cardnumber");
|
||||
|
||||
if (!cardNumber || !cardNumber.value) {
|
||||
await interaction.reply('Card Number is required');
|
||||
await interaction.reply("Card Number is required");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ export default class Dropnumber extends Command {
|
|||
.find(x => x.id == cardNumber.value);
|
||||
|
||||
if (!card) {
|
||||
await interaction.reply('Card not found');
|
||||
await interaction.reply("Card not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ export default class Dropnumber extends Command {
|
|||
const imageFileName = card.path.split("/").pop()!;
|
||||
|
||||
try {
|
||||
image = readFileSync(path.join(process.cwd(), 'cards', card.path));
|
||||
image = readFileSync(path.join(process.cwd(), "cards", card.path));
|
||||
} catch {
|
||||
await interaction.reply(`Unable to fetch image for card ${card.id}`);
|
||||
return;
|
||||
|
@ -78,7 +78,7 @@ export default class Dropnumber extends Command {
|
|||
if (e instanceof DiscordAPIError) {
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
||||
} else {
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
|
||||
await interaction.editReply("Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,37 +12,37 @@ export default class Droprarity extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('droprarity')
|
||||
.setDescription('(TEST) Summon a random card of a specific rarity')
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("droprarity")
|
||||
.setDescription("(TEST) Summon a random card of a specific rarity")
|
||||
.addStringOption(x =>
|
||||
x
|
||||
.setName('rarity')
|
||||
.setDescription('The rarity you want to summon')
|
||||
.setName("rarity")
|
||||
.setDescription("The rarity you want to summon")
|
||||
.setRequired(true));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const rarity = interaction.options.get('rarity');
|
||||
const rarity = interaction.options.get("rarity");
|
||||
|
||||
if (!rarity || !rarity.value) {
|
||||
await interaction.reply('Rarity is required');
|
||||
await interaction.reply("Rarity is required");
|
||||
return;
|
||||
}
|
||||
|
||||
const rarityType = CardRarityParse(rarity.value.toString());
|
||||
|
||||
if (rarityType == CardRarity.Unknown) {
|
||||
await interaction.reply('Invalid rarity');
|
||||
await interaction.reply("Invalid rarity");
|
||||
return;
|
||||
}
|
||||
|
||||
const card = await CardDropHelperMetadata.GetRandomCardByRarity(rarityType);
|
||||
|
||||
if (!card) {
|
||||
await interaction.reply('Card not found');
|
||||
await interaction.reply("Card not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ export default class Droprarity extends Command {
|
|||
const imageFileName = card.card.path.split("/").pop()!;
|
||||
|
||||
try {
|
||||
image = readFileSync(path.join(process.cwd(), 'cards', card.card.path));
|
||||
image = readFileSync(path.join(process.cwd(), "cards", card.card.path));
|
||||
} catch {
|
||||
await interaction.reply(`Unable to fetch image for card ${card.card.id}`);
|
||||
return;
|
||||
|
@ -81,7 +81,7 @@ export default class Droprarity extends Command {
|
|||
if (e instanceof DiscordAPIError) {
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
|
||||
} else {
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
|
||||
await interaction.editReply("Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
src/contracts/EventExecutors.ts
Normal file
19
src/contracts/EventExecutors.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
import { DMChannel, Guild, GuildBan, GuildMember, Message, NonThreadGuildBasedChannel, PartialGuildMember, PartialMessage } from "discord.js";
|
||||
|
||||
interface EventExecutors {
|
||||
ChannelCreate: ((channel: NonThreadGuildBasedChannel) => void)[],
|
||||
ChannelDelete: ((channel: DMChannel | NonThreadGuildBasedChannel) => void)[],
|
||||
ChannelUpdate: ((channel: DMChannel | NonThreadGuildBasedChannel) => void)[],
|
||||
GuildBanAdd: ((ban: GuildBan) => void)[],
|
||||
GuildBanRemove: ((ban: GuildBan) => void)[],
|
||||
GuildCreate: ((guild: Guild) => void)[],
|
||||
GuildMemberAdd: ((member: GuildMember) => void)[],
|
||||
GuildMemberRemove: ((member: GuildMember | PartialGuildMember) => void)[],
|
||||
GuildMemebrUpdate: ((oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) => void)[],
|
||||
MessageCreate: ((message: Message<boolean>) => void)[],
|
||||
MessageDelete: ((message: Message<boolean> | PartialMessage) => void)[],
|
||||
MessageUpdate: ((oldMessage: Message<boolean> | PartialMessage, newMessage: Message<boolean> | PartialMessage) => void)[],
|
||||
}
|
||||
|
||||
export default EventExecutors;
|
|
@ -1,9 +1,11 @@
|
|||
import { Environment } from "../constants/Environment";
|
||||
import { Command } from "../type/command";
|
||||
|
||||
export default interface ICommandItem {
|
||||
interface ICommandItem {
|
||||
Name: string,
|
||||
Command: Command,
|
||||
Environment: Environment,
|
||||
ServerId?: string,
|
||||
}
|
||||
|
||||
export default ICommandItem;
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
import { Environment } from "../constants/Environment";
|
||||
import { EventType } from "../constants/EventType";
|
||||
|
||||
export default interface IEventItem {
|
||||
EventType: EventType,
|
||||
ExecutionFunction: Function,
|
||||
Environment: Environment,
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
export default interface IGDriveFolderListing {
|
||||
export interface IGDriveFolderListing {
|
||||
id: string,
|
||||
name: string,
|
||||
};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { CardRarity } from "../constants/CardRarity";
|
||||
|
||||
export default interface SeriesMetadata {
|
||||
export interface SeriesMetadata {
|
||||
id: number,
|
||||
name: string,
|
||||
cards: CardMetadata[],
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper"
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper";
|
||||
|
||||
export class CreateClaim1694609771821 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Up('1694609771821-CreateClaim', '0.1.5', [
|
||||
'01-CreateClaim',
|
||||
'02-MoveToClaim',
|
||||
'03-AlterInventory',
|
||||
MigrationHelper.Up("1694609771821-CreateClaim", "0.1.5", [
|
||||
"01-CreateClaim",
|
||||
"02-MoveToClaim",
|
||||
"03-AlterInventory",
|
||||
], queryRunner);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
public async down(): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper"
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper";
|
||||
|
||||
export class CreateBase1693769942868 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Up('1693769942868-CreateBase', '0.1', [
|
||||
MigrationHelper.Up("1693769942868-CreateBase", "0.1", [
|
||||
"01-table/Inventory",
|
||||
], queryRunner);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
public async down(): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper"
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import MigrationHelper from "../../../../helpers/MigrationHelper";
|
||||
|
||||
export class CreateConfig1699814500650 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Up('1699814500650-createConfig', '0.2', [
|
||||
MigrationHelper.Up("1699814500650-createConfig", "0.2", [
|
||||
"01-table/Config",
|
||||
], queryRunner);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
public async down(): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ export default class CardDropHelperMetadata {
|
|||
};
|
||||
}
|
||||
|
||||
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: Number, imageFileName: string): EmbedBuilder {
|
||||
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: number, imageFileName: string): EmbedBuilder {
|
||||
let description = "";
|
||||
description += `Series: ${drop.series.name}\n`;
|
||||
description += `Claimed: ${quantityClaimed}\n`;
|
||||
|
@ -68,7 +68,7 @@ export default class CardDropHelperMetadata {
|
|||
.setLabel("Claim")
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`reroll`)
|
||||
.setCustomId("reroll")
|
||||
.setLabel("Reroll")
|
||||
.setStyle(ButtonStyle.Secondary));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
import { CoreClient } from "../client/client";
|
||||
import SeriesMetadata from "../contracts/SeriesMetadata";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
||||
|
||||
|
@ -37,14 +36,14 @@ export default class InventoryHelper {
|
|||
|
||||
const pages: InventoryPage[] = [];
|
||||
|
||||
for (let series of allSeriesClaimed) {
|
||||
for (const series of allSeriesClaimed) {
|
||||
const seriesCards = series.cards;
|
||||
|
||||
for (let i = 0; i < seriesCards.length; i+= cardsPerPage) {
|
||||
const cards = series.cards.slice(i, i + cardsPerPage);
|
||||
const pageCards: InventoryPageCards[] = [];
|
||||
|
||||
for (let card of cards) {
|
||||
for (const card of cards) {
|
||||
const item = inventory.find(x => x.CardNumber == card.id);
|
||||
|
||||
if (!item) {
|
||||
|
@ -77,7 +76,7 @@ export default class InventoryHelper {
|
|||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(username)
|
||||
.setDescription(`**${currentPage.name} (${currentPage.seriesSubpage + 1})**\n${currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n')}`)
|
||||
.setDescription(`**${currentPage.name} (${currentPage.seriesSubpage + 1})**\n${currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join("\n")}`)
|
||||
.setFooter({ text: `Page ${page + 1} of ${pages.length}` })
|
||||
.setColor(EmbedColours.Ok);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { QueryRunner } from "typeorm";
|
|||
|
||||
export default class MigrationHelper {
|
||||
public static Up(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) {
|
||||
for (let path of queryFiles) {
|
||||
for (const path of queryFiles) {
|
||||
const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Up/${path}.sql`).toString();
|
||||
|
||||
queryRunner.query(query);
|
||||
|
@ -11,7 +11,7 @@ export default class MigrationHelper {
|
|||
}
|
||||
|
||||
public static Down(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) {
|
||||
for (let path of queryFiles) {
|
||||
for (const path of queryFiles) {
|
||||
const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Down/${path}.sql`).toString();
|
||||
|
||||
queryRunner.query(query);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export default class StringTools {
|
||||
public static Capitalise(str: string): string {
|
||||
const words = str.split(" ");
|
||||
let result: string[] = [];
|
||||
const result: string[] = [];
|
||||
|
||||
words.forEach(word => {
|
||||
const firstLetter = word.substring(0, 1).toUpperCase();
|
||||
|
@ -26,10 +26,10 @@ export default class StringTools {
|
|||
public static RandomString(length: number) {
|
||||
let result = "";
|
||||
|
||||
const characters = 'abcdefghkmnpqrstuvwxyz23456789';
|
||||
const characters = "abcdefghkmnpqrstuvwxyz23456789";
|
||||
const charactersLength = characters.length;
|
||||
|
||||
for ( var i = 0; i < length; i++ ) {
|
||||
for ( let i = 0; i < length; i++ ) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,6 @@ export default class StringTools {
|
|||
}
|
||||
|
||||
public static ReplaceAll(str: string, find: string, replace: string) {
|
||||
return str.replace(new RegExp(find, 'g'), replace);
|
||||
return str.replace(new RegExp(find, "g"), replace);
|
||||
}
|
||||
}
|
|
@ -4,23 +4,23 @@ export default class TimeLengthInput {
|
|||
public readonly value: string;
|
||||
|
||||
constructor(input: string) {
|
||||
this.value = StringTools.ReplaceAll(input, ',', '');
|
||||
this.value = StringTools.ReplaceAll(input, ",", "");
|
||||
}
|
||||
|
||||
public GetDays(): number {
|
||||
return this.GetValue('d');
|
||||
return this.GetValue("d");
|
||||
}
|
||||
|
||||
public GetHours(): number {
|
||||
return this.GetValue('h');
|
||||
return this.GetValue("h");
|
||||
}
|
||||
|
||||
public GetMinutes(): number {
|
||||
return this.GetValue('m');
|
||||
return this.GetValue("m");
|
||||
}
|
||||
|
||||
public GetSeconds(): number {
|
||||
return this.GetValue('s');
|
||||
return this.GetValue("s");
|
||||
}
|
||||
|
||||
public GetMilliseconds(): number {
|
||||
|
@ -106,7 +106,7 @@ export default class TimeLengthInput {
|
|||
}
|
||||
|
||||
private GetValue(designation: string): number {
|
||||
const valueSplit = this.value.split(' ');
|
||||
const valueSplit = this.value.split(" ");
|
||||
|
||||
const desString = valueSplit.find(x => x.charAt(x.length - 1) == designation);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
|||
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
||||
|
||||
export default async function ReloadDB(req: Request, res: Response) {
|
||||
console.log('Reloading Card DB...');
|
||||
console.log("Reloading Card DB...");
|
||||
|
||||
await CardMetadataFunction.Execute();
|
||||
|
||||
|
|
|
@ -20,15 +20,15 @@ import Reroll from "./buttonEvents/Reroll";
|
|||
export default class Registry {
|
||||
public static RegisterCommands() {
|
||||
// Global Commands
|
||||
CoreClient.RegisterCommand('about', new About());
|
||||
CoreClient.RegisterCommand('drop', new Drop());
|
||||
CoreClient.RegisterCommand('gdrivesync', new Gdrivesync());
|
||||
CoreClient.RegisterCommand('inventory', new Inventory());
|
||||
CoreClient.RegisterCommand('resync', new Resync());
|
||||
CoreClient.RegisterCommand("about", new About());
|
||||
CoreClient.RegisterCommand("drop", new Drop());
|
||||
CoreClient.RegisterCommand("gdrivesync", new Gdrivesync());
|
||||
CoreClient.RegisterCommand("inventory", new Inventory());
|
||||
CoreClient.RegisterCommand("resync", new Resync());
|
||||
|
||||
// Test Commands
|
||||
CoreClient.RegisterCommand('dropnumber', new Dropnumber(), Environment.Test);
|
||||
CoreClient.RegisterCommand('droprarity', new Droprarity(), Environment.Test);
|
||||
CoreClient.RegisterCommand("dropnumber", new Dropnumber(), Environment.Test);
|
||||
CoreClient.RegisterCommand("droprarity", new Droprarity(), Environment.Test);
|
||||
}
|
||||
|
||||
public static RegisterEvents() {
|
||||
|
@ -36,8 +36,8 @@ export default class Registry {
|
|||
}
|
||||
|
||||
public static RegisterButtonEvents() {
|
||||
CoreClient.RegisterButtonEvent('claim', new Claim());
|
||||
CoreClient.RegisterButtonEvent('inventory', new InventoryButtonEvent);
|
||||
CoreClient.RegisterButtonEvent('reroll', new Reroll());
|
||||
CoreClient.RegisterButtonEvent("claim", new Claim());
|
||||
CoreClient.RegisterButtonEvent("inventory", new InventoryButtonEvent);
|
||||
CoreClient.RegisterButtonEvent("reroll", new Reroll());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
import { ButtonInteraction } from "discord.js";
|
||||
|
||||
export class ButtonEvent {
|
||||
public execute(interaction: ButtonInteraction) {
|
||||
|
||||
}
|
||||
export abstract class ButtonEvent {
|
||||
abstract execute(interaction: ButtonInteraction): Promise<void>;
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||
|
||||
export class Command {
|
||||
public CommandBuilder: any;
|
||||
|
||||
public execute(interaction: CommandInteraction) {
|
||||
export abstract class Command {
|
||||
public CommandBuilder: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
|
||||
|
||||
}
|
||||
abstract execute(interaction: CommandInteraction): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ export default class Webhooks {
|
|||
}
|
||||
|
||||
private setupRoutes() {
|
||||
this.app.post('/api/reload-db', ReloadDB);
|
||||
this.app.post("/api/reload-db", ReloadDB);
|
||||
}
|
||||
|
||||
private setupListen() {
|
||||
|
|
Loading…
Reference in a new issue