Auto-generate plugin docs (WIP)

This commit is contained in:
Dragory 2019-08-22 01:22:26 +03:00
parent 6bdb05e678
commit ee6d622941
44 changed files with 599 additions and 150 deletions

70
src/api/docs.ts Normal file
View file

@ -0,0 +1,70 @@
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";
const commandManager = new CommandManager();
export function initDocs(app: express.Express) {
const docsPlugins = availablePlugins.filter(pluginClass => pluginClass.showInDocs);
app.get("/docs/plugins", (req: express.Request, res: express.Response) => {
res.json(
docsPlugins.map(pluginClass => {
const thinInfo = pluginClass.pluginInfo ? { prettyName: pluginClass.pluginInfo.prettyName } : {};
return {
name: pluginClass.pluginName,
info: thinInfo,
};
}),
);
});
app.get("/docs/plugins/:pluginName", (req: express.Request, res: express.Response) => {
const pluginClass = docsPlugins.find(obj => obj.pluginName === req.params.pluginName);
if (!pluginClass) {
return notFound(res);
}
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) {
arr.push(
...propCommands.map(cmd => {
const trigger = typeof cmd.command === "string" ? cmd.command : cmd.command.source;
const parameters = cmd.parameters
? typeof cmd.parameters === "string"
? commandManager.parseParameterString(cmd.parameters)
: cmd.parameters
: [];
const config: ICommandConfig = cmd.options || {};
if (config.overloads) {
config.overloads = config.overloads.map(overload => {
return typeof overload === "string" ? commandManager.parseParameterString(overload) : overload;
});
}
return {
trigger,
parameters,
config,
};
}),
);
}
return arr;
}, []);
const options = (pluginClass as typeof ZeppelinPlugin).getStaticDefaultOptions();
res.json({
name: pluginClass.pluginName,
info: pluginClass.pluginInfo || {},
options,
commands,
});
});
}

View file

