Skip to content

Commit

Permalink
refactor structures and events
Browse files Browse the repository at this point in the history
  • Loading branch information
Moebits committed Aug 22, 2024
1 parent 8be2662 commit 992405d
Show file tree
Hide file tree
Showing 54 changed files with 1,260 additions and 884 deletions.
2 changes: 0 additions & 2 deletions .slugignore

This file was deleted.

2 changes: 0 additions & 2 deletions Aptfile

This file was deleted.

1 change: 0 additions & 1 deletion Procfile

This file was deleted.

8 changes: 4 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
],
"website": "https://kisaragi.moe/",
"support": "",
"patreon": "",
"kofi": "",
"invite": "https://discord.com/oauth2/authorize?client_id=CLIENTID&scope=bot&permissions=543279148279",
"oauth2": "https://kisaragi-discord-bot.herokuapp.com/discord",
"oauth2Testing": "http://localhost:5000/discord",
Expand All @@ -23,9 +21,11 @@
"kisaragiAPI": "https://kisaragi-discord-bot.herokuapp.com",
"guildLog": "683760526840692761",
"feedback": "683756932317577232",
"review": "https://bots.ondiscord.xyz/bots/593838271650332672/review",
"vote": "https://top.gg/bot/593838271650332672/vote",
"review": "",
"vote": "",
"trello": "https://trello.com/b/ToodAuzu",
"paypal": "",
"patreon": "",
"kofi": "",
"testing": "off"
}
16 changes: 16 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare module "*.png"
declare module "*.jpg"
declare module "*.gif"
declare module "*.mp3"
declare module "*.wav"
declare module "*.mp4"
declare module "*.mov"
declare module "*.webm"
declare module "*.webp"
declare module "*.sql"
declare module "*.txt"
declare module "*.glb"
declare module "*.obj"
declare module "*.fbx"
declare module "*.ttf"
declare module "*.otf"
1 change: 0 additions & 1 deletion ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
apps : [{
name: "Kisaragi",
script: "shard.js",

args: "one two",
instances: 1,
autorestart: true,
Expand Down
43 changes: 21 additions & 22 deletions events/caseUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {DMChannel, Message, MessageEmbed, TextChannel, User, Webhook} from "discord.js"
import {EmbedBuilder, TextChannel} from "discord.js"
import {Embeds} from "./../structures/Embeds"
import {Functions} from "./../structures/Functions"
import {Kisaragi} from "./../structures/Kisaragi"
import {SQLQuery} from "./../structures/SQLQuery"

export default class CaseUpdate {
constructor(private readonly discord: Kisaragi) {}

public insert = async (sql: SQLQuery, embed: MessageEmbed, instance: any, cases: any) => {
public insert = async (sql: SQLQuery, embed: EmbedBuilder, instance: any, cases: any) => {
const discord = this.discord
const user = await discord.users.fetch(instance.user)
const executor = await discord.users.fetch(instance.executor)
Expand All @@ -22,16 +21,16 @@ export default class CaseUpdate {
context = `[**Context**](${instance.context})`
}
embed
.setThumbnail(user.displayAvatarURL({format: "png", dynamic: true}))
.setThumbnail(user.displayAvatarURL({extension: "png"}))
.setDescription(
`${discord.getEmoji("star")}_User:_ **${user.tag}** \`(${user.id})\`\n` +
`${discord.getEmoji("star")}_Moderator:_ **${executor.tag}** \`(${executor.id})\`\n` +
`${discord.getEmoji("star")}_Reason:_ ${instance.reason}\n` +
context
)
.setFooter(channelName, executor.displayAvatarURL({format: "png", dynamic: true}))
.setFooter({text: channelName, iconURL: executor.displayAvatarURL({extension: "png"})})
.setTimestamp(Date.now())
const msg = await modLog?.send(embed).then((m) => m.id).catch(() => null)
const msg = await modLog?.send({embeds: [embed]}).then((m) => m.id).catch(() => null)
const data = {...instance, case: caseNumber, message: msg}
cases.push(data)
await sql.updateColumn("warns", "cases", cases)
Expand All @@ -58,127 +57,127 @@ export default class CaseUpdate {
case "warn":
const warnEmbed = embeds.createEmbed()
warnEmbed
.setAuthor("warn", "https://www.emoji.co.uk/files/phantom-open-emojis/symbols-phantom/13025-warning-sign.png")
.setAuthor({name: "warn", iconURL: "https://www.emoji.co.uk/files/phantom-open-emojis/symbols-phantom/13025-warning-sign.png"})
.setTitle(`**Warn | Case #${caseNumber}** ${discord.getEmoji("raphi")}`)
.setColor("#ffab3d")
await this.insert(sql, warnEmbed, instance, cases)
break
case "ban":
const banEmbed = embeds.createEmbed()
banEmbed
.setAuthor("ban", "https://discordemoji.com/assets/emoji/bancat.png")
.setAuthor({name: "ban", iconURL: "https://discordemoji.com/assets/emoji/bancat.png"})
.setTitle(`**Ban | Case #${caseNumber}** ${discord.getEmoji("kannaFU")}`)
.setColor("#ff2457")
await this.insert(sql, banEmbed, instance, cases)
break
case "unban":
const unbanEmbed = embeds.createEmbed()
unbanEmbed
.setAuthor("unban", "https://discordemoji.com/assets/emoji/bancat.png")
.setAuthor({name: "unban", iconURL: "https://discordemoji.com/assets/emoji/bancat.png"})
.setTitle(`**Unban | Case #${caseNumber}** ${discord.getEmoji("ceaseBullying")}`)
.setColor("#3daeff")
await this.insert(sql, unbanEmbed, instance, cases)
break
case "kick":
const kickEmbed = embeds.createEmbed()
kickEmbed
.setAuthor("kick", "https://discordemoji.com/assets/emoji/4331_UmaruWave.png")
.setAuthor({name: "kick", iconURL: "https://discordemoji.com/assets/emoji/4331_UmaruWave.png"})
.setTitle(`**Kick | Case #${caseNumber}** ${discord.getEmoji("kannaFU")}`)
.setColor("#ff3dfc")
await this.insert(sql, kickEmbed, instance, cases)
break
case "mute":
const muteEmbed = embeds.createEmbed()
muteEmbed
.setAuthor("mute", "https://images.emojiterra.com/mozilla/512px/1f507.png")
.setAuthor({name: "mute", iconURL: "https://images.emojiterra.com/mozilla/512px/1f507.png"})
.setTitle(`**Mute | Case #${caseNumber}** ${discord.getEmoji("sagiriBleh")}`)
.setColor("#ff3df5")
await this.insert(sql, muteEmbed, instance, cases)
break
case "unmute":
const unmuteEmbed = embeds.createEmbed()
unmuteEmbed
.setAuthor("unmute", "https://images.emojiterra.com/mozilla/512px/1f507.png")
.setAuthor({name: "unmute", iconURL: "https://images.emojiterra.com/mozilla/512px/1f507.png"})
.setTitle(`**Unmute | Case #${caseNumber}** ${discord.getEmoji("mexShrug")}`)
.setColor("#3de2ff")
await this.insert(sql, unmuteEmbed, instance, cases)
break
case "restrict":
const restrictEmbed = embeds.createEmbed()
restrictEmbed
.setAuthor("restrict", "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/mozilla/36/no-entry-sign_1f6ab.png")
.setAuthor({name: "restrict", iconURL: "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/mozilla/36/no-entry-sign_1f6ab.png"})
.setTitle(`**Restrict | Case #${caseNumber}** ${discord.getEmoji("no")}`)
.setColor("#ff873d")
await this.insert(sql, restrictEmbed, instance, cases)
break
case "unrestrict":
const unrestrictEmbed = embeds.createEmbed()
unrestrictEmbed
.setAuthor("unrestrict", "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/mozilla/36/no-entry-sign_1f6ab.png")
.setAuthor({name: "unrestrict", iconURL: "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/mozilla/36/no-entry-sign_1f6ab.png"})
.setTitle(`**Unrestrict | Case #${caseNumber}** ${discord.getEmoji("yes")}`)
.setColor("#5e3dff")
await this.insert(sql, unrestrictEmbed, instance, cases)
break
case "deafen":
const deafenEmbed = embeds.createEmbed()
deafenEmbed
.setAuthor("deafen", "https://cdn4.iconfinder.com/data/icons/music-audio-4/24/mute_sound_speaker_headphone_headset_music-512.png")
.setAuthor({name: "deafen", iconURL: "https://cdn4.iconfinder.com/data/icons/music-audio-4/24/mute_sound_speaker_headphone_headset_music-512.png"})
.setTitle(`**Deafen | Case #${caseNumber}** ${discord.getEmoji("sataniaDead")}`)
.setColor("#be3dff")
await this.insert(sql, deafenEmbed, instance, cases)
break
case "undeafen":
const undeafenEmbed = embeds.createEmbed()
undeafenEmbed
.setAuthor("undeafen", "https://d29fhpw069ctt2.cloudfront.net/icon/image/39276/preview.png")
.setAuthor({name: "undeafen", iconURL: "https://d29fhpw069ctt2.cloudfront.net/icon/image/39276/preview.png"})
.setTitle(`**Undeafen | Case #${caseNumber}** ${discord.getEmoji("mexShrug")}`)
.setColor("#3dabff")
await this.insert(sql, undeafenEmbed, instance, cases)
break
case "vcmute":
const vcmuteEmbed = embeds.createEmbed()
vcmuteEmbed
.setAuthor("voice mute", "https://www.kindpng.com/picc/m/499-4998592_mute-microphone-comments-mute-mic-icon-png-transparent.png")
.setAuthor({name: "voice mute", iconURL: "https://www.kindpng.com/picc/m/499-4998592_mute-microphone-comments-mute-mic-icon-png-transparent.png"})
.setTitle(`**Voice Mute | Case #${caseNumber}** ${discord.getEmoji("vigneDead")}`)
.setColor("#ff3db8")
await this.insert(sql, vcmuteEmbed, instance, cases)
break
case "vcunmute":
const vcunmuteEmbed = embeds.createEmbed()
vcunmuteEmbed
.setAuthor("voice unmute", "https://images.assetsdelivery.com/compings_v2/vectorgalaxy/vectorgalaxy1808/vectorgalaxy180807510.jpg")
.setAuthor({name: "voice unmute", iconURL: "https://images.assetsdelivery.com/compings_v2/vectorgalaxy/vectorgalaxy1808/vectorgalaxy180807510.jpg"})
.setTitle(`**Voice Unmute | Case #${caseNumber}** ${discord.getEmoji("aquaUp")}`)
.setColor("#3ddfff")
await this.insert(sql, vcunmuteEmbed, instance, cases)
break
case "vckick":
const vckickEmbed = embeds.createEmbed()
vckickEmbed
.setAuthor("voice kick", "https://cdn1.iconfinder.com/data/icons/interface-filled-blue/32/Microphone_recorder_sound_voice-512.png")
.setAuthor({name: "voice kick", iconURL: "https://cdn1.iconfinder.com/data/icons/interface-filled-blue/32/Microphone_recorder_sound_voice-512.png"})
.setTitle(`**Voice Kick | Case #${caseNumber}** ${discord.getEmoji("tohruSmug")}`)
.setColor("#47ff3d")
await this.insert(sql, vckickEmbed, instance, cases)
break
case "tempban":
const tempbanEmbed = embeds.createEmbed()
tempbanEmbed
.setAuthor("tempban", "https://cdn.discordapp.com/emojis/579870079735562261.png")
.setAuthor({name: "tempban", iconURL: "https://cdn.discordapp.com/emojis/579870079735562261.png"})
.setTitle(`**Temp Ban | Case #${caseNumber}** ${discord.getEmoji("kannaFU")}`)
.setColor("#ff3d64")
await this.insert(sql, tempbanEmbed, instance, cases)
break
case "tempmute":
const tempmuteEmbed = embeds.createEmbed()
tempmuteEmbed
.setAuthor("tempmute", "https://images.emojiterra.com/mozilla/512px/1f507.png")
.setAuthor({name: "tempmute", iconURL: "https://images.emojiterra.com/mozilla/512px/1f507.png"})
.setTitle(`**Temp Mute | Case #${caseNumber}** ${discord.getEmoji("sagiriBleh")}`)
.setColor("#a13dff")
await this.insert(sql, tempmuteEmbed, instance, cases)
break
case "softban":
const softbanEmbed = embeds.createEmbed()
softbanEmbed
.setAuthor("softban", "https://cdn.discordapp.com/emojis/593867503055274006.png")
.setAuthor({name: "softban", iconURL: "https://cdn.discordapp.com/emojis/593867503055274006.png"})
.setTitle(`**Soft Ban | Case #${caseNumber}** ${discord.getEmoji("sagiriBleh")}`)
.setColor("#ff24ba")
await this.insert(sql, softbanEmbed, instance, cases)
Expand Down
17 changes: 8 additions & 9 deletions events/channelPinsUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {DMChannel, Message, TextChannel, Webhook} from "discord.js"
import {MessageType, Message, TextChannel, TextBasedChannel, Webhook} from "discord.js"
import {Embeds} from "./../structures/Embeds"
import {Functions} from "./../structures/Functions"
import {Kisaragi} from "./../structures/Kisaragi"
import {SQLQuery} from "./../structures/SQLQuery"

Expand All @@ -16,7 +15,7 @@ export default class ChannelPinsUpdate {
webhook = webhooks.first()!
} else {
try {
webhook = await pinChannel.createWebhook("Pinboard", {avatar: this.discord.user!.displayAvatarURL({format: "png", dynamic: true})})
webhook = await pinChannel.createWebhook({name: "Pinboard", avatar: this.discord.user!.displayAvatarURL({extension: "png"})})
} catch {
return channel.send(`I need the **Manage Webhooks** permission to forward pinned messages ${discord.getEmoji("kannaFacepalm")}`)
}
Expand All @@ -30,20 +29,20 @@ export default class ChannelPinsUpdate {
if (!pin?.pinned) return
const pinEmbed = embeds.createEmbed()
pinEmbed
.setAuthor("pin", "https://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/pin-icon.png")
.setAuthor({name: "pin", iconURL: "https://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/pin-icon.png"})
.setTitle(`**Message Pinned!**`)
.setURL(pin.url)
.setDescription(`[**Message Link**](${pin.url})\n` + pin.content)
.setImage(pin.attachments.first() ? pin.attachments.first()!.url : "")
.setFooter(`${pin.author.tag} • #${(message.channel as TextChannel).name}`, pin.author.displayAvatarURL({format: "png", dynamic: true}))
await webhook.send({embeds: [pinEmbed], avatarURL: pin.author.displayAvatarURL({format: "png", dynamic: true}), username: pin.member?.displayName})
.setFooter({text: `${pin.author.tag} • #${(message.channel as TextChannel).name}`, iconURL: pin.author.displayAvatarURL({extension: "png"})})
await webhook.send({embeds: [pinEmbed], avatarURL: pin.author.displayAvatarURL({extension: "png"}), username: pin.member?.displayName})
await pin.unpin()
const pinMsg = await channel.messages.fetch({limit: 10}).then((m) => m.find((m) => m.type === "PINS_ADD"))
const pinMsg = await channel.messages.fetch({limit: 10}).then((m) => m.find((m) => m.type === MessageType.ChannelPinnedMessage))
if (pinMsg) await pinMsg.delete()
}

public run = async (channel: DMChannel | TextChannel, time: Date) => {
if (channel instanceof DMChannel) return
public run = async (channel: TextBasedChannel, time: Date) => {
if (!(channel instanceof TextChannel)) return
const message = channel.lastMessage!
const sql = new SQLQuery(message)

Expand Down
15 changes: 7 additions & 8 deletions events/guildBanAdd.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import {Guild, GuildAuditLogsEntry, Message, TextChannel, User} from "discord.js"
import {Guild, GuildAuditLogsEntry, AuditLogEvent, TextChannel, User, GuildBan} from "discord.js"
import {Embeds} from "./../structures/Embeds"
import {Functions} from "./../structures/Functions"
import {Kisaragi} from "./../structures/Kisaragi"
import {SQLQuery} from "./../structures/SQLQuery"

export default class GuildBanAdd {
constructor(private readonly discord: Kisaragi) {}

public run = async (guild: Guild, user: User) => {
public run = async (ban: GuildBan) => {
const discord = this.discord
const message = await discord.fetchFirstMessage(guild)
const message = await discord.fetchFirstMessage(ban.guild)
const sql = new SQLQuery(message!)
const embeds = new Embeds(discord, message!)

const logBan = async (guild: Guild, user: User) => {
const logBan = async (guild: Guild) => {
const modLog = await sql.fetchColumn("guilds", "mod log")
if (modLog) {
const modChannel = guild?.channels.cache.get(modLog)! as TextChannel
const log = await guild.fetchAuditLogs({type: "MEMBER_BAN_ADD", limit: 1}).then((l) => l.entries.first())
const log = await guild.fetchAuditLogs({type: AuditLogEvent.MemberBanAdd, limit: 1}).then((l) => l.entries.first())
.catch(async () => {
await modChannel.send(`I need the **View Audit Logs** permission in order to log guild bans.`).catch(() => null)
return
}) as GuildAuditLogsEntry
if (!log) return
const data = {type: "ban", user: (log.target as User).id, executor: log.executor.id, date: Date.now(), guild: guild.id, reason: log.reason}
const data = {type: "ban", user: (log.target as User).id, executor: log.executor?.id, date: Date.now(), guild: guild.id, reason: log.reason}
discord.emit("caseUpdate", data)
}
}
logBan(guild, user)
logBan(ban.guild)
}
}
14 changes: 7 additions & 7 deletions events/guildBanRemove.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Guild, GuildAuditLogsEntry, Message, TextChannel, User} from "discord.js"
import {Guild, GuildAuditLogsEntry, AuditLogEvent, GuildBan, TextChannel, User} from "discord.js"
import {Embeds} from "./../structures/Embeds"
import {Functions} from "./../structures/Functions"
import {Kisaragi} from "./../structures/Kisaragi"
Expand All @@ -7,27 +7,27 @@ import {SQLQuery} from "./../structures/SQLQuery"
export default class GuildBanRemove {
constructor(private readonly discord: Kisaragi) {}

public run = async (guild: Guild, user: User) => {
public run = async (ban: GuildBan) => {
const discord = this.discord
const message = await discord.fetchFirstMessage(guild)
const message = await discord.fetchFirstMessage(ban.guild)
if (!message) return
const sql = new SQLQuery(message)
const embeds = new Embeds(discord, message)

const logUnban = async (guild: Guild, user: User) => {
const logUnban = async (guild: Guild) => {
const modLog = await sql.fetchColumn("guilds", "mod log")
if (modLog) {
const modChannel = guild?.channels.cache.get(modLog)! as TextChannel
const log = await guild.fetchAuditLogs({type: "MEMBER_BAN_REMOVE", limit: 1}).then((l) => l.entries.first())
const log = await guild.fetchAuditLogs({type: AuditLogEvent.MemberBanRemove, limit: 1}).then((l) => l.entries.first())
.catch(async () => {
await modChannel.send(`I need the **View Audit Logs** permission in order to log guild bans.`).catch(() => null)
return
}) as GuildAuditLogsEntry
if (!log) return
const data = {type: "unban", user: (log.target as User).id, executor: log.executor.id, date: Date.now(), guild: guild.id, reason: log.reason}
const data = {type: "unban", user: (log.target as User).id, executor: log.executor?.id, date: Date.now(), guild: guild.id, reason: log.reason}
discord.emit("caseUpdate", data)
}
}
logUnban(guild, user)
logUnban(ban.guild)
}
}
Loading

0 comments on commit 992405d

Please sign in to comment.