mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Update to Knub 24. Update Node typings to fix error with [util.inspect.custom] property.
This commit is contained in:
parent
1681a45069
commit
4d7ab10fcf
12 changed files with 183 additions and 122 deletions
|
@ -11,7 +11,7 @@ export class PluginRuntimeError {
|
|||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
[util.inspect.custom](depth, options) {
|
||||
[util.inspect.custom](depth?, options?) {
|
||||
return `PRE [${this.pluginName}] [${this.guildId}] ${this.message}`;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,9 @@ import express from "express";
|
|||
import { availablePlugins } from "../plugins/availablePlugins";
|
||||
import { ZeppelinPlugin } from "../plugins/ZeppelinPlugin";
|
||||
import { notFound } from "./responses";
|
||||
import { CommandManager, ICommandConfig } from "knub/dist/CommandManager";
|
||||
import { dropPropertiesByName, indentLines } from "../utils";
|
||||
|
||||
const commandManager = new CommandManager();
|
||||
import { IPluginCommandConfig, Plugin, pluginUtils } from "knub";
|
||||
import { parseParameters } from "knub-command-manager";
|
||||
|
||||
function formatConfigSchema(schema) {
|
||||
if (schema._tag === "InterfaceType" || schema._tag === "PartialType") {
|
||||
|
@ -79,20 +78,20 @@ export function initDocs(app: express.Express) {
|
|||
const props = Reflect.ownKeys(pluginClass.prototype);
|
||||
const commands = props.reduce((arr, prop) => {
|
||||
if (typeof prop !== "string") return arr;
|
||||
const propCommands = Reflect.getMetadata("commands", pluginClass.prototype, prop);
|
||||
if (propCommands) {
|
||||
const decoratorCommands = pluginUtils.getPluginDecoratorCommands(pluginClass as typeof Plugin);
|
||||
if (decoratorCommands) {
|
||||
arr.push(
|
||||
...propCommands.map(cmd => {
|
||||
const trigger = typeof cmd.command === "string" ? cmd.command : cmd.command.source;
|
||||
...decoratorCommands.map(cmd => {
|
||||
const trigger = typeof cmd.trigger === "string" ? cmd.trigger : cmd.trigger.source;
|
||||
const parameters = cmd.parameters
|
||||
? typeof cmd.parameters === "string"
|
||||
? commandManager.parseParameterString(cmd.parameters)
|
||||
? parseParameters(cmd.parameters)
|
||||
: cmd.parameters
|
||||
: [];
|
||||
const config: ICommandConfig = cmd.options || {};
|
||||
const config: IPluginCommandConfig = cmd.config || {};
|
||||
if (config.overloads) {
|
||||
config.overloads = config.overloads.map(overload => {
|
||||
return typeof overload === "string" ? commandManager.parseParameterString(overload) : overload;
|
||||
return typeof overload === "string" ? parseParameters(overload) : overload;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,41 +6,42 @@ import {
|
|||
resolveUser,
|
||||
UnknownUser,
|
||||
} from "./utils";
|
||||
import { CommandArgumentTypeError } from "knub";
|
||||
import { Client, GuildChannel, Message } from "eris";
|
||||
import { TypeConversionError } from "knub-command-manager";
|
||||
import { ICommandContext } from "knub";
|
||||
|
||||
export const customArgumentTypes = {
|
||||
delay(value) {
|
||||
const result = convertDelayStringToMS(value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(`Could not convert ${value} to a delay`);
|
||||
throw new TypeConversionError(`Could not convert ${value} to a delay`);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedUser(value, msg, bot: Client) {
|
||||
const result = await resolveUser(bot, value);
|
||||
async resolvedUser(value, context: ICommandContext) {
|
||||
const result = await resolveUser(context.bot, value);
|
||||
if (result == null || result instanceof UnknownUser) {
|
||||
throw new CommandArgumentTypeError(`User \`${disableCodeBlocks(value)}\` was not found`);
|
||||
throw new TypeConversionError(`User \`${disableCodeBlocks(value)}\` was not found`);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedUserLoose(value, msg, bot: Client) {
|
||||
const result = await resolveUser(bot, value);
|
||||
async resolvedUserLoose(value, context: ICommandContext) {
|
||||
const result = await resolveUser(context.bot, value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(`Invalid user: \`${disableCodeBlocks(value)}\``);
|
||||
throw new TypeConversionError(`Invalid user: \`${disableCodeBlocks(value)}\``);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedMember(value, msg: Message, bot: Client) {
|
||||
if (!(msg.channel instanceof GuildChannel)) return null;
|
||||
async resolvedMember(value, context: ICommandContext) {
|
||||
if (!(context.message.channel instanceof GuildChannel)) return null;
|
||||
|
||||
const result = await resolveMember(bot, msg.channel.guild, value);
|
||||
const result = await resolveMember(context.bot, context.message.channel.guild, value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(
|
||||
throw new TypeConversionError(
|
||||
`Member \`${disableCodeBlocks(value)}\` was not found or they have left the server`,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { decorators as d, logger } from "knub";
|
||||
import { decorators as d, ICommandContext, logger } from "knub";
|
||||
import { GlobalZeppelinPlugin } from "./GlobalZeppelinPlugin";
|
||||
import { Attachment, GuildChannel, Message, TextChannel } from "eris";
|
||||
import { confirm, downloadFile, errorMessage, noop, SECONDS, trimLines } from "../utils";
|
||||
|
@ -57,8 +57,8 @@ export class ChannelArchiverPlugin extends ZeppelinPlugin {
|
|||
},
|
||||
],
|
||||
preFilters: [
|
||||
(msg, command, plugin: ChannelArchiverPlugin) => {
|
||||
return plugin.isOwner(msg.author.id);
|
||||
(command, context: ICommandContext) => {
|
||||
return (context.plugin as ChannelArchiverPlugin).isOwner(context.message.author.id);
|
||||
},
|
||||
],
|
||||
})
|
||||
|
|
|
@ -87,7 +87,7 @@ export class CustomEventsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
onLoad() {
|
||||
for (const [key, event] of Object.entries(this.getConfig().events)) {
|
||||
if (event.trigger.type === "command") {
|
||||
this.commands.add(
|
||||
this.addCommand(
|
||||
event.trigger.name,
|
||||
event.trigger.params,
|
||||
(msg, args) => {
|
||||
|
@ -95,8 +95,9 @@ export class CustomEventsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
this.runEvent(event, { msg, args }, { args, msg: strippedMsg });
|
||||
},
|
||||
{
|
||||
requiredPermission: `events.${key}.trigger.can_use`,
|
||||
locks: [],
|
||||
extra: {
|
||||
requiredPermission: `events.${key}.trigger.can_use`,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,8 +78,10 @@ export class LocatePlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("where", "<member:resolvedMember>", {
|
||||
info: {
|
||||
description: "Posts an instant invite to the voice channel that `<member>` is in",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Posts an instant invite to the voice channel that `<member>` is in",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_where")
|
||||
|
@ -90,8 +92,10 @@ export class LocatePlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("vcalert", "<member:resolvedMember> [duration:delay] [reminder:string$]", {
|
||||
aliases: ["vca"],
|
||||
info: {
|
||||
description: "Sets up an alert that notifies you any time `<member>` switches or joins voice channels",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Sets up an alert that notifies you any time `<member>` switches or joins voice channels",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_alert")
|
||||
|
|
|
@ -483,9 +483,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("update", "<caseNumber:number> [note:string$]", {
|
||||
overloads: ["[note:string$]"],
|
||||
info: {
|
||||
description:
|
||||
"Update the specified case (or, if case number is omitted, your latest case) by adding more notes/details to it",
|
||||
extra: {
|
||||
info: {
|
||||
description:
|
||||
"Update the specified case (or, if case number is omitted, your latest case) by adding more notes/details to it",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_note")
|
||||
|
@ -527,8 +529,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("note", "<user:string> <note:string$>", {
|
||||
info: {
|
||||
description: "Add a note to the specified user",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Add a note to the specified user",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_note")
|
||||
|
@ -552,8 +556,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("warn", "<user:string> <reason:string$>", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Send a warning to the specified user",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Send a warning to the specified user",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_warn")
|
||||
|
@ -757,8 +763,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
@d.command("mute", "<user:string> <time:delay> <reason:string$>", {
|
||||
overloads: ["<user:string> <time:delay>", "<user:string> [reason:string$]"],
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Mute the specified member",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Mute the specified member",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_mute")
|
||||
|
@ -798,8 +806,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
@d.command("forcemute", "<user:string> <time:delay> <reason:string$>", {
|
||||
overloads: ["<user:string> <time:delay>", "<user:string> [reason:string$]"],
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Force-mute the specified user, even if they're not on the server",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Force-mute the specified user, even if they're not on the server",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_mute")
|
||||
|
@ -876,8 +886,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
@d.command("unmute", "<user:string> <time:delay> <reason:string$>", {
|
||||
overloads: ["<user:string> <time:delay>", "<user:string> [reason:string$]"],
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Unmute the specified member",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Unmute the specified member",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_mute")
|
||||
|
@ -921,8 +933,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
@d.command("forceunmute", "<user:string> <time:delay> <reason:string$>", {
|
||||
overloads: ["<user:string> <time:delay>", "<user:string> [reason:string$]"],
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Force-unmute the specified user, even if they're not on the server",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Force-unmute the specified user, even if they're not on the server",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_mute")
|
||||
|
@ -950,8 +964,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("kick", "<user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Kick the specified member",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Kick the specified member",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_kick")
|
||||
|
@ -1011,8 +1027,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("ban", "<user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Ban the specified member",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Ban the specified member",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_ban")
|
||||
|
@ -1072,9 +1090,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("softban", "<user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description:
|
||||
'"Softban" the specified user by banning and immediately unbanning them. Effectively a kick with message deletions.',
|
||||
extra: {
|
||||
info: {
|
||||
description:
|
||||
'"Softban" the specified user by banning and immediately unbanning them. Effectively a kick with message deletions.',
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_ban")
|
||||
|
@ -1162,8 +1182,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("unban", "<user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Unban the specified member",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Unban the specified member",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_ban")
|
||||
|
@ -1216,8 +1238,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("forceban", "<user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Force-ban the specified user, even if they aren't on the server",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Force-ban the specified user, even if they aren't on the server",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_ban")
|
||||
|
@ -1283,8 +1307,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("massban", "<userIds:string...>", {
|
||||
info: {
|
||||
description: "Mass-ban a list of user IDs",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Mass-ban a list of user IDs",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_massban")
|
||||
|
@ -1370,8 +1396,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("addcase", "<type:string> <user:string> [reason:string$]", {
|
||||
options: [{ name: "mod", type: "member" }],
|
||||
info: {
|
||||
description: "Add an arbitrary case to the specified user without taking any action",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Add an arbitrary case to the specified user without taking any action",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_addcase")
|
||||
|
@ -1434,8 +1462,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("case", "<caseNumber:number>", {
|
||||
info: {
|
||||
description: "Show information about a specific case",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Show information about a specific case",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_view")
|
||||
|
@ -1465,8 +1495,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
shortcut: "h",
|
||||
},
|
||||
],
|
||||
info: {
|
||||
description: "Show a list of cases the specified user has",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Show a list of cases the specified user has",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_view")
|
||||
|
@ -1532,8 +1564,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
@d.command("cases", null, {
|
||||
options: [{ name: "mod", type: "Member" }],
|
||||
info: {
|
||||
description: "Show the most recent 5 cases by the specified --mod",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Show the most recent 5 cases by the specified --mod",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_view")
|
||||
|
@ -1561,8 +1595,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("hidecase", "<caseNum:number>", {
|
||||
info: {
|
||||
description: "Hide the specified case so it doesn't appear in !cases or !info",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Hide the specified case so it doesn't appear in !cases or !info",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_hidecase")
|
||||
|
@ -1580,8 +1616,10 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
}
|
||||
|
||||
@d.command("unhidecase", "<caseNum:number>", {
|
||||
info: {
|
||||
description: "Un-hide the specified case, making it appear in !cases and !info again",
|
||||
extra: {
|
||||
info: {
|
||||
description: "Un-hide the specified case, making it appear in !cases and !info again",
|
||||
},
|
||||
},
|
||||
})
|
||||
@d.permission("can_hidecase")
|
||||
|
|
|
@ -10,6 +10,7 @@ import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
|||
import { parseTemplate, renderTemplate, TemplateParseError } from "../templateFormatter";
|
||||
import { GuildArchives } from "../data/GuildArchives";
|
||||
import * as t from "io-ts";
|
||||
import { parseArguments } from "knub-command-manager";
|
||||
|
||||
const ConfigSchema = t.type({
|
||||
prefix: t.string,
|
||||
|
@ -233,7 +234,7 @@ export class TagsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
|
||||
// Substitute variables (matched with Knub's argument parser -> supports quotes etc.)
|
||||
const variableStr = msg.data.content.slice(prefix.length + tagName.length).trim();
|
||||
const tagArgs = this.commands.parseArguments(variableStr).map(v => v.value);
|
||||
const tagArgs = parseArguments(variableStr).map(v => v.value);
|
||||
|
||||
// Format the string
|
||||
try {
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
import { decorators as d, getCommandSignature, IPluginOptions, ICommandDefinition, waitForReaction } from "knub";
|
||||
import {
|
||||
decorators as d,
|
||||
getCommandSignature,
|
||||
ICommandContext,
|
||||
ICommandExtraData,
|
||||
IPluginOptions,
|
||||
waitForReaction,
|
||||
} from "knub";
|
||||
import {
|
||||
CategoryChannel,
|
||||
Channel,
|
||||
|
@ -45,6 +52,7 @@ import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
|||
import { getCurrentUptime } from "../uptime";
|
||||
import LCL from "last-commit-log";
|
||||
import * as t from "io-ts";
|
||||
import { ICommandDefinition } from "knub-command-manager";
|
||||
|
||||
const ConfigSchema = t.type({
|
||||
can_roles: t.boolean,
|
||||
|
@ -959,17 +967,18 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
helpCmd(msg: Message, args: { command: string }) {
|
||||
const searchStr = args.command.toLowerCase();
|
||||
|
||||
const matchingCommands: ICommandDefinition[] = [];
|
||||
const matchingCommands: Array<ICommandDefinition<ICommandContext, ICommandExtraData>> = [];
|
||||
|
||||
const guildData = this.knub.getGuildData(this.guildId);
|
||||
for (const plugin of guildData.loadedPlugins.values()) {
|
||||
if (!(plugin instanceof ZeppelinPlugin)) continue;
|
||||
|
||||
const commands = plugin.getRegisteredCommands();
|
||||
for (const command of commands) {
|
||||
const trigger = command.trigger.source.toLowerCase();
|
||||
if (trigger.startsWith(searchStr)) {
|
||||
matchingCommands.push(command);
|
||||
const registeredCommands = plugin.getRegisteredCommands();
|
||||
for (const registeredCommand of registeredCommands) {
|
||||
for (const trigger of registeredCommand.command.triggers) {
|
||||
if (trigger.source.startsWith(searchStr)) {
|
||||
matchingCommands.push(registeredCommand.command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -977,16 +986,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
const totalResults = matchingCommands.length;
|
||||
const limitedResults = matchingCommands.slice(0, 15);
|
||||
const signatures = limitedResults.map(command => {
|
||||
return (
|
||||
"`" +
|
||||
getCommandSignature(
|
||||
guildData.config.prefix,
|
||||
command.trigger.source,
|
||||
command.parameters,
|
||||
command.config.options,
|
||||
) +
|
||||
"`"
|
||||
);
|
||||
return "`" + getCommandSignature(command) + "`";
|
||||
});
|
||||
|
||||
if (totalResults === 0) {
|
||||
|
|
|
@ -184,13 +184,6 @@ export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plug
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended for cross-plugin functionality
|
||||
*/
|
||||
public getRegisteredCommands() {
|
||||
return this.commands.commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended for cross-plugin functionality
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue