mirror of
https://github.com/nx-bat/synapse.git
synced 2026-09-22 14:39:04 -04:00
(events): added messageCreate & messageUpdate. this also removes the
`shardReady` event as it isn't in use.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { CommandClient, Event, Guild } from "athena-prime";
|
import { CommandClient, Event, Guild } from "athena-prime";
|
||||||
import { createConfiguration } from "../../utils/database";
|
import { database } from "../../utils";
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ class GuildCreateEvent extends Event<CommandClient> {
|
|||||||
event: string = 'guildCreate' as const;
|
event: string = 'guildCreate' as const;
|
||||||
|
|
||||||
async handle(context: CommandClient<any, any>, guild: Guild) {
|
async handle(context: CommandClient<any, any>, guild: Guild) {
|
||||||
await createConfiguration(guild.id);
|
await database.createConfiguration(guild.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CommandClient, Event, Guild } from "athena-prime";
|
import { CommandClient, Event, Guild } from "athena-prime";
|
||||||
import { deleteConfiguration } from "../../utils/database";
|
import { database } from "../../utils";
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class GuildDeleteEvent extends Event<CommandClient> {
|
|||||||
//
|
//
|
||||||
// For simplicity, I'm keeping it like this. In the future this will be handled by
|
// For simplicity, I'm keeping it like this. In the future this will be handled by
|
||||||
// a scheduled task.
|
// a scheduled task.
|
||||||
await deleteConfiguration(guild.id);
|
await database.deleteConfiguration(guild.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -1,11 +1,13 @@
|
|||||||
import guildCreate from './guild/guildCreate';
|
import guildCreate from './guild/guildCreate';
|
||||||
import guildDelete from './guild/guildDelete';
|
import guildDelete from './guild/guildDelete';
|
||||||
|
import messageCreate from './message/messageCreate';
|
||||||
|
import messageUpdate from './message/messageUpdate';
|
||||||
import ready from './client/ready';
|
import ready from './client/ready';
|
||||||
import shardReady from './shard/shardReady';
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
guildCreate,
|
guildCreate,
|
||||||
guildDelete,
|
guildDelete,
|
||||||
ready,
|
messageCreate,
|
||||||
shardReady
|
messageUpdate,
|
||||||
|
ready
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { CommandClient, Event, Message } from "athena-prime";
|
||||||
|
import { database } from "../../utils";
|
||||||
|
|
||||||
|
class MessageCreateEvent extends Event<CommandClient> {
|
||||||
|
event: string = 'messageCreate' as const;
|
||||||
|
|
||||||
|
async handle(context: CommandClient<any, any>, message: Message) {
|
||||||
|
await database.createMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new MessageCreateEvent('messageCreate');
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { CommandClient, Event, Message } from "athena-prime";
|
||||||
|
import { database } from "../../utils";
|
||||||
|
|
||||||
|
class MessageUpdateEvent extends Event<CommandClient> {
|
||||||
|
event: string = 'messageUpdate' as const;
|
||||||
|
|
||||||
|
async handle(context: CommandClient<any, any>, message: Message, _: Message) {
|
||||||
|
await database.updateMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new MessageUpdateEvent('messageUpdate');
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Event, CommandClient } from 'athena-prime';
|
|
||||||
|
|
||||||
class ShardReadyEvent extends Event<CommandClient> {
|
|
||||||
event: string = 'shardReady' as const;
|
|
||||||
|
|
||||||
async handle(context: CommandClient<any, any>, shardId: number) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new ShardReadyEvent('shardReady');
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import postgres from "postgres";
|
import postgres from "postgres";
|
||||||
import { Configuration } from "../types";
|
import { Configuration } from "../types";
|
||||||
|
import { Message } from "athena-prime";
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
@@ -83,3 +84,22 @@ export async function deleteConfiguration(guildId: string): Promise<void> {
|
|||||||
WHERE guild_id = ${guildId};
|
WHERE guild_id = ${guildId};
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Messages ---
|
||||||
|
|
||||||
|
export async function createMessage(message: Message) {
|
||||||
|
if (!message.guildID) return; // This shouldn't be false since this is only ever called in a guild context.
|
||||||
|
|
||||||
|
await client`
|
||||||
|
INSERT INTO messages (message_id, channel_id, guild_id, content)
|
||||||
|
VALUES (${message.id}, ${message.channel.id}, ${message.guildID}, ${message.content})
|
||||||
|
ON CONFLICT (message_id) DO NOTHING;
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateMessage(message: Message) {
|
||||||
|
await client`
|
||||||
|
UPDATE messages SET content = ${message.content}
|
||||||
|
WHERE message_id = ${message.id};
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
export * from './database';
|
export * as database from './database';
|
||||||
|
|||||||
Reference in New Issue
Block a user