3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Add custom logger. Fix a bunch of errors. Optimize imports.

This commit is contained in:
Dragory 2020-07-22 22:56:21 +03:00
parent 0dae54745d
commit 1064a1ca46
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
89 changed files with 198 additions and 229 deletions

View file

@ -1,5 +1,5 @@
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { ConfigSchema, AutoReactionsPluginType } from "./types";
import { AutoReactionsPluginType, ConfigSchema } from "./types";
import { PluginOptions } from "knub";
import { NewAutoReactionsCmd } from "./commands/NewAutoReactionsCmd";
import { DisableAutoReactionsCmd } from "./commands/DisableAutoReactionsCmd";

View file

@ -1,6 +1,6 @@
import { autoReactionsCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isEmoji, customEmojiRegex, canUseEmoji } from "src/utils";
import { canUseEmoji, customEmojiRegex, isEmoji } from "src/utils";
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
export const NewAutoReactionsCmd = autoReactionsCmd({

View file

@ -1,7 +1,7 @@
import { autoReactionsEvt } from "../types";
import { isDiscordRESTError } from "src/utils";
import { logger } from "knub";
import { LogType } from "src/data/LogType";
import { logger } from "../../../logger";
export const AddReactionsEvt = autoReactionsEvt({
event: "messageCreate",

View file

@ -1,6 +1,5 @@
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { CaseArgs, CaseNoteArgs, CasesPluginType, ConfigSchema } from "./types";
import { resolveUser } from "../../utils";
import { createCase } from "./functions/createCase";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildArchives } from "../../data/GuildArchives";

View file

@ -2,7 +2,8 @@ import { CaseArgs, CasesPluginType } from "../types";
import { resolveUser } from "../../../utils";
import { PluginData } from "knub";
import { createCaseNote } from "./createCaseNote";
import { postToCaseLogChannel } from "./postToCaseLogChannel";
import { postCaseToCaseLogChannel } from "./postToCaseLogChannel";
import { logger } from "../../../logger";
export async function createCase(pluginData: PluginData<CasesPluginType>, args: CaseArgs) {
const user = await resolveUser(pluginData.client, args.userId);
@ -21,7 +22,7 @@ export async function createCase(pluginData: PluginData<CasesPluginType>, args:
const existingAuditLogCase = await pluginData.state.cases.findByAuditLogId(args.auditLogId);
if (existingAuditLogCase) {
delete args.auditLogId;
console.warn(`Duplicate audit log ID for mod case: ${args.auditLogId}`);
logger.warn(`Duplicate audit log ID for mod case: ${args.auditLogId}`);
}
}
@ -66,7 +67,7 @@ export async function createCase(pluginData: PluginData<CasesPluginType>, args:
(!args.automatic || config.log_automatic_actions) &&
args.postInCaseLogOverride !== false
) {
await postToCaseLogChannel(pluginData, createdCase);
await postCaseToCaseLogChannel(pluginData, createdCase);
}
return createdCase;

View file

@ -1,4 +1,4 @@
import { plugin, PluginData } from "knub";
import { PluginData } from "knub";
import { CasesPluginType } from "../types";
import { Message, MessageContent, MessageFile, TextChannel } from "eris";
import { isDiscordRESTError } from "../../../utils";
@ -6,6 +6,7 @@ import { LogType } from "../../../data/LogType";
import { Case } from "../../../data/entities/Case";
import { getCaseEmbed } from "./getCaseEmbed";
import { resolveCaseId } from "./resolveCaseId";
import { logger } from "../../../logger";
export async function postToCaseLogChannel(
pluginData: PluginData<CasesPluginType>,
@ -23,7 +24,7 @@ export async function postToCaseLogChannel(
result = await caseLogChannel.createMessage(content, file);
} catch (e) {
if (isDiscordRESTError(e) && (e.code === 50013 || e.code === 50001)) {
console.warn(
logger.warn(
`Missing permissions to post mod cases in <#${caseLogChannel.id}> in guild ${pluginData.guild.name} (${pluginData.guild.id})`,
);
pluginData.state.logs.log(LogType.BOT_ALERT, {

View file

@ -4,9 +4,7 @@ import { CaseTypes } from "../../data/CaseTypes";
import { BasePluginType } from "knub";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildCases } from "../../data/GuildCases";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildArchives } from "../../data/GuildArchives";
import { Supporters } from "../../data/Supporters";
export const ConfigSchema = t.type({
log_automatic_actions: t.boolean,

View file

@ -1,8 +1,4 @@
import { BasePluginType } from "knub";
import { GuildMutes } from "../../data/GuildMutes";
import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs";
import { GuildArchives } from "../../data/GuildArchives";
import { TConfigSchema } from "../Mutes/types";
import { Configs } from "../../data/Configs";
import Timeout = NodeJS.Timeout;

View file

@ -1,13 +1,13 @@
import { PluginOptions } from "knub";
import { LocateUserPluginType, ConfigSchema } from "./types";
import { ConfigSchema, LocateUserPluginType } from "./types";
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { GuildVCAlerts } from "src/data/GuildVCAlerts";
import { outdatedAlertsLoop } from "./utils/outdatedLoop";
import { fillActiveAlertsList } from "./utils/fillAlertsList";
import { WhereCmd } from "./commands/WhereCmd";
import { FollowCmd } from "./commands/FollowCmd";
import { ListFollowCmd, DeleteFollowCmd } from "./commands/ListFollowCmd";
import { ChannelJoinAlertsEvt, ChannelSwitchAlertsEvt, ChannelLeaveAlertsEvt } from "./events/SendAlertsEvts";
import { DeleteFollowCmd, ListFollowCmd } from "./commands/ListFollowCmd";
import { ChannelJoinAlertsEvt, ChannelLeaveAlertsEvt, ChannelSwitchAlertsEvt } from "./events/SendAlertsEvts";
import { GuildBanRemoveAlertsEvt } from "./events/BanRemoveAlertsEvt";
const defaultOptions: PluginOptions<LocateUserPluginType> = {
@ -40,9 +40,9 @@ export const LocateUserPlugin = zeppelinPlugin<LocateUserPluginType>()("locate_u
// prettier-ignore
events: [
ChannelJoinAlertsEvt,
ChannelSwitchAlertsEvt,
ChannelLeaveAlertsEvt,
ChannelJoinAlertsEvt,
ChannelSwitchAlertsEvt,
ChannelLeaveAlertsEvt,
GuildBanRemoveAlertsEvt
],

View file

@ -1,7 +1,7 @@
import { locateUserCommand } from "../types";
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sorter, createChunkedMessage } from "src/utils";
import { createChunkedMessage, sorter } from "src/utils";
export const ListFollowCmd = locateUserCommand({
trigger: ["follows", "fs"],

View file

@ -1,6 +1,6 @@
import { locateUserEvent } from "../types";
import { sendAlerts } from "../utils/sendAlerts";
import { VoiceChannel, TextableChannel } from "eris";
import { TextableChannel, VoiceChannel } from "eris";
export const ChannelJoinAlertsEvt = locateUserEvent({
event: "voiceChannelJoin",

View file

@ -9,7 +9,7 @@ export async function moveMember(
target: Member,
errorChannel: TextableChannel,
) {
const modMember: Member = await this.bot.getRESTGuildMember(pluginData.guild.id, toMoveID);
const modMember: Member = await pluginData.client.getRESTGuildMember(pluginData.guild.id, toMoveID);
if (modMember.voiceState.channelID != null) {
try {
await modMember.edit({

View file

@ -12,6 +12,6 @@ export async function outdatedAlertsLoop(pluginData) {
}
if (!pluginData.state.unloaded) {
pluginData.state.outdatedAlertsTimeout = setTimeout(() => this.outdatedAlertsLoop(pluginData), ALERT_LOOP_TIME);
pluginData.state.outdatedAlertsTimeout = setTimeout(() => outdatedAlertsLoop(pluginData), ALERT_LOOP_TIME);
}
}

View file

@ -12,7 +12,7 @@ export async function sendAlerts(pluginData: PluginData<LocateUserPluginType>, u
triggeredAlerts.forEach(alert => {
const prepend = `<@!${alert.requestor_id}>, an alert requested by you has triggered!\nReminder: \`${alert.body}\`\n`;
const txtChannel = pluginData.client.getChannel(alert.channel_id) as TextableChannel;
sendWhere.call(this, pluginData.guild, member, txtChannel, prepend);
sendWhere(pluginData, member, txtChannel, prepend);
if (alert.active) {
moveMember(pluginData, alert.requestor_id, member, txtChannel);
}

View file

@ -1,9 +1,17 @@
import { Guild, Member, TextableChannel, VoiceChannel } from "eris";
import { Member, TextableChannel, VoiceChannel } from "eris";
import { getInviteLink } from "knub/dist/helpers";
import { createOrReuseInvite } from "./createOrReuseInvite";
import { PluginData } from "knub";
import { LocateUserPluginType } from "../types";
import { sendErrorMessage } from "../../../pluginUtils";
export async function sendWhere(guild: Guild, member: Member, channel: TextableChannel, prepend: string) {
const voice = guild.channels.get(member.voiceState.channelID) as VoiceChannel;
export async function sendWhere(
pluginData: PluginData<LocateUserPluginType>,
member: Member,
channel: TextableChannel,
prepend: string,
) {
const voice = pluginData.guild.channels.get(member.voiceState.channelID) as VoiceChannel;
if (voice == null) {
channel.createMessage(prepend + "That user is not in a channel");
@ -12,7 +20,7 @@ export async function sendWhere(guild: Guild, member: Member, channel: TextableC
try {
invite = await createOrReuseInvite(voice);
} catch (e) {
this.sendErrorMessage(channel, "Cannot create an invite to that channel!");
sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!");
return;
}
channel.createMessage(

View file

@ -2,7 +2,7 @@ import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { ConfigSchema, MessageSaverPluginType } from "./types";
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { PluginOptions } from "knub";
import { MessageCreateEvt, MessageUpdateEvt, MessageDeleteEvt, MessageDeleteBulkEvt } from "./events/SaveMessagesEvts";
import { MessageCreateEvt, MessageDeleteBulkEvt, MessageDeleteEvt, MessageUpdateEvt } from "./events/SaveMessagesEvts";
import { SaveMessagesToDBCmd } from "./commands/SaveMessagesToDB";
import { SavePinsToDBCmd } from "./commands/SavePinsToDB";

View file

@ -1,7 +1,6 @@
import { messageSaverCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { saveMessagesToDB } from "../saveMessagesToDB";
import { TextChannel } from "eris";
import { sendSuccessMessage } from "src/pluginUtils";
export const SaveMessagesToDBCmd = messageSaverCmd({

View file

@ -1,6 +1,6 @@
import { MessageSaverPluginType } from "./types";
import { PluginData } from "knub";
import { TextChannel, Message } from "eris";
import { Message, TextChannel } from "eris";
export async function saveMessagesToDB(
pluginData: PluginData<MessageSaverPluginType>,

View file

@ -1,6 +1,5 @@
import { command } from "knub";
import { MutesPluginType } from "../types";
import { User } from "eris";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { commandTypeHelpers as ct } from "../../../commandTypes";

View file

@ -1,6 +1,5 @@
import { command } from "knub";
import { MutesPluginType } from "../types";
import { User } from "eris";
import { sendSuccessMessage } from "../../../pluginUtils";
import { resolveMember } from "../../../utils";

View file

@ -2,14 +2,7 @@ import { PluginData } from "knub";
import { MuteOptions, MutesPluginType } from "../types";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import humanizeDuration from "humanize-duration";
import {
notifyUser,
resolveMember,
resolveUser,
stripObjectToScalars,
ucfirst,
UserNotificationResult,
} from "../../../utils";
import { notifyUser, resolveUser, stripObjectToScalars, ucfirst, UserNotificationResult } from "../../../utils";
import { renderTemplate } from "../../../templateFormatter";
import { TextChannel, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin";

View file

@ -8,8 +8,8 @@ import { GuildLogs } from "../../data/GuildLogs";
import { GuildCases } from "../../data/GuildCases";
import { GuildArchives } from "../../data/GuildArchives";
import { GuildMutes } from "../../data/GuildMutes";
import Timeout = NodeJS.Timeout;
import { CaseArgs } from "../Cases/types";
import Timeout = NodeJS.Timeout;
export const ConfigSchema = t.type({
mute_role: tNullable(t.string),

View file

@ -1,5 +1,5 @@
import { PluginOptions } from "knub";
import { NameHistoryPluginType, ConfigSchema } from "./types";
import { ConfigSchema, NameHistoryPluginType } from "./types";
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { GuildNicknameHistory } from "src/data/GuildNicknameHistory";
import { UsernameHistory } from "src/data/UsernameHistory";

View file

@ -1,6 +1,6 @@
import { nameHistoryCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { disableCodeBlocks, createChunkedMessage } from "knub/dist/helpers";
import { createChunkedMessage, disableCodeBlocks } from "knub/dist/helpers";
import { NICKNAME_RETENTION_PERIOD } from "src/data/cleanup/nicknames";
import { DAYS } from "src/utils";
import { MAX_NICKNAME_ENTRIES_PER_USER } from "src/data/GuildNicknameHistory";

View file

@ -1,6 +1,6 @@
import { PluginOptions } from "knub";
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { PersistPluginType, ConfigSchema } from "./types";
import { ConfigSchema, PersistPluginType } from "./types";
import { GuildPersistedData } from "src/data/GuildPersistedData";
import { GuildLogs } from "src/data/GuildLogs";
import { StoreDataEvt } from "./events/StoreDataEvt";

View file

@ -1,10 +1,10 @@
import { PluginOptions } from "knub";
import { PingableRolesPluginType, ConfigSchema } from "./types";
import { ConfigSchema, PingableRolesPluginType } from "./types";
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { GuildPingableRoles } from "src/data/GuildPingableRoles";
import { PingableRoleEnableCmd } from "./commands/PingableRoleEnableCmd";
import { PingableRoleDisableCmd } from "./commands/PingableRoleDisableCmd";
import { TypingEnablePingableEvt, MessageCreateDisablePingableEvt } from "./events/ChangePingableEvts";
import { MessageCreateDisablePingableEvt, TypingEnablePingableEvt } from "./events/ChangePingableEvts";
const defaultOptions: PluginOptions<PingableRolesPluginType> = {
config: {

View file

@ -1,5 +1,5 @@
import * as t from "io-ts";
import { BasePluginType, eventListener, command } from "knub";
import { BasePluginType, command, eventListener } from "knub";
import { GuildPingableRoles } from "src/data/GuildPingableRoles";
import { PingableRole } from "src/data/entities/PingableRole";

View file

@ -45,7 +45,8 @@ export const RemindCmd = remindersCommand({
return;
}
const reminderBody = args.reminder || `https://discord.com/channels/${this.guildId}/${msg.channel.id}/${msg.id}`;
const reminderBody =
args.reminder || `https://discord.com/channels/${pluginData.guild.id}/${msg.channel.id}/${msg.id}`;
await pluginData.state.reminders.add(
msg.author.id,
msg.channel.id,

View file

@ -1,6 +1,6 @@
import { remindersCommand } from "../types";
import { sendErrorMessage } from "src/pluginUtils";
import { sorter, createChunkedMessage } from "src/utils";
import { createChunkedMessage, sorter } from "src/utils";
import moment from "moment-timezone";
import humanizeDuration from "humanize-duration";

View file

@ -21,12 +21,12 @@ export const ContextCmd = utilityCmd({
return;
}
const previousMessage = (await this.bot.getMessages(args.channel.id, 1, args.messageId))[0];
const previousMessage = (await pluginData.client.getMessages(args.channel.id, 1, args.messageId))[0];
if (!previousMessage) {
sendErrorMessage(pluginData, msg.channel, "Message context not found");
return;
}
msg.channel.createMessage(messageLink(this.guildId, previousMessage.channel.id, previousMessage.id));
msg.channel.createMessage(messageLink(pluginData.guild.id, previousMessage.channel.id, previousMessage.id));
},
});

View file

@ -18,7 +18,7 @@ export const HelpCmd = utilityCmd({
const searchStr = args.command.toLowerCase();
const matchingCommands: Array<{
plugin: LoadedPlugin;
plugin: LoadedPlugin<any>;
command: PluginCommandDefinition;
}> = [];
@ -62,12 +62,10 @@ export const HelpCmd = utilityCmd({
.toLowerCase()
.replace(/\s/g, "-");
const pluginName = plugin.blueprint?.name || plugin.class?.pluginName;
let snippet = `**${prefix}${trigger}**`;
if (description) snippet += `\n${description}`;
if (usage) snippet += `\nBasic usage: \`${usage}\``;
snippet += `\n<https://zeppelin.gg/docs/plugins/${pluginName}/usage#command-${commandSlug}>`;
snippet += `\n<https://zeppelin.gg/docs/plugins/${plugin.blueprint.name}/usage#command-${commandSlug}>`;
return snippet;
});

View file

@ -1,6 +1,6 @@
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { PluginOptions } from "knub";
import { WelcomeMessagePluginType, ConfigSchema } from "./types";
import { ConfigSchema, WelcomeMessagePluginType } from "./types";
import { GuildLogs } from "src/data/GuildLogs";
import { SendWelcomeMessageEvt } from "./events/SendWelcomeMessageEvt";

View file

@ -1,6 +1,6 @@
import { welcomeEvent } from "../types";
import { renderTemplate } from "src/templateFormatter";
import { stripObjectToScalars, createChunkedMessage } from "src/utils";
import { createChunkedMessage, stripObjectToScalars } from "src/utils";
import { LogType } from "src/data/LogType";
import { TextChannel } from "eris";

View file

@ -1,7 +1,3 @@
import { ZeppelinPluginClass } from "./ZeppelinPluginClass";
import { ZeppelinPluginBlueprint } from "./ZeppelinPluginBlueprint";
// prettier-ignore
export type ZeppelinPlugin =
| typeof ZeppelinPluginClass
| ZeppelinPluginBlueprint<any>;
export type ZeppelinPlugin = ZeppelinPluginBlueprint<any>;

View file

@ -1,6 +1,6 @@
import { BasePluginType, plugin, PluginBlueprint } from "knub";
import * as t from "io-ts";
import { pluginConfigPreprocessor } from "../pluginUtils";
import { getPluginConfigPreprocessor } from "../pluginUtils";
export interface ZeppelinPluginBlueprint<TPluginType extends BasePluginType = BasePluginType>
extends PluginBlueprint<TPluginType> {
@ -23,7 +23,7 @@ export function zeppelinPlugin<TPluginType extends BasePluginType>(): <
export function zeppelinPlugin(...args) {
if (args.length) {
const blueprint: ZeppelinPluginBlueprint = plugin(...(args as Parameters<typeof plugin>));
blueprint.configPreprocessor = pluginConfigPreprocessor.bind(blueprint);
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint);
return blueprint;
} else {
return zeppelinPlugin;

View file

@ -1,16 +0,0 @@
import { BasePluginType, PluginClass, PluginOptions } from "knub";
import * as t from "io-ts";
import { TZeppelinKnub, ZeppelinPluginInfo } from "../types";
import { pluginConfigPreprocessor } from "../pluginUtils";
export class ZeppelinPluginClass<TPluginType extends BasePluginType = BasePluginType> extends PluginClass<TPluginType> {
public static pluginInfo: ZeppelinPluginInfo;
public static showInDocs: boolean = true;
public static configSchema: t.TypeC<any>;
protected readonly knub: TZeppelinKnub;
public static configPreprocessor(options: PluginOptions<any>) {
return pluginConfigPreprocessor.bind(this)(options);
}
}