add trello // webhook features

This commit is contained in:
Lio Young 2021-04-24 17:41:24 +02:00
parent c1c79c4a21
commit 780086b8a2
No known key found for this signature in database
GPG Key ID: 789795A11879E169
2 changed files with 58 additions and 0 deletions

30
src/utils/trello.ts Normal file
View File

@ -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

28
src/utils/webhook.ts Normal file
View File

@ -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]
})
}