mirror of https://github.com/clickscodes/nucleus
parent
813bdf45f3
commit
02ba023698
@ -1,153 +0,0 @@
|
||||
import { ChannelType } from 'discord-api-types';
|
||||
import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
|
||||
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
|
||||
import confirmationMessage from "../../utils/confirmationMessage.js";
|
||||
import getEmojiByName from "../../utils/getEmojiByName.js";
|
||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||
import { WrappedCheck } from "jshaiku";
|
||||
import client from "../../utils/client.js";
|
||||
|
||||
const command = (builder: SlashCommandSubcommandBuilder) =>
|
||||
builder
|
||||
.setName("staff")
|
||||
.setDescription("Settings for the staff notifications channel")
|
||||
.addChannelOption(option => option.setName("channel").setDescription("The channel to set the staff notifications channel to").addChannelTypes([
|
||||
ChannelType.GuildNews, ChannelType.GuildText
|
||||
]).setRequired(false))
|
||||
|
||||
const callback = async (interaction: CommandInteraction): Promise<any> => {
|
||||
let m;
|
||||
m = await interaction.reply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Loading")
|
||||
.setStatus("Danger")
|
||||
.setEmoji("NUCLEUS.LOADING")
|
||||
], ephemeral: true, fetchReply: true});
|
||||
if (interaction.options.getChannel("channel")) {
|
||||
let channel
|
||||
try {
|
||||
channel = interaction.options.getChannel("channel")
|
||||
} catch {
|
||||
return await interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setEmoji("CHANNEL.TEXT.DELETE")
|
||||
.setTitle("Staff Notifications Channel")
|
||||
.setDescription("The channel you provided is not a valid channel")
|
||||
.setStatus("Danger")
|
||||
]})
|
||||
}
|
||||
channel = channel as Discord.TextChannel
|
||||
if (channel.guild.id != interaction.guild.id) {
|
||||
return interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Staff Notifications Channel")
|
||||
.setDescription(`You must choose a channel in this server`)
|
||||
.setStatus("Danger")
|
||||
.setEmoji("CHANNEL.TEXT.DELETE")
|
||||
]});
|
||||
}
|
||||
let confirmation = await new confirmationMessage(interaction)
|
||||
.setEmoji("CHANNEL.TEXT.EDIT")
|
||||
.setTitle("Staff Notifications Channel")
|
||||
.setDescription(
|
||||
`This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n` +
|
||||
`Are you sure you want to set the staff notifications channel to <#${channel.id}>?`
|
||||
)
|
||||
.setColor("Warning")
|
||||
.setInverted(true)
|
||||
.send(true)
|
||||
if (confirmation.success) {
|
||||
try {
|
||||
await client.database.guilds.write(interaction.guild.id, {"logging.staff.channel": channel.id})
|
||||
const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
|
||||
try {
|
||||
let data = {
|
||||
meta:{
|
||||
type: 'logIgnoreUpdated',
|
||||
displayName: 'Staff Notifications Channel Updated',
|
||||
calculateType: 'nucleusSettingsUpdated',
|
||||
color: NucleusColors.yellow,
|
||||
emoji: "CHANNEL.TEXT.EDIT",
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
list: {
|
||||
memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
|
||||
changedBy: entry(interaction.user.id, renderUser(interaction.user)),
|
||||
channel: entry(channel.id, renderChannel(channel)),
|
||||
},
|
||||
hidden: {
|
||||
guild: interaction.guild.id
|
||||
}
|
||||
}
|
||||
log(data);
|
||||
} catch {}
|
||||
} catch (e) {
|
||||
return interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Staff Notifications Channel")
|
||||
.setDescription(`Something went wrong and the staff notifications channel could not be set`)
|
||||
.setStatus("Danger")
|
||||
.setEmoji("CHANNEL.TEXT.DELETE")
|
||||
], components: []});
|
||||
}
|
||||
} else {
|
||||
return interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Staff Notifications Channel")
|
||||
.setDescription(`No changes were made`)
|
||||
.setStatus("Success")
|
||||
.setEmoji("CHANNEL.TEXT.CREATE")
|
||||
], components: []});
|
||||
}
|
||||
}
|
||||
let clicks = 0;
|
||||
let data = await client.database.guilds.read(interaction.guild.id);
|
||||
let channel = data.logging.staff.channel;
|
||||
while (true) {
|
||||
await interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Staff Notifications channel")
|
||||
.setDescription(channel ? `Your staff notifications channel is currently set to <#${channel}>` : "This server does not have a staff notifications channel")
|
||||
.setStatus("Success")
|
||||
.setEmoji("CHANNEL.TEXT.CREATE")
|
||||
], components: [new MessageActionRow().addComponents([new MessageButton()
|
||||
.setCustomId("clear")
|
||||
.setLabel(clicks ? "Click again to confirm" : "Reset channel")
|
||||
.setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
|
||||
.setStyle("DANGER")
|
||||
.setDisabled(!channel)
|
||||
])]});
|
||||
let i;
|
||||
try {
|
||||
i = await m.awaitMessageComponent({time: 300000});
|
||||
} catch(e) { break }
|
||||
i.deferUpdate()
|
||||
if (i.component.customId == "clear") {
|
||||
clicks += 1;
|
||||
if (clicks == 2) {
|
||||
clicks = 0;
|
||||
await client.database.guilds.write(interaction.guild.id, {}, ["logging.staff.channel"])
|
||||
channel = undefined;
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
await interaction.editReply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Staff Notifications channel")
|
||||
.setDescription(channel ? `Your staff notifications channel is currently set to <#${channel}>` : "This server does not have a staff notifications channel")
|
||||
.setStatus("Success")
|
||||
.setEmoji("CHANNEL.TEXT.CREATE")
|
||||
.setFooter({text: "Message closed"})
|
||||
], components: [new MessageActionRow().addComponents([new MessageButton()
|
||||
.setCustomId("clear")
|
||||
.setLabel("Clear")
|
||||
.setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
|
||||
.setStyle("SECONDARY")
|
||||
.setDisabled(true)
|
||||
])]});
|
||||
}
|
||||
|
||||
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
|
||||
let member = (interaction.member as Discord.GuildMember)
|
||||
if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the Manage Server permission to use this command"
|
||||
return true;
|
||||
}
|
||||
|
||||
export { command };
|
||||
export { callback };
|
||||
export { check };
|
||||
@ -1,21 +1,58 @@
|
||||
import { CommandInteraction } from "discord.js";
|
||||
import { AutocompleteInteraction, CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { WrappedCheck } from "jshaiku";
|
||||
import { callback as statsChannelAdd } from '../reflex/statsChannelAdd.js';
|
||||
import client from "../utils/client.js"
|
||||
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
|
||||
|
||||
const command = new SlashCommandBuilder()
|
||||
.setName("tag")
|
||||
.setDescription("Get and manage the servers tags")
|
||||
.addStringOption(o => o.setName("tag").setDescription("The tag to get").setAutocomplete(true).setRequired(true))
|
||||
|
||||
const callback = async (interaction: CommandInteraction) => {
|
||||
const config = await client.database.guilds.read(interaction.guild.id)
|
||||
const tags = config.getKey("tags")
|
||||
const tag = tags[interaction.options.getString("tag")]
|
||||
if (!tag) {
|
||||
return await interaction.reply({embeds: [new EmojiEmbed()
|
||||
.setTitle("Tag")
|
||||
.setDescription(`Tag \`${interaction.options.getString("tag")}\` does not exist`)
|
||||
.setEmoji("PUNISH.NICKNAME.RED")
|
||||
.setStatus("Danger")
|
||||
], ephemeral: true})
|
||||
}
|
||||
let url = ""
|
||||
let components = []
|
||||
if (tag.match(/^(http|https):\/\/[^ "]+$/)) {
|
||||
url = tag
|
||||
components = [new MessageActionRow().addComponents([new MessageButton()
|
||||
.setLabel("Open")
|
||||
.setURL(url)
|
||||
.setStyle("LINK")
|
||||
])]
|
||||
}
|
||||
return await interaction.reply({embeds: [new EmojiEmbed()
|
||||
.setTitle(interaction.options.getString("tag"))
|
||||
.setDescription(tag)
|
||||
.setEmoji("PUNISH.NICKNAME.GREEN")
|
||||
.setStatus("Success")
|
||||
.setImage(url)
|
||||
], components: components, ephemeral: true})
|
||||
|
||||
const callback = (interaction: CommandInteraction) => {
|
||||
interaction.reply("This command is not yet finished [tag]");
|
||||
}
|
||||
|
||||
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
|
||||
return true;
|
||||
}
|
||||
|
||||
const autocomplete = async (interaction: AutocompleteInteraction): Promise<string[]> => {
|
||||
if (!interaction.guild) return [];
|
||||
const config = await client.database.guilds.read(interaction.guild.id)
|
||||
const tags = Object.keys(config.getKey("tags"));
|
||||
return tags
|
||||
}
|
||||
|
||||
export { command };
|
||||
export { callback };
|
||||
export { check };
|
||||
export { autocomplete };
|
||||
@ -1,33 +0,0 @@
|
||||
import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
|
||||
import singleNotify from '../utils/singleNotify.js';
|
||||
import client from '../utils/client.js';
|
||||
|
||||
export async function callback(_, member) {
|
||||
let config = await client.database.guilds.read(member.guild.id);
|
||||
|
||||
config.stats.forEach(async element => {
|
||||
if (element.enabled) {
|
||||
let string = element.text
|
||||
if (!string) return
|
||||
string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
|
||||
let channel;
|
||||
try {
|
||||
channel = await member.client.channels.fetch(element.channel)
|
||||
} catch (error) { channel = null }
|
||||
if (!channel) {
|
||||
return singleNotify(
|
||||
"statsChannelDeleted",
|
||||
member.guild.id,
|
||||
"One or more of your stats channels have been deleted. Please open the settings menu to change this.",
|
||||
"Critical"
|
||||
)
|
||||
}
|
||||
if (channel.guild.id !== member.guild.id) return
|
||||
try {
|
||||
await channel.edit({ name: string })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
import client from '../utils/client.js';
|
||||
import convertCurlyBracketString from '../utils/convertCurlyBracketString.js'
|
||||
import singleNotify from '../utils/singleNotify.js';
|
||||
|
||||
export async function callback(_, member) {
|
||||
let config = await client.database.guilds.read(member.guild.id);
|
||||
|
||||
config.stats.forEach(async element => {
|
||||
if (element.enabled) {
|
||||
let string = element.text
|
||||
if (!string) return
|
||||
string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members)
|
||||
let channel;
|
||||
try {
|
||||
channel = await member.client.channels.fetch(element.channel)
|
||||
} catch { channel = null }
|
||||
if (!channel) return singleNotify(
|
||||
"statsChannelDeleted",
|
||||
member.guild.id,
|
||||
"One or more of your stats channels have been deleted. Please open the settings menu to change this.",
|
||||
"Critical"
|
||||
)
|
||||
try {
|
||||
await channel.edit({ name: string })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue