mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
adapt to new system message type
This commit is contained in:
parent
4776e54bde
commit
5bf7852f22
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<string> {
|
|||
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]}`)
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue