diff --git a/bot/src/bot/modules/event_handler.ts b/bot/src/bot/modules/event_handler.ts index c67246e..42062e0 100644 --- a/bot/src/bot/modules/event_handler.ts +++ b/bot/src/bot/modules/event_handler.ts @@ -8,27 +8,29 @@ import logger from "../logger"; import { storeInfraction } from "../util"; import { DEFAULT_PREFIX } from "./command_handler"; import { SendableEmbed } from "revolt-api"; +import { UserSystemMessage } from "revolt.js"; const DM_SESSION_LIFETIME = 1000 * 60 * 60 * 24 * 30; // Listen to system messages client.on('messageCreate', async message => { - let sysMsg = message.systemMessage; + let systemMessage = message.systemMessage; - if (sysMsg) switch(sysMsg.type) { + if (systemMessage) switch(systemMessage.type) { case 'user_kicked': case 'user_banned': try { + let sysMsg = systemMessage as UserSystemMessage; let recentEvents = await dbs.INFRACTIONS.findOne({ date: { $gt: Date.now() - 30000 }, - user: sysMsg.id, + user: sysMsg.userId, server: message.channel!.serverId!, actionType: sysMsg.type == 'user_kicked' ? 'kick' : 'ban', }); if (!message.channel || - !sysMsg.id || + !sysMsg.userId || recentEvents) return; storeInfraction({ @@ -38,28 +40,30 @@ client.on('messageCreate', async message => { date: message.createdAt.getTime(), server: message.channel!.serverId, type: InfractionType.Manual, - user: sysMsg.id, + user: sysMsg.userId, actionType: sysMsg.type == 'user_kicked' ? 'kick' : 'ban', } as Infraction).catch(console.warn); } catch(e) { console.error(e) } break; case 'user_joined': { try { + let sysMsg = systemMessage as UserSystemMessage; + const [ serverConfig, userConfig ] = await Promise.all([ dbs.SERVERS.findOne({ id: message.channel!.serverId }), - dbs.USERS.findOne({ id: sysMsg.id }), + dbs.USERS.findOne({ id: sysMsg.userId }), ]); if (userConfig?.globalBlacklist && !serverConfig?.allowBlacklistedUsers) { const server = message.channel?.server; if (server && server.havePermission('BanMembers')) { - await server.banUser(sysMsg.id, { reason: BLACKLIST_BAN_REASON }); + await server.banUser(sysMsg.userId, { reason: BLACKLIST_BAN_REASON }); if (server.systemMessages?.user_banned) { const channel = server.channels.find(c => c?.id == server.systemMessages?.user_banned); if (channel && channel.havePermission('SendMessage')) { - const user = client.users.get(sysMsg.id); - await channel.sendMessage(BLACKLIST_MESSAGE(user?.username ?? sysMsg.id)); + const user = sysMsg.user; + await channel.sendMessage(BLACKLIST_MESSAGE(user?.username ?? sysMsg.userId)); } } } diff --git a/bridge/src/revolt/events.ts b/bridge/src/revolt/events.ts index 24ab77f..bdba6ce 100644 --- a/bridge/src/revolt/events.ts +++ b/bridge/src/revolt/events.ts @@ -1,9 +1,9 @@ import { BRIDGED_EMOJIS, BRIDGED_MESSAGES, BRIDGE_CONFIG, logger } from ".."; import { AUTUMN_URL, client } from "./client"; import { client as discordClient } from "../discord/client"; -import { Channel as DiscordChannel, Message as DiscordMessage, MessageEmbed, MessagePayload, TextChannel, WebhookClient, WebhookMessageOptions } from "discord.js"; +import { Message as DiscordMessage, MessageEmbed, MessagePayload, TextChannel, WebhookClient, WebhookMessageOptions } from "discord.js"; import GenericEmbed from "../types/GenericEmbed"; -import { SendableEmbed, SystemMessage } from "revolt-api"; +import { SendableEmbed } from "revolt-api"; import { clipText, discordFetchMessage, @@ -13,6 +13,7 @@ import { import { smartReplace } from "smart-replace"; import { metrics } from "../metrics"; import { fetchEmojiList } from "../discord/bridgeEmojis"; +import { ChannelRenamedSystemMessage, SystemMessage, TextSystemMessage, UserSystemMessage } from "revolt.js"; const RE_MENTION_USER = /<@[0-9A-HJ-KM-NP-TV-Z]{26}>/g; const RE_MENTION_CHANNEL = /<#[0-9A-HJ-KM-NP-TV-Z]{26}>/g; @@ -507,35 +508,35 @@ async function renderSystemMessage(message: SystemMessage): Promise { case "user_joined": case "user_added": return `<:joined:1042831832888127509> ${await getUsername( - message.id + (message as UserSystemMessage).userId )} joined`; case "user_left": case "user_remove": return `<:left:1042831834259652628> ${await getUsername( - message.id + (message as UserSystemMessage).userId )} left`; case "user_kicked": return `<:kicked:1042831835421483050> ${await getUsername( - message.id + (message as UserSystemMessage).userId )} was kicked`; case "user_banned": return `<:banned:1042831836675588146> ${await getUsername( - message.id + (message as UserSystemMessage).userId )} was banned`; case "channel_renamed": return `<:channel_renamed:1042831837912891392> ${await getUsername( - message.by - )} renamed the channel to **${message.name}**`; + (message as ChannelRenamedSystemMessage).byId + )} renamed the channel to **${(message as ChannelRenamedSystemMessage).name}**`; case "channel_icon_changed": return `<:channel_icon:1042831840538542222> ${await getUsername( - message.by + (message as ChannelRenamedSystemMessage).byId )} changed the channel icon`; case "channel_description_changed": return `<:channel_description:1042831839217328228> ${await getUsername( - message.by + (message as ChannelRenamedSystemMessage).byId )} changed the channel description`; case "text": - return message.content; + return (message as TextSystemMessage).content; default: return Object.entries(message) .map((e) => `${e[0]}: ${e[1]}`) diff --git a/lib/.yarn/install-state.gz b/lib/.yarn/install-state.gz index e7b0dae..c64fbd5 100644 Binary files a/lib/.yarn/install-state.gz and b/lib/.yarn/install-state.gz differ