From 435de37dc8c8fddf771a1692dd3ccb678bcd439a Mon Sep 17 00:00:00 2001 From: Dragory Date: Thu, 3 Jan 2019 06:16:00 +0200 Subject: [PATCH] tags: add !tag list command --- src/data/GuildTags.ts | 8 ++++++++ src/plugins/Tags.ts | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/data/GuildTags.ts b/src/data/GuildTags.ts index 27e3bffb..df3cfdf1 100644 --- a/src/data/GuildTags.ts +++ b/src/data/GuildTags.ts @@ -10,6 +10,14 @@ export class GuildTags extends BaseRepository { this.tags = getRepository(Tag); } + async all(): Promise { + return this.tags.find({ + where: { + guild_id: this.guildId + } + }); + } + async find(tag): Promise { return this.tags.findOne({ where: { diff --git a/src/plugins/Tags.ts b/src/plugins/Tags.ts index efcbeb16..abc23c9c 100644 --- a/src/plugins/Tags.ts +++ b/src/plugins/Tags.ts @@ -4,7 +4,7 @@ import { errorMessage, successMessage } from "../utils"; import { GuildTags } from "../data/GuildTags"; export class TagsPlugin extends Plugin { - public static pluginName = 'tags'; + public static pluginName = "tags"; protected tags: GuildTags; @@ -34,6 +34,22 @@ export class TagsPlugin extends Plugin { this.tags = GuildTags.getInstance(this.guildId); } + @d.command("tag list") + @d.permission("create") + async tagListCmd(msg: Message) { + const tags = await this.tags.all(); + if (tags.length === 0) { + msg.channel.createMessage(`No tags created yet! Use \`tag create\` command to create one.`); + return; + } + + const prefix = this.configValueForMsg(msg, "prefix"); + const tagNames = tags.map(t => t.tag).sort(); + msg.channel.createMessage(` + Available tags (use with ${prefix}tag): \`\`\`${tagNames.join(", ")}\`\`\` + `); + } + @d.command("tag delete", "") @d.permission("create") async deleteTagCmd(msg: Message, args: { tag: string }) {