feat: stats setup

This commit is contained in:
TresAbhi committed 2023-04-22 01:58:42 +00:00
1 parent 5f3d42c690
commit bf7993fa38
8 files changed
+74 -13

No files matched your search

+8 -3
View File
@@ -9,8 +9,10 @@ import {
} from 'discord.js';
import { readdirSync } from 'fs';
import discord from '../../discord.json' assert { type: 'json' };
import getClientId from '../utilities/getClientId.js';
export interface CommandRegistry {
disabled?: boolean;
data: SlashCommandBuilder;
execute: (interaction: Interaction) => void;
}
@@ -22,15 +24,18 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`)) as CommandRegistry;
commands.push(command.data.toJSON());
commandCollection.set(command.data.name, command);
if (!command.disabled) {
commands.push(command.data.toJSON());
commandCollection.set(command.data.name, command);
}
}
try {
console.log(`Started refreshing ${commands.length} command(s).`);
const data = (await rest.put(
Routes.applicationGuildCommands(discord.client_id, discord.guild_id),
Routes.applicationGuildCommands(getClientId(), discord.guild_id),
{ body: commands },
)) as { length: number };
+45
View File
@@ -0,0 +1,45 @@
import {
CacheType,
ChatInputCommandInteraction,
SlashCommandBuilder,
} from 'discord.js';
import { SERVERS } from '../constants/servers.js';
export async function execute(
interaction: ChatInputCommandInteraction<CacheType>,
) {
interaction.reply('YOU SUCK MORON GO PLAY ROBLOX');
}
export const data = new SlashCommandBuilder()
.setName('stats')
.setDescription("Gets the user's in-game statistics")
.addStringOption((option) =>
option
.setName('server')
.setDescription('The Blitz server you are in')
.addChoices(
{ name: SERVERS.com, value: 'com' },
{ name: SERVERS.eu, value: 'eu' },
{ name: SERVERS.asia, value: 'asia' },
)
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('ign')
.setDescription('The username you use in Blitz')
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('period')
.setDescription('The last number of days of stats')
.setChoices(
{ name: '30 Days', value: '30' },
{ name: '60 Days', value: '60' },
{ name: '90 Days', value: '90' },
{ name: 'Career', value: 'career' },
)
.setRequired(true),
);
+6 -5
View File
@@ -6,16 +6,17 @@ import {
} from 'discord.js';
import fetch from 'node-fetch';
import discord from '../../discord.json' assert { type: 'json' };
import { SERVERS } from '../constants/servers.js';
import AccountList from '../types/accountList.js';
const SERVER_NAMES = { com: 'North America', eu: 'Europe', asia: 'Asia' };
export const disabled = true;
export async function execute(
interaction: ChatInputCommandInteraction<CacheType>,
) {
const ign = interaction.options.getString('ign')!;
const server = interaction.options.getString('server')!;
const serverName = SERVER_NAMES[server as keyof typeof SERVER_NAMES];
const serverName = SERVERS[server as keyof typeof SERVERS];
const players = (await fetch(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`,
).then((response) => response.json())) as AccountList;
@@ -102,9 +103,9 @@ export const data = new SlashCommandBuilder()
.setDescription('The Blitz server you are in')
.setRequired(true)
.addChoices(
{ name: SERVER_NAMES.com, value: 'com' },
{ name: SERVER_NAMES.eu, value: 'eu' },
{ name: SERVER_NAMES.asia, value: 'asia' },
{ name: SERVERS.com, value: 'com' },
{ name: SERVERS.eu, value: 'eu' },
{ name: SERVERS.asia, value: 'asia' },
),
)
.addStringOption((option) =>
+5
View File
@@ -0,0 +1,5 @@
export const SERVERS = {
com: 'North America',
eu: 'Europe',
asia: 'Asia',
};
+1 -2
View File
@@ -1,5 +1,4 @@
import { Client, GatewayIntentBits } from 'discord.js';
import guildMemberAdd from './behaviors/guildMemberAdd.js';
import interactionCreate from './behaviors/interactionCreate.js';
import ready from './behaviors/ready.js';
import tokenRequirements from './utilities/tokenRequirements.js';
@@ -12,6 +11,6 @@ const client = new Client({
client.on('error', console.error);
client.on('ready', ready);
client.on('guildMemberAdd', guildMemberAdd);
// client.on('guildMemberAdd', guildMemberAdd);
client.on('interactionCreate', interactionCreate);
client.login(process.env.DISCORD_TOKEN);
+8
View File
@@ -0,0 +1,8 @@
import { argv } from 'process';
import discord from '../../discord.json' assert { type: 'json' };
const isDev = argv.includes('--dev');
export default function getClientId() {
return isDev ? discord.client_id_dev : discord.client_id;
}