This commit is contained in:
parent
84749c3381
commit
58461db7c2
10 changed files with 86 additions and 8 deletions
2
.dev.env
2
.dev.env
|
@ -12,6 +12,7 @@ BOT_AUTHOR=Vylpes
|
|||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=682942374040961060
|
||||
BOT_ENV=4
|
||||
BOT_ADMINS=147392775707426816,887272961504071690
|
||||
|
||||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
@ -30,5 +31,4 @@ DB_CARD_FILE=:memory:
|
|||
|
||||
EXPRESS_PORT=3303
|
||||
|
||||
GDRIVESYNC_WHITELIST=147392775707426816,887272961504071690
|
||||
GDRIVESYNC_AUTO=true
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -107,5 +107,5 @@ config.json
|
|||
.DS_Store
|
||||
ormconfig.json
|
||||
gdrive-credentials.json
|
||||
cards/
|
||||
data/
|
||||
*.db
|
|
@ -12,6 +12,7 @@ BOT_AUTHOR=Vylpes
|
|||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=1093810443589529631
|
||||
BOT_ENV=1
|
||||
BOT_ADMINS=147392775707426816,887272961504071690
|
||||
|
||||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
@ -30,5 +31,4 @@ DB_CARD_FILE=:memory:
|
|||
|
||||
EXPRESS_PORT=3323
|
||||
|
||||
GDRIVESYNC_WHITELIST=147392775707426816,887272961504071690
|
||||
GDRIVESYNC_AUTO=false
|
||||
|
|
|
@ -12,6 +12,7 @@ BOT_AUTHOR=Vylpes
|
|||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=1147976642942214235
|
||||
BOT_ENV=2
|
||||
BOT_ADMINS=147392775707426816,887272961504071690
|
||||
|
||||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
@ -30,5 +31,4 @@ DB_CARD_FILE=:memory:
|
|||
|
||||
EXPRESS_PORT=3313
|
||||
|
||||
GDRIVESYNC_WHITELIST=147392775707426816,887272961504071690
|
||||
GDRIVESYNC_AUTO=false
|
||||
|
|
|
@ -14,6 +14,7 @@ const requiredConfigs: string[] = [
|
|||
"BOT_OWNERID",
|
||||
"BOT_CLIENTID",
|
||||
"BOT_ENV",
|
||||
"BOT_ADMINS",
|
||||
"DATA_DIR",
|
||||
"DB_HOST",
|
||||
"DB_PORT",
|
||||
|
@ -22,7 +23,6 @@ const requiredConfigs: string[] = [
|
|||
"DB_SYNC",
|
||||
"DB_LOGGING",
|
||||
"EXPRESS_PORT",
|
||||
"GDRIVESYNC_WHITELIST",
|
||||
]
|
||||
|
||||
requiredConfigs.forEach(config => {
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class Gdrivesync extends Command {
|
|||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(',');
|
||||
const whitelistedUsers = process.env.BOT_ADMINS!.split(',');
|
||||
|
||||
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
|
||||
await interaction.reply("Only whitelisted users can use this command.");
|
||||
|
|
68
src/commands/give.ts
Normal file
68
src/commands/give.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
import { CacheType, CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||
import { Command } from "../type/command";
|
||||
import { CoreClient } from "../client/client";
|
||||
import Config from "../database/entities/app/Config";
|
||||
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
|
||||
export default class Give extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('give')
|
||||
.setDescription('Give a user a card manually, in case bot breaks')
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||
.addStringOption(x =>
|
||||
x
|
||||
.setName('cardnumber')
|
||||
.setDescription('G')
|
||||
.setRequired(true))
|
||||
.addUserOption(x =>
|
||||
x
|
||||
.setName('user')
|
||||
.setDescription("The user to give the card to")
|
||||
.setRequired(true));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!CoreClient.AllowDrops) {
|
||||
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.');
|
||||
return;
|
||||
}
|
||||
|
||||
const whitelistedUsers = process.env.BOT_ADMINS!.split(',');
|
||||
|
||||
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
|
||||
await interaction.reply("Only whitelisted users can use this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
const cardNumber = interaction.options.get('cardnumber', true);
|
||||
const user = interaction.options.getUser('user', true);
|
||||
|
||||
const card = CardDropHelperMetadata.GetCardByCardNumber(cardNumber.value!.toString());
|
||||
|
||||
if (!card) {
|
||||
await interaction.reply("Unable to fetch card, please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
let inventory = await Inventory.FetchOneByCardNumberAndUserId(user.id, card.id);
|
||||
|
||||
if (!inventory) {
|
||||
inventory = new Inventory(user.id, card.id, 1);
|
||||
} else {
|
||||
inventory.SetQuantity(inventory.Quantity + 1);
|
||||
}
|
||||
|
||||
await inventory.Save(Inventory, inventory);
|
||||
|
||||
await interaction.reply(`${card.name} given to ${interaction.user}, they now have ${inventory.Quantity}`);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ export default class Resync extends Command {
|
|||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const whitelistedUsers = process.env.GDRIVESYNC_WHITELIST!.split(',');
|
||||
const whitelistedUsers = process.env.BOT_ADMINS!.split(',');
|
||||
|
||||
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
|
||||
await interaction.reply("Only whitelisted users can use this command.");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import CardRarityChances from "../constants/CardRarityChances";
|
||||
import { DropResult } from "../contracts/SeriesMetadata";
|
||||
import { CardMetadata, DropResult } from "../contracts/SeriesMetadata";
|
||||
import { CoreClient } from "../client/client";
|
||||
|
||||
export default class CardDropHelperMetadata {
|
||||
|
@ -47,6 +47,14 @@ export default class CardDropHelperMetadata {
|
|||
};
|
||||
}
|
||||
|
||||
public static GetCardByCardNumber(cardNumber: string): CardMetadata | undefined {
|
||||
const card = CoreClient.Cards
|
||||
.flatMap(x => x.cards)
|
||||
.find(x => x.id == cardNumber);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: Number, imageFileName: string): EmbedBuilder {
|
||||
let description = "";
|
||||
description += `Series: ${drop.series.name}\n`;
|
||||
|
|
|
@ -5,6 +5,7 @@ import { Environment } from "./constants/Environment";
|
|||
import About from "./commands/about";
|
||||
import Drop from "./commands/drop";
|
||||
import Gdrivesync from "./commands/gdrivesync";
|
||||
import Give from "./commands/give";
|
||||
import Inventory from "./commands/inventory";
|
||||
import Resync from "./commands/resync";
|
||||
|
||||
|
@ -23,6 +24,7 @@ export default class Registry {
|
|||
CoreClient.RegisterCommand('about', new About());
|
||||
CoreClient.RegisterCommand('drop', new Drop());
|
||||
CoreClient.RegisterCommand('gdrivesync', new Gdrivesync());
|
||||
CoreClient.RegisterCommand('give', new Give());
|
||||
CoreClient.RegisterCommand('inventory', new Inventory());
|
||||
CoreClient.RegisterCommand('resync', new Resync());
|
||||
|
||||
|
|
Loading…
Reference in a new issue