From 780086b8a2f2c37633eddbfb7e53c7c561ddfe3a Mon Sep 17 00:00:00 2001 From: Lio Young Date: Sat, 24 Apr 2021 17:41:24 +0200 Subject: [PATCH] add trello // webhook features --- src/utils/trello.ts | 30 ++++++++++++++++++++++++++++++ src/utils/webhook.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/utils/trello.ts create mode 100644 src/utils/webhook.ts diff --git a/src/utils/trello.ts b/src/utils/trello.ts new file mode 100644 index 0000000..28795ab --- /dev/null +++ b/src/utils/trello.ts @@ -0,0 +1,30 @@ +import { Trello as TClient } from "trello-helper"; +import config from '../../config' + +process.env.trelloHelper = JSON.stringify({ + appKey: config.trello.key, + token: config.trello.token +}) + +const Trello = new TClient({ + useExistingEnvVar: true +}) + + +export async function suggest({ title, desc, author, guild }: { title: string, desc?: string, author: string, guild: string }) { + let Card = await Trello.addCard({ + idList: config.trello.options.list.suggestions, + name: `Suggestion - ${title}`, + desc: ` + ${desc || title} + + Author: ${author} + Server: ${guild} + ` + }) + + return Card +} + + +export default Trello \ No newline at end of file diff --git a/src/utils/webhook.ts b/src/utils/webhook.ts new file mode 100644 index 0000000..4357e9c --- /dev/null +++ b/src/utils/webhook.ts @@ -0,0 +1,28 @@ +import { Guild, MessageEmbed, User, WebhookClient } from "discord.js"; +import { Webhook } from "../utils/types" +import embed from "../utils/embed"; +import config from "../../config"; +export default async function SendWS( + webhook: Webhook, + content: { + title: string, + desc: string, + ctx: { + author: User, + guild: Guild | null + } + }) { + + let Hook = new WebhookClient(webhook.id, webhook.token) + let author = `${content.ctx.author.username} (${content.ctx.author.id})` + let guild = `${content.ctx.guild?.name} (${content.ctx.guild?.id})` + // @ts-ignore + embed.setAuthor(`${author}\n${guild}`, content.ctx.author.avatarURL()) + embed.setDescription(`${content.title}${content.desc ? `\n\n${content.desc}` : ""}`) + + Hook.send(`New ${webhook.type}`, { + username: webhook.username, + avatarURL: config.variables.avatar, + embeds: [embed] + }) +} \ No newline at end of file