first commands n'stuff

This commit is contained in:
Lio Young 2021-10-17 18:39:40 +02:00
parent 5544ddbb2b
commit 74d0379885
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import { Context } from "../../utils/types"
import { Command } from "../../modules/eu/src/index"
export = class TestingCommand extends Command {
constructor() {
super({
name: "testing",
aliases: ["t"],
})
// console.log(this)
}
async run(context: Context): Promise<any> {
// console.log(context)
// console.log(this.nsfw)
console.log("testing")
return "Generic command"
}
}

View File

@ -0,0 +1,78 @@
import { Message, Collection, TextChannel, MessageEmbed } from 'discord.js';
import { Context } from '../../utils/types';
import { EuClient } from '../../modules/eu/src/misc/types';
import modulus from '../../utils/modulus'
import prefixHandler from '../../utils/prefix'
import config from '../../utils/config';
import language from '../../utils/language';
import replace from '../../utils/replace';
export = {
name: "messageCreate",
run: async (Eu: EuClient, message: Message) => {
if (message.author.bot) return;
let helper = await prefixHandler(message.guild.id, message.content)
if (!helper.success) return
// @ts-ignore
const cmd = Eu.commands.find((c) => c.name == helper.command || (c.aliases && c.aliases.includes(helper.command)))
if (!cmd) return
if (!Eu.cooldowns.has(cmd.name)) {
Eu.cooldowns.set(cmd.name, new Collection())
}
let ctx: Context = {
Eu, message, modulus, config,
args: helper.args,
channel: (message.channel as TextChannel),
guild: message.guild,
member: message.member,
author: message.author,
settings: await modulus.server(message.guild.id),
// @ts-ignore
isDev: config?.devs.find(d => d == message.author.id)
}
if (ctx.isDev) cmd.permissions = ["NONE"]
if (cmd.permissions !== [] && ctx.member.permissions.toArray().some(p => cmd.permissions.includes(p)))
return ctx.channel.send(replace(/PERMISSIONS/gm, cmd.permissions.join(', '), language.get(ctx.settings.locale).error.permissions))
if (cmd.nsfw && !ctx.channel.nsfw) return ctx.channel.send(language.get(ctx.settings.locale).error.nsfw)
const now = Date.now()
const timestamps = Eu.cooldowns.get(cmd.name)
const cooldown = (cmd.cooldown || 1) * 1000
// @ts-ignore
if (timestamps.has(ctx.author.id)) {
// @ts-ignore
const time = timestamps.get(ctx.author.id) + cooldown
if (now < time) {
const left = ((time - now) / 1000).toFixed(1)
let embed = new MessageEmbed()
.setTitle(replace(/COMMAND/gm, cmd.name, language.get(ctx.settings.locale).error.cooldown.name))
// @ts-ignore
.setDescription(replace(/COMMAND/gm, cmd.name, replace(/COOLDOWN/gm, `${cmd.cooldown}s`, replace(/TIME/g, left, language.get(ctx.settings.locale).error.cooldown.desc))))
.setColor("RED")
// @ts-ignore
return message.channel.send({ embeds: [embed] })
}
} else {
// @ts-ignore
timestamps.set(ctx.author.id, now)
setTimeout(() => {
// @ts-ignore
timestamps.delete(ctx.author.id, now)
}, cooldown);
try {
await cmd.run(ctx)
} catch (error) {
let ErrorEmbed = new MessageEmbed().setTitle(replace(/COMMAND/g, cmd.name, language.get(ctx.settings.locale).error.error)).setDescription(`\`${error.message}\`\n\n\`${error}\``).setColor("RED")
return message.channel.send({ embeds: [ErrorEmbed] })
}
}
}
};

View File

@ -0,0 +1,7 @@
export = {
name: "ready",
run: async (Eu: any) => {
console.log(`${Eu.user.username} is ready!`);
}
};