initial commit

This commit is contained in:
2024-10-13 14:50:19 +00:00
commit dbdbf16bfe
34 changed files with 3035 additions and 0 deletions

29
commands/utils/help.ts Normal file
View File

@@ -0,0 +1,29 @@
import {CommandInteraction, EmbedBuilder} from 'discord.js';
import {Command} from '../../classes/command';
import {logger} from '../../logger';
import {config} from '../../config';
class Help extends Command{
get name(){return "help";}
get description(){return "Help messages.";}
async execute(interaction: CommandInteraction): Promise<void>{
const embed = new EmbedBuilder()
.setTitle("Help message")
.setDescription(`Report issues on [this page](${config.urls.issue})`)
.setColor(0x1f1e33)
.setAuthor({
name: 'Ian Shih (konchin)',
url: config.urls.author,
iconURL: config.urls.icon
})
.setFields(
{name: 'Read the documentation', value: config.urls.help},
{name: 'Read the source code', value: config.urls.git}
);
await interaction.reply({embeds: [embed], ephemeral: true});
logger.log(`Command: help`);
}
};
export const command = new Help();

19
commands/utils/ping.ts Normal file
View File

@@ -0,0 +1,19 @@
import {CommandInteraction} from 'discord.js';
import {Command} from '../../classes/command';
class Ping extends Command{
get name(){return "ping";}
get description(){return "Reply with the RTT of this bot.";}
async execute(interaction: CommandInteraction): Promise<void>{
const sent = await interaction.reply({
content: "Pinging...",
ephemeral: true,
fetchReply: true,
});
await interaction.editReply(`Roundtrip latency: ${
sent.createdTimestamp - interaction.createdTimestamp
}ms`);
}
};
export const command = new Ping();

104
commands/utils/set.ts Normal file
View File

@@ -0,0 +1,104 @@
import discord, {
CommandInteraction,
CommandInteractionOptionResolver,
SlashCommandBuilder,
SlashCommandSubcommandBuilder,
SlashCommandStringOption,
SlashCommandChannelOption,
InteractionResponse,
SlashCommandSubcommandsOnlyBuilder,
} from 'discord.js';
import {HydratedDocument} from 'mongoose';
import {Command} from '../../classes/command';
import {logger} from '../../logger';
import {Guild, guildModel} from '../../models/Guild';
type CIOR = CommandInteractionOptionResolver;
async function log(interaction: CommandInteraction): Promise<void>{
const feature: string | null =
(interaction.options as CIOR).getString('feature');
if(!feature)
throw Error('feature not exist');
const logChannel = (interaction.options as CIOR).getChannel('channel');
if(!logChannel || !('send' in logChannel))
throw Error('logChannel not exist or illegal');
if(!interaction.guild || !interaction.guild.id || !interaction.guild.name)
throw Error('guild not exist');
let guild: HydratedDocument<Guild> | null = null;
switch(feature){
case 'giveaway':
await guildModel.findOneAndUpdate(
{id: interaction.guild.id},
{$set: {
name: interaction.guild.name,
giveawayLogChannelId: logChannel.id
}},
{new: true, upsert: true}
);
break;
case 'autorole':
await guildModel.findOneAndUpdate(
{id: interaction.guild.id},
{$set: {
name: interaction.guild.name,
autoroleLogChannelId: logChannel.id
}},
{new: true, upsert: true}
);
break;
}
await interaction.reply({
content: logger.log(`The log channel of ${feature} has been set to ${logChannel}`)
});
;
}
class SetVariables extends Command{
get name(){return "set";}
get description(){return "Set guild variables.";}
async execute(interaction: CommandInteraction): Promise<void>{
try{
const subcommand: string =
(interaction.options as CIOR).getSubcommand();
switch(subcommand){
case 'log':
await log(interaction); break;
default:
throw Error('subcommand not exist');
}
}catch(err: unknown){
let message;
if(err instanceof Error) message = err.message;
else message = String(message);
logger.error(`While executing "/set", ${message}`);
await interaction.reply({content: `While executing "/set", ${message}`});
}
}
override build(): SlashCommandSubcommandsOnlyBuilder{
return new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description)
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand
.setName('log')
.setDescription('Set log of features.')
.addStringOption((option: SlashCommandStringOption) => option
.setName('feature')
.setDescription('Specify the to be set feature.')
.setRequired(true)
.addChoices(
{name: 'giveaway', value: 'giveaway'},
{name: 'autorole', value: 'autorole'},
)
)
.addChannelOption((option: SlashCommandChannelOption) => option
.setName('channel')
.setDescription('The channel that log send to.')
.setRequired(true)
)
)
}
};
export const command = new SetVariables();