Add !guild_reload to reload the current guild's config and plugins

This commit is contained in:
Dragory 2018-08-03 19:26:54 +03:00
parent 1b151fff24
commit 60c434999e

View file

@ -1,5 +1,5 @@
import { Plugin, decorators as d, reply } from "knub"; import { Plugin, decorators as d, reply } from "knub";
import { Channel, Embed, EmbedOptions, Message, TextChannel, User, VoiceChannel } from "eris"; import { Channel, EmbedOptions, Message, TextChannel, User, VoiceChannel } from "eris";
import { import {
embedPadding, embedPadding,
errorMessage, errorMessage,
@ -18,6 +18,8 @@ import { CaseType } from "../data/CaseType";
const MAX_SEARCH_RESULTS = 15; const MAX_SEARCH_RESULTS = 15;
const MAX_CLEAN_COUNT = 50; const MAX_CLEAN_COUNT = 50;
const activeReloads: Map<string, TextChannel> = new Map();
export class UtilityPlugin extends Plugin { export class UtilityPlugin extends Plugin {
protected logs: GuildLogs; protected logs: GuildLogs;
protected cases: GuildCases; protected cases: GuildCases;
@ -30,7 +32,8 @@ export class UtilityPlugin extends Plugin {
search: false, search: false,
clean: false, clean: false,
info: false, info: false,
server: true server: false,
reload_guild: false
}, },
overrides: [ overrides: [
{ {
@ -41,7 +44,8 @@ export class UtilityPlugin extends Plugin {
search: true, search: true,
clean: true, clean: true,
info: true, info: true,
server: true server: true,
reload_guild: true
} }
} }
] ]
@ -51,6 +55,11 @@ export class UtilityPlugin extends Plugin {
onLoad() { onLoad() {
this.logs = new GuildLogs(this.guildId); this.logs = new GuildLogs(this.guildId);
this.cases = new GuildCases(this.guildId); this.cases = new GuildCases(this.guildId);
if (activeReloads && activeReloads.has(this.guildId)) {
activeReloads.get(this.guildId).createMessage(successMessage("Reloaded!"));
activeReloads.delete(this.guildId);
}
} }
@d.command("roles") @d.command("roles")
@ -346,4 +355,14 @@ export class UtilityPlugin extends Plugin {
msg.channel.createMessage({ embed }); msg.channel.createMessage({ embed });
} }
@d.command("reload_guild")
@d.permission("reload_guild")
reloadGuildCmd(msg: Message) {
if (activeReloads.has(this.guildId)) return;
activeReloads.set(this.guildId, msg.channel as TextChannel);
msg.channel.createMessage("Reloading...");
this.knub.reloadGuild(this.guildId);
}
} }