Typed log functions + more

This commit is contained in:
Dragory 2021-08-18 01:51:42 +03:00
parent d2ac700143
commit bed6589d48
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
166 changed files with 4021 additions and 869 deletions

View file

@ -42,6 +42,7 @@ import { hasPermission } from "./functions/hasPermission";
import { activeReloads } from "./guildReloads";
import { refreshMembersIfNeeded } from "./refreshMembers";
import { ConfigSchema, UtilityPluginType } from "./types";
import { LogsPlugin } from "../Logs/LogsPlugin";
const defaultOptions: PluginOptions<UtilityPluginType> = {
config: {
@ -118,7 +119,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
prettyName: "Utility",
},
dependencies: [TimeAndDatePlugin, ModActionsPlugin],
dependencies: [TimeAndDatePlugin, ModActionsPlugin, LogsPlugin],
configSchema: ConfigSchema,
defaultOptions,

View file

@ -1,7 +1,7 @@
import { Message, Snowflake, TextChannel, User } from "discord.js";
import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { SavedMessage } from "../../../data/entities/SavedMessage";
import { LogType } from "../../../data/LogType";
@ -11,6 +11,7 @@ import { allowTimeout } from "../../../RegExpRunner";
import { DAYS, getInviteCodesInString, noop, SECONDS } from "../../../utils";
import { utilityCmd, UtilityPluginType } from "../types";
import { boolean, number } from "io-ts";
import { LogsPlugin } from "../../Logs/LogsPlugin";
const MAX_CLEAN_COUNT = 150;
const MAX_CLEAN_TIME = 1 * DAYS;
@ -42,9 +43,9 @@ export async function cleanMessages(
const baseUrl = getBaseUrl(pluginData);
const archiveUrl = pluginData.state.archives.getUrl(baseUrl, archiveId);
pluginData.state.logs.log(LogType.CLEAN, {
mod: userToConfigAccessibleUser(mod),
channel: channelToConfigAccessibleChannel(channel),
pluginData.getPlugin(LogsPlugin).logClean({
mod,
channel,
count: savedMessages.length,
archiveUrl,
});

View file

@ -1,13 +1,14 @@
import { VoiceChannel } from "discord.js";
import {
channelToConfigAccessibleChannel,
memberToConfigAccessibleMember,
userToConfigAccessibleUser,
} from "../../../utils/configAccessibleObjects";
channelToTemplateSafeChannel,
memberToTemplateSafeMember,
userToTemplateSafeUser,
} from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { utilityCmd } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const VcdisconnectCmd = utilityCmd({
trigger: ["vcdisconnect", "vcdisc", "vcdc", "vckick", "vck"],
@ -38,10 +39,10 @@ export const VcdisconnectCmd = utilityCmd({
return;
}
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_DISCONNECT, {
mod: userToConfigAccessibleUser(msg.author),
member: memberToConfigAccessibleMember(args.member),
oldChannel: channelToConfigAccessibleChannel(channel),
pluginData.getPlugin(LogsPlugin).logVoiceChannelForceDisconnect({
mod: msg.author,
member: args.member,
oldChannel: channel,
});
sendSuccessMessage(pluginData, msg.channel, `**${args.member.user.tag}** disconnected from **${channel.name}**`);

View file

@ -1,15 +1,16 @@
import { Snowflake, VoiceChannel } from "discord.js";
import {
channelToConfigAccessibleChannel,
memberToConfigAccessibleMember,
userToConfigAccessibleUser,
} from "../../../utils/configAccessibleObjects";
channelToTemplateSafeChannel,
memberToTemplateSafeMember,
userToTemplateSafeUser,
} from "../../../utils/templateSafeObjects";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { channelMentionRegex, isSnowflake, simpleClosestStringMatch } from "../../../utils";
import { utilityCmd } from "../types";
import { ChannelTypeStrings } from "../../../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export const VcmoveCmd = utilityCmd({
trigger: "vcmove",
@ -79,11 +80,11 @@ export const VcmoveCmd = utilityCmd({
return;
}
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_MOVE, {
mod: userToConfigAccessibleUser(msg.author),
member: memberToConfigAccessibleMember(args.member),
oldChannel: channelToConfigAccessibleChannel(oldVoiceChannel!),
newChannel: channelToConfigAccessibleChannel(channel),
pluginData.getPlugin(LogsPlugin).logVoiceChannelForceMove({
mod: msg.author,
member: args.member,
oldChannel: oldVoiceChannel!,
newChannel: channel,
});
sendSuccessMessage(pluginData, msg.channel, `**${args.member.user.tag}** moved to **${channel.name}**`);
@ -179,11 +180,11 @@ export const VcmoveAllCmd = utilityCmd({
continue;
}
pluginData.state.logs.log(LogType.VOICE_CHANNEL_FORCE_MOVE, {
mod: userToConfigAccessibleUser(msg.author),
member: memberToConfigAccessibleMember(currMember),
oldChannel: channelToConfigAccessibleChannel(args.oldChannel),
newChannel: channelToConfigAccessibleChannel(channel),
pluginData.getPlugin(LogsPlugin).logVoiceChannelForceMove({
mod: msg.author,
member: currMember,
oldChannel: args.oldChannel,
newChannel: channel,
});
}