@ -4,6 +4,7 @@ import cors from "cors";
import { initAuth } from "./auth";
import { initGuildsAPI } from "./guilds";
import { initArchives } from "./archives";
import { initDocs } from "./docs";
import { connect } from "../data/db";
import path from "path";
import { TokenError } from "passport-oauth2";
@ -12,15 +13,13 @@ import { PluginError } from "knub";
require("dotenv").config({ path: path.resolve(__dirname, "..", "..", "api.env") });
function errorHandler(err) {
// tslint:disable:no-console
console.error(err.stack || err);
console.error(err.stack || err); // tslint:disable-line:no-console
process.exit(1);
// tslint:enable:no-console
}
process.on("unhandledRejection", errorHandler);
console.log("Connecting to database...");
console.log("Connecting to database..."); // tslint:disable-line
connect().then(() => {
const app = express();
@ -34,6 +33,7 @@ connect().then(() => {
initAuth(app);
initGuildsAPI(app);
initArchives(app);
initDocs(app);
// Default route
app.get("/", (req, res) => {
@ -45,7 +45,7 @@ connect().then(() => {
if (err instanceof TokenError) {
clientError(res, "Invalid code");
} else {
console.error(err);
console.error(err); // tslint:disable-line
error(res, "Server error", err.status || 500);
}
});
@ -56,5 +56,6 @@ connect().then(() => {
});
const port = process.env.PORT || 3000;
// tslint:disable-next-line
app.listen(port, () => console.log(`API server listening on port ${port}`));
});

View file

@ -21,7 +21,7 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<TConfigSchema> {
private onMessageCreateFn;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_manage: false,

View file

@ -358,7 +358,7 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema> {
return config;
}
protected static getStaticDefaultOptions() {
public static getStaticDefaultOptions() {
return {
rules: [],
};

View file

@ -27,7 +27,7 @@ export class BotControlPlugin extends GlobalZeppelinPlugin<TConfigSchema> {
protected archives: GuildArchives;
protected static getStaticDefaultOptions() {
public static getStaticDefaultOptions() {
return {
config: {
can_use: false,

View file

@ -51,7 +51,7 @@ export class CasesPlugin extends ZeppelinPlugin<TConfigSchema> {
protected archives: GuildArchives;
protected logs: GuildLogs;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
log_automatic_actions: true,

View file

@ -46,7 +46,7 @@ export class CensorPlugin extends ZeppelinPlugin<TConfigSchema> {
private onMessageCreateFn;
private onMessageUpdateFn;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
filter_zalgo: false,

View file

@ -30,7 +30,7 @@ export class CompanionChannelPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "companion_channels";
protected static configSchema = ConfigSchema;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
entries: {},

View file

@ -70,12 +70,13 @@ class ActionError extends Error {}
export class CustomEventsPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "custom_events";
public static showInDocs = false;
public static dependencies = ["cases"];
protected static configSchema = ConfigSchema;
private clearTriggers: () => void;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
events: {},
@ -162,7 +163,7 @@ export class CustomEventsPlugin extends ZeppelinPlugin<TConfigSchema> {
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
await casesPlugin.createCase({
userId: targetId,
modId: modId,
modId,
type: CaseTypes[action.case_type],
reason: `__[${event.name}]__ ${reason}`,
});

View file

@ -21,7 +21,7 @@ export class GlobalZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extend
* we need a static version of getDefaultOptions(). This static version is then,
* by turn, called from getDefaultOptions() so everything still works as expected.
*/
protected static getStaticDefaultOptions() {
public static getStaticDefaultOptions() {
// Implemented by plugin
return {};
}

View file

@ -4,6 +4,7 @@ import { MINUTES } from "../utils";
export class GuildInfoSaverPlugin extends ZeppelinPlugin {
public static pluginName = "guild_info_saver";
public static showInDocs = false;
protected allowedGuilds: AllowedGuilds;
private updateInterval;

View file

@ -23,7 +23,7 @@ export class LocatePlugin extends ZeppelinPlugin<TConfigSchema> {
private outdatedAlertsTimeout;
private usersWithAlerts: string[] = [];
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_where: false,

View file

@ -70,7 +70,7 @@ export class LogsPlugin extends ZeppelinPlugin<TConfigSchema> {
private excludedUserProps = ["user", "member", "mod"];
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
channels: {},

View file

@ -12,11 +12,12 @@ type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export class MessageSaverPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "message_saver";
public static showInDocs = false;
protected static configSchema = ConfigSchema;
protected savedMessages: GuildSavedMessages;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_manage: false,

View file

@ -16,6 +16,8 @@ import {
stripObjectToScalars,
successMessage,
tNullable,
trimEmptyStartEndLines,
trimIndents,
trimLines,
ucfirst,
UnknownUser,
@ -68,11 +70,58 @@ interface IIgnoredEvent {
userId: string;
}
export type WarnResult =
| {
status: "failed";
error: string;
}
| {
status: "success";
case: Case;
notifyResult: INotifyUserResult;
};
export type KickResult =
| {
status: "failed";
error: string;
}
| {
status: "success";
case: Case;
notifyResult: INotifyUserResult;
};
export type BanResult =
| {
status: "failed";
error: string;
}
| {
status: "success";
case: Case;
notifyResult: INotifyUserResult;
};
type WarnMemberNotifyRetryCallback = () => boolean | Promise<boolean>;
export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "mod_actions";
public static dependencies = ["cases", "mutes"];
protected static configSchema = ConfigSchema;
public static pluginInfo = {
prettyName: "Mod actions",
description: trimIndents(
trimEmptyStartEndLines(`
Testing **things**
Multiline haHAA
`),
6,
),
};
protected mutes: GuildMutes;
protected cases: GuildCases;
protected serverLogs: GuildLogs;
@ -87,7 +136,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
this.ignoredEvents = [];
}
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
dm_on_warn: true,
@ -439,6 +488,10 @@ 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",
},
})
@d.permission("can_note")
async updateCmd(msg: Message, args: { caseNumber?: number; note?: string }) {
@ -478,7 +531,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
msg.channel.createMessage(successMessage(`Case \`#${theCase.case_number}\` updated`));
}
@d.command("note", "<user:string> <note:string$>")
@d.command("note", "<user:string> <note:string$>", {
info: {
description: "Add a note to the specified user",
},
})
@d.permission("can_note")
async noteCmd(msg: Message, args: { user: string; note: string }) {
const user = await this.resolveUser(args.user);
@ -500,6 +557,9 @@ 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",
},
})
@d.permission("can_warn")
async warnCmd(msg: Message, args: { user: string; reason: string; mod?: Member }) {
@ -702,6 +762,9 @@ 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",
},
})
@d.permission("can_mute")
async muteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod: Member }) {
@ -740,6 +803,9 @@ 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",
},
})
@d.permission("can_mute")
async forcemuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod: Member }) {
@ -815,6 +881,9 @@ 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",
},
})
@d.permission("can_mute")
async unmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) {
@ -857,6 +926,9 @@ 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",
},
})
@d.permission("can_mute")
async forceunmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) {
@ -883,6 +955,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.command("kick", "<user:string> [reason:string$]", {
options: [{ name: "mod", type: "member" }],
info: {
description: "Kick the specified member",
},
})
@d.permission("can_kick")
async kickCmd(msg, args: { user: string; reason: string; mod: Member }) {
@ -941,6 +1016,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.command("ban", "<user:string> [reason:string$]", {
options: [{ name: "mod", type: "member" }],
info: {
description: "Ban the specified member",
},
})
@d.permission("can_ban")
async banCmd(msg, args: { user: string; reason?: string; mod?: Member }) {
@ -977,62 +1055,32 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
mod = args.mod;
}
const config = this.getConfig();
const reason = this.formatReasonWithAttachments(args.reason, msg.attachments);
const banResult = await this.banUserId(memberToBan.id, reason, {
modId: mod.id,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
});
// Attempt to message the user *before* banning them, as doing it after may not be possible
let userMessageResult: INotifyUserResult = { status: NotifyUserStatus.Ignored };
if (reason) {
const banMessage = await renderTemplate(config.ban_message, {
guildName: this.guild.name,
reason,
});
userMessageResult = await notifyUser(this.bot, this.guild, memberToBan.user, banMessage, {
useDM: config.dm_on_ban,
useChannel: config.message_on_ban,
channelId: config.message_channel,
});
}
// (Try to) ban the user
this.serverLogs.ignoreLog(LogType.MEMBER_BAN, memberToBan.id);
this.ignoreEvent(IgnoredEventType.Ban, memberToBan.id);
try {
await memberToBan.ban(1);
} catch (e) {
msg.channel.create(errorMessage("Failed to ban the user"));
if (banResult.status === "failed") {
msg.channel.createMessage(errorMessage(`Failed to ban member`));
return;
}
// Create a case for this action
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
const createdCase = await casesPlugin.createCase({
userId: memberToBan.id,
modId: mod.id,
type: CaseTypes.Ban,
reason,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
noteDetails: userMessageResult.status !== NotifyUserStatus.Ignored ? [ucfirst(userMessageResult.text)] : [],
});
// Confirm the action to the moderator
let response = `Banned **${memberToBan.user.username}#${memberToBan.user.discriminator}** (Case #${
createdCase.case_number
banResult.case.case_number
})`;
if (userMessageResult.text) response += ` (${userMessageResult.text})`;
if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`;
msg.channel.createMessage(successMessage(response));
// Log the action
this.serverLogs.log(LogType.MEMBER_BAN, {
mod: stripObjectToScalars(mod.user),
user: stripObjectToScalars(memberToBan.user),
});
}
@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.',
},
})
@d.permission("can_ban")
async softbanCmd(msg, args: { user: string; reason: string; mod?: Member }) {
@ -1119,6 +1167,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.command("unban", "<user:string> [reason:string$]", {
options: [{ name: "mod", type: "member" }],
info: {
description: "Unban the specified member",
},
})
@d.permission("can_ban")
async unbanCmd(msg: Message, args: { user: string; reason: string; mod: Member }) {
@ -1170,6 +1221,9 @@ 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",
},
})
@d.permission("can_ban")
async forcebanCmd(msg: Message, args: { user: string; reason?: string; mod?: Member }) {
@ -1233,7 +1287,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
});
}
@d.command("massban", "<userIds:string...>")
@d.command("massban", "<userIds:string...>", {
info: {
description: "Mass-ban a list of user IDs",
},
})
@d.permission("can_massban")
async massbanCmd(msg: Message, args: { userIds: string[] }) {
// Limit to 100 users at once (arbitrary?)
@ -1317,6 +1375,9 @@ 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",
},
})
@d.permission("can_addcase")
async addcaseCmd(msg: Message, args: { type: string; user: string; reason?: string; mod?: Member }) {
@ -1377,15 +1438,13 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
});
}
/**
* Display a case or list of cases
* If the argument passed is a case id, display that case
* If the argument passed is a user id, show all cases on that user
*/
@d.command("case", "<caseNumber:number>")
@d.command("case", "<caseNumber:number>", {
info: {
description: "Show information about a specific case",
},
})
@d.permission("can_view")
async showCaseCmd(msg: Message, args: { caseNumber: number }) {
// Assume case id
const theCase = await this.cases.findByCaseNumber(args.caseNumber);
if (!theCase) {
@ -1411,6 +1470,9 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
shortcut: "h",
},
],
info: {
description: "Show a list of cases the specified user has",
},
})
@d.permission("can_view")
async userCasesCmd(msg: Message, args: { user: string; expand?: boolean; hidden?: boolean }) {
@ -1475,6 +1537,9 @@ 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",
},
})
@d.permission("can_view")
async recentCasesCmd(msg: Message, args: { mod?: Member }) {
@ -1500,7 +1565,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
}
}
@d.command("hidecase", "<caseNum:number>")
@d.command("hidecase", "<caseNum:number>", {
info: {
description: "Hide the specified case so it doesn't appear in !cases or !info",
},
})
@d.permission("can_hidecase")
async hideCaseCmd(msg: Message, args: { caseNum: number }) {
const theCase = await this.cases.findByCaseNumber(args.caseNum);
@ -1515,7 +1584,11 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
);
}
@d.command("unhidecase", "<caseNum:number>")
@d.command("unhidecase", "<caseNum:number>", {
info: {
description: "Un-hide the specified case, making it appear in !cases and !info again",
},
})
@d.permission("can_hidecase")
async unhideCaseCmd(msg: Message, args: { caseNum: number }) {
const theCase = await this.cases.findByCaseNumber(args.caseNum);

View file

@ -71,7 +71,7 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
protected serverLogs: GuildLogs;
private muteClearIntervalId: NodeJS.Timer;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
mute_role: null,

View file

@ -13,12 +13,13 @@ type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export class NameHistoryPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "name_history";
public static showInDocs = false;
protected static configSchema = ConfigSchema;
protected nicknameHistory: GuildNicknameHistory;
protected usernameHistory: UsernameHistory;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_view: false,

View file

@ -22,7 +22,7 @@ export class PersistPlugin extends ZeppelinPlugin<TConfigSchema> {
protected persistedData: GuildPersistedData;
protected logs: GuildLogs;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
persisted_roles: [],

View file

@ -21,7 +21,7 @@ export class PingableRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
protected cache: Map<string, PingableRole[]>;
protected timeouts: Map<string, any>;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_manage: false,

View file

@ -58,7 +58,7 @@ export class PostPlugin extends ZeppelinPlugin<TConfigSchema> {
clearTimeout(this.scheduledPostLoopTimeout);
}
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_post: false,

View file

@ -55,7 +55,7 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
private autoRefreshTimeout;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
auto_refresh_interval: MIN_AUTO_REFRESH,

View file

@ -32,7 +32,7 @@ export class RemindersPlugin extends ZeppelinPlugin<TConfigSchema> {
private postRemindersTimeout;
private unloaded = false;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_use: false,

View file

@ -14,11 +14,12 @@ type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export class SelfGrantableRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "self_grantable_roles";
public static showInDocs = false;
protected static configSchema = ConfigSchema;
protected selfGrantableRoles: GuildSelfGrantableRoles;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_manage: false,

View file

@ -42,7 +42,7 @@ export class SlowmodePlugin extends ZeppelinPlugin<TConfigSchema> {
private onMessageCreateFn;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
use_native_slowmode: true,

View file

@ -96,7 +96,7 @@ export class SpamPlugin extends ZeppelinPlugin<TConfigSchema> {
private expiryInterval;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
max_censor: null,

View file

@ -25,6 +25,7 @@ type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
public static pluginName = "starboard";
public static showInDocs = false;
protected static configSchema = ConfigSchema;
protected starboards: GuildStarboards;
@ -32,7 +33,7 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
private onMessageDeleteFn;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_manage: false,

View file

@ -34,7 +34,7 @@ export class TagsPlugin extends ZeppelinPlugin<TConfigSchema> {
protected tagFunctions;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
prefix: "!!",
@ -117,7 +117,7 @@ export class TagsPlugin extends ZeppelinPlugin<TConfigSchema> {
}
const prefix = this.getConfigForMsg(msg).prefix;
const tagNames = tags.map(t => t.tag).sort();
const tagNames = tags.map(tag => tag.tag).sort();
msg.channel.createMessage(`
Available tags (use with ${prefix}tag): \`\`\`${tagNames.join(", ")}\`\`\`
`);

View file

@ -92,7 +92,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
protected lastFullMemberRefresh = 0;
protected lastReload;
protected static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
public static getStaticDefaultOptions(): IPluginOptions<TConfigSchema> {
return {
config: {
can_roles: false,

View file

@ -22,12 +22,21 @@ import { mergeConfig } from "knub/dist/configUtils";
const SLOW_RESOLVE_THRESHOLD = 1500;
export interface PluginInfo {
name: string;
prettyName: string;
description?: string;
}
export interface CommandInfo {
description?: string;
basicUsage?: string;
parameterDescriptions?: {
[key: string]: string;
};
}
export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plugin<TConfig> {
public static pluginInfo: PluginInfo;
public static showInDocs: boolean = true;
protected static configSchema: t.TypeC<any>;
public static dependencies = [];
@ -51,7 +60,7 @@ export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plug
* we need a static version of getDefaultOptions(). This static version is then,
* by turn, called from getDefaultOptions() so everything still works as expected.
*/
protected static getStaticDefaultOptions() {
public static getStaticDefaultOptions() {
// Implemented by plugin
return {};
}

View file

@ -244,6 +244,37 @@ export function asSingleLine(str: string) {
return trimLines(str).replace(/\n/g, " ");
}
export function trimEmptyStartEndLines(str: string) {
const lines = str.split("\n");
let emptyLinesAtStart = 0;
let emptyLinesAtEnd = 0;
for (const line of lines) {
if (line.match(/^\s*$/)) {
emptyLinesAtStart++;
} else {
break;
}
}
for (let i = lines.length - 1; i > 0; i--) {
if (lines[i].match(/^\s*$/)) {
emptyLinesAtEnd++;
} else {
break;
}
}
return lines.slice(emptyLinesAtStart, emptyLinesAtEnd ? -1 * emptyLinesAtEnd : null).join("\n");
}
export function trimIndents(str: string, indentLength: number) {
return str
.split("\n")
.map(line => line.slice(indentLength))
.join("\n");
}
export const emptyEmbedValue = "\u200b";
export const embedPadding = "\n" + emptyEmbedValue;