3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Add Tags plugin

This commit is contained in:
Dragory 2018-08-05 01:32:59 +03:00
parent 54b79ca51f
commit 4a1a14be59
6 changed files with 158 additions and 5 deletions

73
src/plugins/Tags.ts Normal file
View file

@ -0,0 +1,73 @@
import { Plugin, decorators as d } from "knub";
import { Channel, Message, TextChannel } from "eris";
import { errorMessage, successMessage } from "../utils";
import { GuildTags } from "../data/GuildTags";
export class TagsPlugin extends Plugin {
protected tags: GuildTags;
getDefaultOptions() {
return {
config: {
prefix: "!!"
},
permissions: {
create: false,
use: true
},
overrides: [
{
level: ">=50",
permissions: {
create: true
}
}
]
};
}
onLoad() {
this.tags = new GuildTags(this.guildId);
}
@d.command("tag", "<tag:string> <body:string$>")
@d.permission("create")
async tagCmd(msg: Message, args: { tag: string; body: string }) {
await this.tags.createOrUpdate(args.tag, args.body, msg.author.id);
const prefix = this.configValue("prefix");
msg.channel.createMessage(successMessage(`Tag set! Use it with: \`${prefix}${args.tag}\``));
}
@d.command("tag_delete", "<tag:string>")
@d.permission("create")
async deleteTagCmd(msg: Message, args: { tag: string }) {
const tag = await this.tags.find(args.tag);
if (!tag) {
msg.channel.createMessage(errorMessage("No tag with that name"));
return;
}
await this.tags.delete(args.tag);
msg.channel.createMessage(successMessage("Tag deleted!"));
}
@d.event("messageCreate")
@d.permission("use")
async onMessageCreate(msg: Message) {
if (!msg.content) return;
if (msg.type !== 0) return;
if (!msg.author || msg.author.bot) return;
const prefix = this.configValueForMsg(msg, "prefix");
if (!msg.content.startsWith(prefix)) return;
const withoutPrefix = msg.content.slice(prefix.length);
const tag = await this.tags.find(withoutPrefix);
if (!tag) return;
msg.channel.createMessage(tag.body);
}
}