apparently i need to update the discord.js for this so let me do that
This commit is contained in:
parent
8de11bdac2
commit
d735d51676
|
@ -10,6 +10,7 @@ import { Command } from './types/index';
|
||||||
import { startServer } from './web/web';
|
import { startServer } from './web/web';
|
||||||
import { init as initPVP } from './lib/rpg/pvp';
|
import { init as initPVP } from './lib/rpg/pvp';
|
||||||
import { autocomplete } from './lib/autocomplete';
|
import { autocomplete } from './lib/autocomplete';
|
||||||
|
import { setupListeners } from './lib/events';
|
||||||
|
|
||||||
const bot = new Client({
|
const bot = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -69,6 +70,8 @@ bot.on(Events.ClientReady, async () => {
|
||||||
log.nonsense(`| ${prettyBytes(memory.rss)} memory usage, ${prettyBytes(memory.heapUsed)} / ${prettyBytes(memory.heapTotal)} heap usage`);
|
log.nonsense(`| ${prettyBytes(memory.rss)} memory usage, ${prettyBytes(memory.heapUsed)} / ${prettyBytes(memory.heapTotal)} heap usage`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setupListeners(bot);
|
||||||
|
|
||||||
function stringifyArg(arg: CommandInteractionOption): string {
|
function stringifyArg(arg: CommandInteractionOption): string {
|
||||||
switch (arg.type) {
|
switch (arg.type) {
|
||||||
case ApplicationCommandOptionType.Boolean:
|
case ApplicationCommandOptionType.Boolean:
|
||||||
|
|
|
@ -102,4 +102,10 @@ export interface RoleSeperator {
|
||||||
guild: string,
|
guild: string,
|
||||||
role: string,
|
role: string,
|
||||||
type: RoleSeperatorType,
|
type: RoleSeperatorType,
|
||||||
|
}
|
||||||
|
export interface AuditLog {
|
||||||
|
guild: string,
|
||||||
|
channel: string,
|
||||||
|
// comma-seperated
|
||||||
|
eventTypes: string,
|
||||||
}
|
}
|
|
@ -1,39 +1,41 @@
|
||||||
import { Sticker, ThreadChannel, Message, User, Invite, GuildMember, GuildScheduledEvent, GuildEmoji, Channel } from 'discord.js';
|
import { Sticker, ThreadChannel, Message, User, Invite, GuildMember, GuildScheduledEvent, GuildEmoji, Channel, Client, Events, GuildAuditLogsEntry, AuditLogEvent } from 'discord.js';
|
||||||
|
import { AuditLog, db } from './db';
|
||||||
|
import * as log from './log';
|
||||||
|
|
||||||
export enum EventType {
|
export enum EventType {
|
||||||
ChannelCreate,
|
ChannelCreate = 'CHANNEL_CREATE',
|
||||||
ChannelRename,
|
ChannelRename = 'CHANNEL_RENAME',
|
||||||
ChannelDelete,
|
ChannelDelete = 'CHANNEL_DELETE',
|
||||||
|
|
||||||
EmojiCreate,
|
EmojiCreate = 'EMOJI_CREATE',
|
||||||
EmojiRename,
|
EmojiRename = 'EMOJI_RENAME',
|
||||||
EmojiDelete,
|
EmojiDelete = 'EMOJI_DELETE',
|
||||||
|
|
||||||
EventCreate,
|
EventCreate = 'EVENT_CREATE',
|
||||||
EventEdit,
|
EventEdit = 'EVENT_EDIT',
|
||||||
EventDelete,
|
EventDelete = 'EVENT_DELETE',
|
||||||
|
|
||||||
InviteCreate,
|
InviteCreate = 'INVITE_CREATE',
|
||||||
InviteUpdate,
|
InviteUpdate = 'INVITE_UPDATE',
|
||||||
InviteDelete,
|
InviteDelete = 'INVITE_DELETE',
|
||||||
|
|
||||||
MemberBan,
|
MemberBan = 'MEMBER_BAN',
|
||||||
MemberUnban,
|
MemberUnban = 'MEMBER_UNBAN',
|
||||||
MemberKick,
|
MemberKick = 'MEMBER_KICK',
|
||||||
MemberDisconnect,
|
MemberDisconnect = 'MEMBER_DISCONNECT',
|
||||||
MemberNickname,
|
MemberNickname = 'MEMBER_NICKNAME',
|
||||||
MemberChangeRoles,
|
MemberChangeRoles = 'MEMBER_CHANGE_ROLES',
|
||||||
|
|
||||||
MessageDelete,
|
MessageDelete = 'MESSAGE_DELETE',
|
||||||
MessageEdit,
|
MessageEdit = 'MESSAGE_EDIT',
|
||||||
|
|
||||||
StickerCreate,
|
StickerCreate = 'STICKER_CREATE',
|
||||||
StickerRename,
|
StickerRename = 'STICKER_RENAME',
|
||||||
StickerDelete,
|
StickerDelete = 'STICKER_DELETE',
|
||||||
|
|
||||||
ThreadCreate,
|
ThreadCreate = 'THREAD_CREATE',
|
||||||
ThreadEdit,
|
ThreadEdit = 'THREAD_EDIT',
|
||||||
ThreadDelete,
|
ThreadDelete = 'THREAD_DELETE',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Event = {
|
export type Event = {
|
||||||
|
@ -153,6 +155,49 @@ export type Event = {
|
||||||
thread: ThreadChannel,
|
thread: ThreadChannel,
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function triggerEvent(event: Event) {
|
export async function triggerEvent(bot: Client, event: Event) {
|
||||||
|
const type = event.type;
|
||||||
|
|
||||||
|
log.info(`Got event ${event.type}: ${JSON.stringify(event)}`);
|
||||||
|
|
||||||
|
const logs = await db<AuditLog>('auditLogs')
|
||||||
|
.select('guild', 'channel')
|
||||||
|
// @ts-expect-error this LITERALLY works
|
||||||
|
.whereLike(db.raw('UPPER(eventTypes)'), `%${type.toUpperCase()}%`);
|
||||||
|
|
||||||
|
for (const auditLog of logs) {
|
||||||
|
let channel;
|
||||||
|
try {
|
||||||
|
channel = await bot.channels.fetch(auditLog.channel);
|
||||||
|
} catch (err) {
|
||||||
|
log.warn(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel && channel.isText()) {
|
||||||
|
channel.send(`${JSON.stringify(event)}`);
|
||||||
|
} else {
|
||||||
|
log.warn(`Channel ${auditLog.channel} from guild ${auditLog.guild} not found! Deleting audit log`);
|
||||||
|
await db<AuditLog>('auditLogs')
|
||||||
|
.where('channel', auditLog.channel)
|
||||||
|
.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupListeners(bot: Client) {
|
||||||
|
/*bot.on(Events.GuildAuditLogEntryCreate, async (auditLog: GuildAuditLogsEntry) => {
|
||||||
|
const { action, extra: channel, executorId, targetId } = auditLog;
|
||||||
|
|
||||||
|
// Check only for deleted messages.
|
||||||
|
if (action !== AuditLogEvent.MessageDelete) return;
|
||||||
|
|
||||||
|
// Ensure the executor is cached.
|
||||||
|
const executor = await bot.users.fetch(executorId);
|
||||||
|
|
||||||
|
// Ensure the author whose message was deleted is cached.
|
||||||
|
const target = await bot.users.fetch(targetId);
|
||||||
|
|
||||||
|
// Log the output.
|
||||||
|
console.log(`A message by ${target.tag} was deleted by ${executor.tag} in ${channel}.`);
|
||||||
|
});*/
|
||||||
}
|
}
|
Loading…
Reference in New Issue