First iteration!
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
import type { ChatInputCommandDeniedPayload, Events } from '@sapphire/framework';
|
||||
import { Listener, UserError } from '@sapphire/framework';
|
||||
|
||||
export class UserEvent extends Listener<typeof Events.ChatInputCommandDenied> {
|
||||
public async run({ context, message: content }: UserError, { interaction }: ChatInputCommandDeniedPayload) {
|
||||
// `context: { silent: true }` should make UserError silent:
|
||||
// Use cases for this are for example permissions error when running the `eval` command.
|
||||
if (Reflect.get(Object(context), 'silent')) return;
|
||||
|
||||
if (interaction.deferred || interaction.replied) {
|
||||
return interaction.editReply({
|
||||
content,
|
||||
allowedMentions: { users: [interaction.user.id], roles: [] }
|
||||
});
|
||||
}
|
||||
|
||||
return interaction.reply({
|
||||
content,
|
||||
allowedMentions: { users: [interaction.user.id], roles: [] },
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import { Listener, LogLevel, type ChatInputCommandSuccessPayload } from '@sapphire/framework';
|
||||
import type { Logger } from '@sapphire/plugin-logger';
|
||||
import { logSuccessCommand } from '../../../lib/utils';
|
||||
|
||||
export class UserListener extends Listener {
|
||||
public run(payload: ChatInputCommandSuccessPayload) {
|
||||
logSuccessCommand(payload);
|
||||
}
|
||||
|
||||
public onLoad() {
|
||||
this.enabled = (this.container.logger as Logger).level <= LogLevel.Debug;
|
||||
return super.onLoad();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import type { ContextMenuCommandDeniedPayload, Events } from '@sapphire/framework';
|
||||
import { Listener, UserError } from '@sapphire/framework';
|
||||
|
||||
export class UserEvent extends Listener<typeof Events.ContextMenuCommandDenied> {
|
||||
public async run({ context, message: content }: UserError, { interaction }: ContextMenuCommandDeniedPayload) {
|
||||
// `context: { silent: true }` should make UserError silent:
|
||||
// Use cases for this are for example permissions error when running the `eval` command.
|
||||
if (Reflect.get(Object(context), 'silent')) return;
|
||||
|
||||
if (interaction.deferred || interaction.replied) {
|
||||
return interaction.editReply({
|
||||
content,
|
||||
allowedMentions: { users: [interaction.user.id], roles: [] }
|
||||
});
|
||||
}
|
||||
|
||||
return interaction.reply({
|
||||
content,
|
||||
allowedMentions: { users: [interaction.user.id], roles: [] },
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import { Listener, LogLevel, type ContextMenuCommandSuccessPayload } from '@sapphire/framework';
|
||||
import type { Logger } from '@sapphire/plugin-logger';
|
||||
import { logSuccessCommand } from '../../../lib/utils';
|
||||
|
||||
export class UserListener extends Listener {
|
||||
public run(payload: ContextMenuCommandSuccessPayload) {
|
||||
logSuccessCommand(payload);
|
||||
}
|
||||
|
||||
public onLoad() {
|
||||
this.enabled = (this.container.logger as Logger).level <= LogLevel.Debug;
|
||||
return super.onLoad();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import type { Events, MessageCommandDeniedPayload } from '@sapphire/framework';
|
||||
import { Listener, type UserError } from '@sapphire/framework';
|
||||
|
||||
export class UserEvent extends Listener<typeof Events.MessageCommandDenied> {
|
||||
public async run({ context, message: content }: UserError, { message }: MessageCommandDeniedPayload) {
|
||||
// `context: { silent: true }` should make UserError silent:
|
||||
// Use cases for this are for example permissions error when running the `eval` command.
|
||||
if (Reflect.get(Object(context), 'silent')) return;
|
||||
|
||||
return message.reply({ content, allowedMentions: { users: [message.author.id], roles: [] } });
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import type { MessageCommandSuccessPayload } from '@sapphire/framework';
|
||||
import { Listener, LogLevel } from '@sapphire/framework';
|
||||
import type { Logger } from '@sapphire/plugin-logger';
|
||||
import { logSuccessCommand } from '../../../lib/utils';
|
||||
|
||||
export class UserEvent extends Listener {
|
||||
public run(payload: MessageCommandSuccessPayload) {
|
||||
logSuccessCommand(payload);
|
||||
}
|
||||
|
||||
public onLoad() {
|
||||
this.enabled = (this.container.logger as Logger).level <= LogLevel.Debug;
|
||||
return super.onLoad();
|
||||
}
|
||||
}
|
10
src/listeners/mentionPrefixOnly.ts
Normal file
10
src/listeners/mentionPrefixOnly.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import type { Events } from '@sapphire/framework';
|
||||
import { Listener } from '@sapphire/framework';
|
||||
import type { Message } from 'discord.js';
|
||||
|
||||
export class UserEvent extends Listener<typeof Events.MentionPrefixOnly> {
|
||||
public async run(message: Message) {
|
||||
const prefix = this.container.client.options.defaultPrefix;
|
||||
return message.channel.send(prefix ? `My prefix in this guild is: \`${prefix}\`` : 'Cannot find any Prefix for Message Commands.');
|
||||
}
|
||||
}
|
50
src/listeners/ready.ts
Normal file
50
src/listeners/ready.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { ApplyOptions } from '@sapphire/decorators';
|
||||
import { Listener, Store } from '@sapphire/framework';
|
||||
import { blue, gray, green, magenta, magentaBright, white, yellow } from 'colorette';
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
@ApplyOptions<Listener.Options>({ once: true })
|
||||
export class UserEvent extends Listener {
|
||||
private readonly style = dev ? yellow : blue;
|
||||
|
||||
public run() {
|
||||
this.printBanner();
|
||||
this.printStoreDebugInformation();
|
||||
}
|
||||
|
||||
private printBanner() {
|
||||
const success = green('+');
|
||||
|
||||
const llc = dev ? magentaBright : white;
|
||||
const blc = dev ? magenta : blue;
|
||||
|
||||
const line01 = llc('');
|
||||
const line02 = llc('');
|
||||
const line03 = llc('');
|
||||
|
||||
// Offset Pad
|
||||
const pad = ' '.repeat(7);
|
||||
|
||||
console.log(
|
||||
String.raw`
|
||||
${line01} ${pad}${blc('1.0.0')}
|
||||
${line02} ${pad}[${success}] Gateway
|
||||
${line03}${dev ? ` ${pad}${blc('<')}${llc('/')}${blc('>')} ${llc('DEVELOPMENT MODE')}` : ''}
|
||||
`.trim()
|
||||
);
|
||||
}
|
||||
|
||||
private printStoreDebugInformation() {
|
||||
const { client, logger } = this.container;
|
||||
const stores = [...client.stores.values()];
|
||||
const last = stores.pop()!;
|
||||
|
||||
for (const store of stores) logger.info(this.styleStore(store, false));
|
||||
logger.info(this.styleStore(last, true));
|
||||
}
|
||||
|
||||
private styleStore(store: Store<any>, last: boolean) {
|
||||
return gray(`${last ? '└─' : '├─'} Loaded ${this.style(store.size.toString().padEnd(3, ' '))} ${store.name}.`);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user