moved to subdir
This commit is contained in:
@@ -0,0 +1,274 @@
|
||||
const { SlashCommandBuilder, EmbedBuilder, MessageFlags } = require('discord.js')
|
||||
const { mClient } = require('../../../index')
|
||||
const { configDotenv } = require('dotenv')
|
||||
configDotenv()
|
||||
|
||||
function isValidDate(day, month) {
|
||||
// Define the number of days in each month
|
||||
const daysInMonth = {
|
||||
1: 31, // January
|
||||
2: 28, // February (ignore leap years)
|
||||
3: 31, // March
|
||||
4: 30, // April
|
||||
5: 31, // May
|
||||
6: 30, // June
|
||||
7: 31, // July
|
||||
8: 31, // August
|
||||
9: 30, // September
|
||||
10: 31, // October
|
||||
11: 30, // November
|
||||
12: 31 // December
|
||||
};
|
||||
|
||||
// Check if month is valid
|
||||
if (month < 1 || month > 12) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if day is valid for the given month
|
||||
if (day < 1 || day > daysInMonth[month]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
async function birthdayAdd(interaction) {
|
||||
let target = await interaction.options.getUser('user')
|
||||
let day = await interaction.options.getNumber('day')
|
||||
let month = await interaction.options.getNumber('month')
|
||||
|
||||
|
||||
if (!isValidDate(day, month)) {
|
||||
return interaction.reply({ content: "Invalid Date", flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const bdayColl = db.collection('items_birthdays')
|
||||
|
||||
const found = await bdayColl.findOne({ userID: target.id })
|
||||
if (found) {
|
||||
return interaction.reply({ content: "Already in Database", flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
const data = {
|
||||
guildID: interaction.guild.id,
|
||||
userID: target.id,
|
||||
day: day,
|
||||
month: month
|
||||
}
|
||||
|
||||
const res = await bdayColl.insertOne(data)
|
||||
if (res.acknowledged) {
|
||||
return interaction.reply({ content: "Birthday added successfully!" })
|
||||
} else {
|
||||
return interaction.reply({ content: "There was an issue!" })
|
||||
}
|
||||
}
|
||||
async function birthdayDelete(interaction) {
|
||||
var target = await interaction.options.getUser('user')
|
||||
const guild = await interaction.client.guilds.cache.get(interaction.guild.id)
|
||||
if (!target) {
|
||||
target = await guild.members.cache.get(await interaction.options.getString('id'))
|
||||
}
|
||||
|
||||
if (!target) {
|
||||
return interaction.reply({ content: "Invalid or No User specified!" })
|
||||
}
|
||||
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const bdayColl = db.collection('items_birthdays')
|
||||
|
||||
const found = await bdayColl.findOne({ userID: target.id })
|
||||
if (!found) {
|
||||
return interaction.reply({ content: "Not yet in Database", flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
const res = await bdayColl.deleteOne({ userID: target.id })
|
||||
if (res.acknowledged) {
|
||||
return interaction.reply({ content: "Birthday removed successfully!" })
|
||||
} else {
|
||||
return interaction.reply({ content: "There was an issue!" })
|
||||
}
|
||||
}
|
||||
async function birthdayEdit(interaction) {
|
||||
let target = await interaction.options.getUser('user')
|
||||
let day = await interaction.options.getNumber('day')
|
||||
let month = await interaction.options.getNumber('month')
|
||||
|
||||
|
||||
if (!isValidDate(day, month)) {
|
||||
return interaction.reply({ content: "Invalid Date", flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const bdayColl = db.collection('items_birthdays')
|
||||
|
||||
const found = await bdayColl.findOne({ userID: target.id })
|
||||
if (!found) {
|
||||
return interaction.reply({ content: "Not yet in Database", flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
const data = {
|
||||
guildID: interaction.guild.id,
|
||||
userID: target.id,
|
||||
day: day,
|
||||
month: month
|
||||
}
|
||||
|
||||
const res = await bdayColl.findOneAndUpdate({ userID: target.id }, { $set: data }, { upsert: true })
|
||||
return interaction.reply({ content: "Birthday edited successfully!" })
|
||||
}
|
||||
async function makeTimestamp(day, month, year) {
|
||||
const date = new Date(year, month - 1, day);
|
||||
const unixTimestamp = Math.floor(date.getTime() / 1000);
|
||||
return unixTimestamp
|
||||
}
|
||||
function isToday(day, month) {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const inputDate = new Date(currentYear, month - 1, day);
|
||||
const today = new Date();
|
||||
return (
|
||||
inputDate.getDate() === today.getDate() &&
|
||||
inputDate.getMonth() === today.getMonth() &&
|
||||
inputDate.getFullYear() === today.getFullYear()
|
||||
);
|
||||
}
|
||||
async function birthdayGet(interaction) {
|
||||
const target = await interaction.options.getUser('user');
|
||||
const db = mClient.db(process.env.M_DB);
|
||||
const bdayColl = db.collection('items_birthdays');
|
||||
|
||||
const found = await bdayColl.findOne({ userID: target.id });
|
||||
if (!found) {
|
||||
return interaction.reply({
|
||||
content: "Not in Database!",
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const isToday =
|
||||
now.getDate() === found.day &&
|
||||
now.getMonth() === (found.month - 1);
|
||||
|
||||
let description;
|
||||
|
||||
if (isToday) {
|
||||
description = `IS TODAY! 🥳🎉`;
|
||||
} else {
|
||||
const unix = getNextBirthdayTimestamp(found.day, found.month);
|
||||
description = `is on the <t:${unix}:d>\n<t:${unix}:R>`;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setThumbnail(target.displayAvatarURL())
|
||||
.setTitle(`${target.globalName ?? target.username}'s Birthday...`)
|
||||
.setDescription(description);
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
function getNextBirthdayTimestamp(day, month) {
|
||||
const now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
|
||||
const currentYear = now.getFullYear();
|
||||
|
||||
let nextBirthday = new Date(currentYear, month - 1, day);
|
||||
|
||||
// If birthday already passed this year → next year
|
||||
if (nextBirthday < now) {
|
||||
nextBirthday.setFullYear(currentYear + 1);
|
||||
}
|
||||
|
||||
return Math.floor(nextBirthday.getTime() / 1000); // Unix timestamp
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('birthday')
|
||||
.setDescription('manage birthdays')
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('add')
|
||||
.setDescription('adds a birthday')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('user')
|
||||
.setDescription('user')
|
||||
.setRequired(true))
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('day')
|
||||
.setDescription('day')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(31)
|
||||
.setRequired(true))
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('month')
|
||||
.setDescription('month')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(12)
|
||||
.setRequired(true))
|
||||
)
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('delete')
|
||||
.setDescription('deletes a birthday')
|
||||
.addUserOption((option) =>
|
||||
option.setName('user').setDescription('user'))
|
||||
.addStringOption((option) =>
|
||||
option.setName('id').setDescription('ID')))
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('edit')
|
||||
.setDescription('edits a birthday')
|
||||
.addUserOption((option) =>
|
||||
option.setName('user').setDescription('user').setRequired(true))
|
||||
.addNumberOption((option) =>
|
||||
option.setName('day').setDescription('day').setRequired(true))
|
||||
.addNumberOption((option) =>
|
||||
option.setName('month').setDescription('month').setRequired(true)))
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('get')
|
||||
.setDescription('gets a birthday')
|
||||
.addUserOption((option) =>
|
||||
option.setName('user').setDescription('user').setRequired(true))),
|
||||
async execute(interaction) {
|
||||
switch (interaction.options._subcommand) {
|
||||
case 'add':
|
||||
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
|
||||
return await interaction.reply({
|
||||
content: "Unprivileged Access!",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
birthdayAdd(interaction)
|
||||
break;
|
||||
case 'delete':
|
||||
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
|
||||
return await interaction.reply({
|
||||
content: "Unprivileged Access!",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
birthdayDelete(interaction)
|
||||
break;
|
||||
case 'edit':
|
||||
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
|
||||
return await interaction.reply({
|
||||
content: "Unprivileged Access!",
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
birthdayEdit(interaction)
|
||||
break;
|
||||
case 'get':
|
||||
birthdayGet(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
const { SlashCommandBuilder, Events, MessageFlags } = require('discord.js')
|
||||
const { mClient } = require('../../../index')
|
||||
require('dotenv').config()
|
||||
|
||||
async function channelSet(interaction) {
|
||||
const channel = interaction.options.getChannel('channel')
|
||||
const purpose = interaction.options.getString('purpose')
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const channelColl = db.collection('config_channels')
|
||||
|
||||
await channelColl.findOneAndUpdate({
|
||||
$and: [{ guildID: channel.guild.id }, { purpose: purpose }]
|
||||
}, {
|
||||
$set: {
|
||||
guildID: channel.guild.id,
|
||||
purpose: purpose,
|
||||
channelID: channel.id
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
return await interaction.editReply({
|
||||
content: `Set <#${channel.id}> as ${purpose} channel!`, flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
|
||||
async function channelSimulate(interaction) {
|
||||
const purpose = interaction.options.getString('purpose')
|
||||
switch (purpose) {
|
||||
case 'birthday':
|
||||
await interaction.client.emit('Birthday', interaction.member)
|
||||
break;
|
||||
case 'wge':
|
||||
// For Future WGE Use
|
||||
break;
|
||||
case 'welcome':
|
||||
await interaction.client.emit(Events.GuildMemberAdd, interaction.member)
|
||||
break;
|
||||
case 'logs':
|
||||
// For Future Log Use
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return interaction.reply({ content: 'Done.', flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
|
||||
async function roleSet(interaction) {
|
||||
const guild = interaction.guild
|
||||
const purpose = interaction.options.getString('purpose')
|
||||
const role = interaction.options.getRole('role')
|
||||
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const roleColl = db.collection('config_roles')
|
||||
|
||||
switch (purpose) {
|
||||
case 'birthday':
|
||||
await roleColl.findOneAndUpdate({
|
||||
$and: [{ guildID: guild.id }, { purpose: purpose }]
|
||||
}, {
|
||||
$set: {
|
||||
guildID: guild.id,
|
||||
purpose: purpose,
|
||||
roleID: role.id
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return await interaction.editReply({
|
||||
content: `Set ${role} as default role for ${purpose} in ${guild} `
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('config')
|
||||
.setDescription('configurations for admins')
|
||||
.addSubcommandGroup(sg =>
|
||||
sg
|
||||
.setName('channels')
|
||||
.setDescription('configure channels for certain events')
|
||||
.addSubcommand(s =>
|
||||
s.setName('set')
|
||||
.setDescription('sets channel')
|
||||
.addStringOption(o =>
|
||||
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
|
||||
name: 'birthday',
|
||||
value: 'birthday'
|
||||
}, {
|
||||
name: 'welcome',
|
||||
value: 'welcome'
|
||||
}, {
|
||||
name: 'logs',
|
||||
value: 'logs'
|
||||
}, {
|
||||
name: 'wge',
|
||||
value: 'wge'
|
||||
}))
|
||||
.addChannelOption(c =>
|
||||
c.setName('channel').setDescription('choose a channel').setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand(s =>
|
||||
s
|
||||
.setName('simulate')
|
||||
.setDescription('simulate a specific channel event')
|
||||
.addStringOption(o =>
|
||||
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
|
||||
name: 'birthday',
|
||||
value: 'birthday'
|
||||
}, {
|
||||
name: 'welcome',
|
||||
value: 'welcome'
|
||||
}, {
|
||||
name: 'logs',
|
||||
value: 'logs'
|
||||
}, {
|
||||
name: 'wge',
|
||||
value: 'wge'
|
||||
}))
|
||||
)
|
||||
)
|
||||
.addSubcommandGroup(sg =>
|
||||
sg.setName('roles')
|
||||
.setDescription('configure roles for certain events')
|
||||
.addSubcommand(s =>
|
||||
s.setName('set')
|
||||
.setDescription('sets roles')
|
||||
.addStringOption(o =>
|
||||
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
|
||||
name: 'birthday',
|
||||
value: 'birthday'
|
||||
}))
|
||||
.addRoleOption(c =>
|
||||
c.setName('role').setDescription('choose a role').setRequired(true)
|
||||
)
|
||||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
switch (interaction.options._group) {
|
||||
case 'channels':
|
||||
switch (interaction.options._subcommand) {
|
||||
case 'set':
|
||||
await interaction.deferReply()
|
||||
channelSet(interaction)
|
||||
break;
|
||||
case 'simulate':
|
||||
channelSimulate(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case 'roles':
|
||||
switch (interaction.options._subcommand) {
|
||||
case 'set':
|
||||
await interaction.deferReply()
|
||||
roleSet(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user