-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: starboard + rename sysAdmin to botAdmin
- Loading branch information
William Harrison
committed
Sep 27, 2023
1 parent
caad32b
commit 6a17be9
Showing
12 changed files
with
334 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Button from "../../classes/Button"; | ||
import ExtendedClient from "../../classes/ExtendedClient"; | ||
import { ButtonInteraction } from "discord.js"; | ||
|
||
const button: Button = { | ||
name: "star-count", | ||
startsWith: false, | ||
requiredRoles: [], | ||
async execute(interaction: ButtonInteraction, client: ExtendedClient, Discord: typeof import("discord.js")) { | ||
// Ignore the interaction | ||
await interaction.deferUpdate(); | ||
} | ||
} | ||
|
||
export = button; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import Event from "../../classes/Event"; | ||
import ExtendedClient from "../../classes/ExtendedClient"; | ||
import { Message, MessageReaction, PartialMessageReaction, PartialUser, PermissionResolvable, TextChannel } from "discord.js"; | ||
|
||
import { channels, main, starboard } from "../../config"; | ||
|
||
const event: Event = { | ||
name: "messageReactionAdd", | ||
once: false, | ||
async execute(client: ExtendedClient, Discord: typeof import("discord.js"), r: PartialMessageReaction, user: PartialUser) { | ||
try { | ||
const reaction: MessageReaction = await r.fetch(); | ||
const message: Message = await reaction.message.fetch(); | ||
const requiredPerms: PermissionResolvable = ["SendMessages", "EmbedLinks"]; | ||
|
||
// Ignore messages not in the primary guild and messages by bots | ||
if(message.author.bot || !message.guild) return; | ||
if(message.guild.id !== main.primaryGuild) return; | ||
// Return if the bot does not have the required permissions | ||
if(!message.guild.members.me.permissions.has(requiredPerms)) return; | ||
|
||
// Starboard | ||
// Return if the reaction emoji is not the starboard emoji | ||
if(reaction.emoji.name !== starboard.emoji) return; | ||
|
||
// Return if the message is more than 1 week old | ||
// The starboard is not supposed to be a history of the server | ||
if(message.createdTimestamp < Date.now() - 604800000) return; | ||
|
||
// Return if the reaction count is less than the required amount | ||
if(reaction.count < starboard.threshold) return; | ||
|
||
// Return if the message is in the starboard channel | ||
if(message.channel.id === channels.starboard) return; | ||
|
||
// Return if the message is in a channel that is not allowed | ||
if(!starboard.allowed.includes(message.channel.id)) return; | ||
|
||
// Return if there is no message content or attachments | ||
if(!message.content && message.attachments.size < 1) return; | ||
|
||
const channel = message.guild.channels.cache.get(channels.starboard) as TextChannel; | ||
|
||
const messages = await channel.messages.fetch({ limit: 100 }); | ||
const starMessage = messages.find(msg => msg.author.id === client.user.id && msg.embeds.length === 1 && msg.embeds[0].footer.text === `ID: ${message.id}`); | ||
|
||
if(starMessage) { | ||
const row: any = starMessage.components[0]; | ||
|
||
row.components[0] = new Discord.ButtonBuilder() | ||
.setStyle(Discord.ButtonStyle.Secondary) | ||
.setCustomId("star-count") | ||
.setEmoji(starboard.emoji) | ||
.setLabel(`${reaction.count}`) | ||
|
||
// Edit the message | ||
starMessage.edit({ embeds: starMessage.embeds, components: starMessage.components }); | ||
} else { | ||
const embed = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.gold) | ||
.setAuthor({ name: message.author.tag.endsWith("#0") ? message.author.username : message.author.tag, iconURL: message.author.displayAvatarURL({ extension: "png", forceStatic: false }), url: `https://discord.com/users/${message.author.id}` }) | ||
.setFooter({ text: `ID: ${message.id}` }) | ||
|
||
const buttons: any = new Discord.ActionRowBuilder() | ||
.addComponents ( | ||
new Discord.ButtonBuilder() | ||
.setStyle(Discord.ButtonStyle.Secondary) | ||
.setCustomId("star-count") | ||
.setEmoji(starboard.emoji) | ||
.setLabel(`${reaction.count}`), | ||
|
||
new Discord.ButtonBuilder() | ||
.setStyle(Discord.ButtonStyle.Link) | ||
.setLabel("Jump to Message") | ||
.setURL(message.url) | ||
) | ||
|
||
// Add content and/or image to the embed | ||
if(message.content) embed.setDescription(message.content); | ||
if(message.attachments.size > 0) embed.setImage(message.attachments.first().url ?? message.attachments.first().proxyURL); | ||
|
||
// Return if there is no content or image | ||
if(!embed.data.description && !embed.data.image) return; | ||
|
||
// Send the message to the starboard channel | ||
channel.send({ embeds: [embed], components: [buttons] }); | ||
} | ||
} catch(err) { | ||
client.logError(err); | ||
} | ||
} | ||
} | ||
|
||
export = event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Event from "../../classes/Event"; | ||
import ExtendedClient from "../../classes/ExtendedClient"; | ||
import { Message, MessageReaction, PartialMessageReaction, PartialUser, PermissionResolvable, TextChannel } from "discord.js"; | ||
|
||
import { channels, main, starboard } from "../../config"; | ||
|
||
const event: Event = { | ||
name: "messageReactionRemove", | ||
once: false, | ||
async execute(client: ExtendedClient, Discord: typeof import("discord.js"), r: PartialMessageReaction, user: PartialUser) { | ||
try { | ||
const reaction: MessageReaction = await r.fetch(); | ||
const message: Message = await reaction.message.fetch(); | ||
const requiredPerms: PermissionResolvable = ["SendMessages", "EmbedLinks"]; | ||
|
||
// Ignore messages not in the primary guild and messages by bots | ||
if(message.author.bot || !message.guild) return; | ||
if(message.guild.id !== main.primaryGuild) return; | ||
// Return if the bot does not have the required permissions | ||
if(!message.guild.members.me.permissions.has(requiredPerms)) return; | ||
|
||
// Starboard | ||
// Return if the reaction emoji is not the starboard emoji | ||
if(reaction.emoji.name !== starboard.emoji) return; | ||
|
||
// Return if the message is more than 1 week old | ||
// The starboard is not supposed to be a history of the server | ||
if(message.createdTimestamp < Date.now() - 604800000) return; | ||
|
||
// Return if the message is in the starboard channel | ||
if(message.channel.id === channels.starboard) return; | ||
|
||
// Return if the message is in a channel that is not allowed | ||
if(!starboard.allowed.includes(message.channel.id)) return; | ||
|
||
// Return if there is no message content or attachments | ||
if(!message.content && message.attachments.size < 1) return; | ||
|
||
const channel = message.guild.channels.cache.get(channels.starboard) as TextChannel; | ||
|
||
const messages = await channel.messages.fetch({ limit: 100 }); | ||
const starMessage = messages.find(msg => msg.author.id === client.user.id && msg.embeds.length === 1 && msg.embeds[0].footer.text === `ID: ${message.id}`); | ||
|
||
// Delete the starboard message if the reaction threshold is no longer met | ||
if(starMessage && reaction.count < starboard.threshold) return starMessage.delete(); | ||
|
||
// Edit the message | ||
if(starMessage) { | ||
const row: any = starMessage.components[0]; | ||
|
||
row.components[0] = new Discord.ButtonBuilder() | ||
.setStyle(Discord.ButtonStyle.Secondary) | ||
.setCustomId("star-count") | ||
.setEmoji(starboard.emoji) | ||
.setLabel(`${reaction.count}`) | ||
|
||
// Edit the message | ||
starMessage.edit({ embeds: starMessage.embeds, components: starMessage.components }); | ||
} | ||
} catch(err) { | ||
client.logError(err); | ||
} | ||
} | ||
} | ||
|
||
export = event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Event from "../../classes/Event"; | ||
import ExtendedClient from "../../classes/ExtendedClient"; | ||
import { Collection, Message, MessageReaction, PartialMessage, PermissionResolvable, Snowflake, TextChannel } from "discord.js"; | ||
|
||
import { channels, main, starboard } from "../../config"; | ||
|
||
const event: Event = { | ||
name: "messageReactionRemoveAll", | ||
once: false, | ||
async execute(client: ExtendedClient, Discord: typeof import("discord.js"), msg: PartialMessage, reactions: Collection<string | Snowflake, MessageReaction>) { | ||
try { | ||
const message: Message = await msg.fetch(); | ||
const requiredPerms: PermissionResolvable = ["SendMessages", "EmbedLinks"]; | ||
|
||
// Ignore messages not in the primary guild and messages by bots | ||
if(message.author.bot || !message.guild) return; | ||
if(message.guild.id !== main.primaryGuild) return; | ||
// Return if the bot does not have the required permissions | ||
if(!message.guild.members.me.permissions.has(requiredPerms)) return; | ||
|
||
// Starboard | ||
// Return if the message is more than 1 week old | ||
// The starboard is not supposed to be a history of the server | ||
if(message.createdTimestamp < Date.now() - 604800000) return; | ||
|
||
// Return if the message is in the starboard channel | ||
if(message.channel.id === channels.starboard) return; | ||
|
||
// Return if the message is in a channel that is not allowed | ||
if(!starboard.allowed.includes(message.channel.id)) return; | ||
|
||
// Return if there is no message content or attachments | ||
if(!message.content && message.attachments.size < 1) return; | ||
|
||
// Fetch the starboard emoji | ||
const reaction = reactions.filter(r => r.emoji.name === starboard.emoji).first(); | ||
|
||
// Return if the reaction is not found | ||
if(!reaction) return; | ||
|
||
const channel = message.guild.channels.cache.get(channels.starboard) as TextChannel; | ||
|
||
const messages = await channel.messages.fetch({ limit: 100 }); | ||
const starMessage = messages.find(msg => msg.author.id === client.user.id && msg.embeds.length === 1 && msg.embeds[0].footer.text === `ID: ${message.id}`); | ||
|
||
// Delete the starboard message if the reaction threshold is no longer met | ||
if(starMessage) return starMessage.delete(); | ||
} catch(err) { | ||
client.logError(err); | ||
} | ||
} | ||
} | ||
|
||
export = event; |
Oops, something went wrong.