core/utils/DiscordBot.ts
Eunwoo Choi 516f72ad08
feat: add open review deny log and max denies restriction (#510)
* feat: add open review log channel and embed

* chore: do not include submit page

* chore: mention instead of date

* feat: add max denies error

* typo: 더 이상

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>

* feat: add exceptions to deny count

* fix: invalid embed used

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>

* fix: invalid guild

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>

* fix: invalid position

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>

* fix: proper reason check position

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>

* feat: sepcific error message

* refactor: change reason embed format

* fix: knex andWhereNot method to whereNotIn method

Co-authored-by: Junseo Park <wonderlandpark@outlook.kr>
2022-08-15 21:22:55 +09:00

41 lines
2.0 KiB
TypeScript

import * as Discord from 'discord.js'
export const DiscordBot = new Discord.Client()
const guildID = '653083797763522580'
const reportChannelID = '813255797823766568'
const loggingChannelID = '844006379823955978'
const statsLoggingChannelID = '653227346962153472'
const reviewGuildID = '906537041326637086'
const botReviewLogChannelID = '906551334063439902'
const openBotReviewLogChannelID = '1008376563731013643'
DiscordBot.on('ready', async () => {
console.log('I\'m Ready')
await getMainGuild().members.fetch()
console.log(`Fetched ${getMainGuild().members.cache.size} Members`)
})
DiscordBot.login(process.env.DISCORD_TOKEN)
export const getMainGuild = () => DiscordBot.guilds.cache.get(guildID)
export const getReviewGuild = () => DiscordBot.guilds.cache.get(reviewGuildID)
export const getReportChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(reportChannelID) as Discord.TextChannel
export const getLoggingChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(loggingChannelID) as Discord.TextChannel
export const getBotReviewLogChannel = (): Discord.TextChannel => getReviewGuild().channels.cache.get(botReviewLogChannelID) as Discord.TextChannel
export const getStatsLoggingChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(statsLoggingChannelID) as Discord.TextChannel
export const getOpenBotReviewLogChannel = (): Discord.TextChannel => getMainGuild().channels.cache.get(openBotReviewLogChannelID) as Discord.TextChannel
export const discordLog = async (type: string, issuerID: string, embed?: Discord.MessageEmbed, attachment?: { content: string, format: string}, content?: string): Promise<void> => {
getLoggingChannel().send({
content: `[${type}] <@${issuerID}> (${issuerID})\n${content || ''}`,
embed: embed && embed.setTitle(type).setTimestamp(new Date()),
...(attachment && { files: [
new Discord.MessageAttachment(Buffer.from(attachment.content), `${type.toLowerCase().replace(/\//g, '-')}-${issuerID}-${Date.now()}.${attachment.format}`)
]
})
})
}