mobile update
This commit is contained in:
@@ -1,46 +1,81 @@
|
|||||||
const { EmbedBuilder, MessageFlags } = require("discord.js")
|
const { EmbedBuilder, MessageFlags } = require("discord.js");
|
||||||
const { client, mClient } = require("../../../index")
|
const { client, mClient } = require("../../../index");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'quotesadd',
|
name: "quotesadd",
|
||||||
description: 'adds a quote to the database by replying to the message',
|
description: "Adds a quote to the database by replying to a message.",
|
||||||
category: 'Quotes',
|
aliases: ["qadd", "qa"],
|
||||||
aliases: ['qadd', 'qa'],
|
async execute(message) {
|
||||||
async execute(message, args) {
|
// Ensure the command is used as a reply.
|
||||||
const refMessage = message.reference // message to be quoted has been replied to
|
if (!message.reference?.messageId) {
|
||||||
const refMessageId = refMessage.messageId
|
return message.reply({
|
||||||
const refChannelId = refMessage.channelId
|
content: "Please reply to the message you want to quote.",
|
||||||
const refGuildId = refMessage.guildId
|
flags: MessageFlags.Ephemeral
|
||||||
var msgData = {}
|
});
|
||||||
var refData = {}
|
}
|
||||||
const quoteGuild = await client.guilds.fetch(refGuildId)
|
|
||||||
const quoteChannel = await quoteGuild.channels.fetch(refChannelId)
|
|
||||||
const quoteMessage = await quoteChannel.messages.fetch(refMessageId)
|
|
||||||
|
|
||||||
msgData = {
|
const { messageId, channelId, guildId } = message.reference;
|
||||||
|
|
||||||
|
let quoteMessage;
|
||||||
|
let quoteChannel;
|
||||||
|
let quoteGuild;
|
||||||
|
|
||||||
|
try {
|
||||||
|
quoteGuild = await client.guilds.fetch(guildId);
|
||||||
|
quoteChannel = await quoteGuild.channels.fetch(channelId);
|
||||||
|
quoteMessage = await quoteChannel.messages.fetch(messageId);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return message.reply({
|
||||||
|
content: "Unable to fetch the quoted message.",
|
||||||
|
flags: MessageFlags.Ephemeral
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const msgData = {
|
||||||
content: quoteMessage.content,
|
content: quoteMessage.content,
|
||||||
author: await quoteMessage.author,
|
author: quoteMessage.author,
|
||||||
reference: await quoteMessage.reference,
|
hasEmbed: quoteMessage.embeds.length > 0,
|
||||||
embed: await quoteMessage.embeds ? 'embed' : null
|
reference: quoteMessage.reference
|
||||||
} // debug
|
};
|
||||||
if (msgData.reference) {
|
|
||||||
const quoteRefGuild = await client.guilds.fetch(msgData.reference.guildId)
|
|
||||||
const quoteRefChannel = await quoteRefGuild.channels.fetch(msgData.reference.channelId)
|
|
||||||
const quoteRefMessage = await quoteRefChannel.messages.fetch(msgData.reference.messageId)
|
|
||||||
|
|
||||||
|
// Only populated if the quoted message is itself a reply.
|
||||||
|
let refData = null;
|
||||||
|
|
||||||
|
if (msgData.reference?.messageId) {
|
||||||
|
try {
|
||||||
|
const refGuild = await client.guilds.fetch(msgData.reference.guildId);
|
||||||
|
const refChannel = await refGuild.channels.fetch(msgData.reference.channelId);
|
||||||
|
const refMessage = await refChannel.messages.fetch(msgData.reference.messageId);
|
||||||
|
|
||||||
refData = {
|
refData = {
|
||||||
content: quoteRefMessage.content,
|
content: refMessage.content,
|
||||||
author: await quoteRefMessage.author,
|
author: refMessage.author,
|
||||||
embed: await quoteRefMessage.embeds.length > 0 ? 'embed' : null
|
hasEmbed: refMessage.embeds.length > 0
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
// Referenced message couldn't be fetched (deleted, inaccessible, etc.)
|
||||||
|
refData = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = mClient.db(process.env.M_DB)
|
const db = mClient.db(process.env.M_DB);
|
||||||
const quotesColl = db.collection('items_quotes')
|
const quotesColl = db.collection("items_quotes");
|
||||||
const found = await quotesColl.findOne({ messageID: quoteMessage.id })
|
|
||||||
if (found) { return await message.reply({ content: 'Quote Already in Database', flags: MessageFlags.Ephemeral }) }
|
const existing = await quotesColl.findOne({
|
||||||
await quotesColl.findOneAndUpdate({ messageID: quoteMessage.id }, {
|
messageID: quoteMessage.id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
return message.reply({
|
||||||
|
content: "Quote already exists in the database.",
|
||||||
|
flags: MessageFlags.Ephemeral
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await quotesColl.findOneAndUpdate(
|
||||||
|
{ messageID: quoteMessage.id },
|
||||||
|
{
|
||||||
$set: {
|
$set: {
|
||||||
messageID: quoteMessage.id,
|
messageID: quoteMessage.id,
|
||||||
channelID: quoteChannel.id,
|
channelID: quoteChannel.id,
|
||||||
@@ -48,29 +83,48 @@ module.exports = {
|
|||||||
userID: msgData.author.id,
|
userID: msgData.author.id,
|
||||||
count: 0
|
count: 0
|
||||||
}
|
}
|
||||||
}, { upsert: true })
|
},
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
|
||||||
var description = ''
|
const messageLink = `https://discord.com/channels/${quoteGuild.id}/${quoteChannel.id}/${quoteMessage.id}`;
|
||||||
|
|
||||||
|
let description = "";
|
||||||
|
|
||||||
|
// Only show the replied-to message if one actually exists.
|
||||||
if (refData) {
|
if (refData) {
|
||||||
description += `> ${refData.author}`
|
description += `> ${refData.author} `;
|
||||||
if (refData.embed) {
|
|
||||||
description += '*an embed / a command* '
|
if (refData.hasEmbed) {
|
||||||
|
description += "*an embed / a command*";
|
||||||
|
} else if (refData.content) {
|
||||||
|
description += refData.content;
|
||||||
} else {
|
} else {
|
||||||
description += refData.content
|
description += "*no text*";
|
||||||
}
|
}
|
||||||
description += `\r\n↳`
|
|
||||||
|
description += "\n↳ ";
|
||||||
}
|
}
|
||||||
const messageLink = `https://discord.com/channels/${quoteGuild.id}/${quoteChannel.id}/${quoteMessage.id}/`
|
|
||||||
description += `${msgData.author} ${msgData.content}\r\n\r\n${messageLink}`
|
description += `${msgData.author} `;
|
||||||
let timestamp = new Date(message.createdTimestamp)
|
|
||||||
let footer = timestamp.toDateString().toString()
|
if (msgData.hasEmbed && !msgData.content) {
|
||||||
|
description += "*an embed / a command*";
|
||||||
|
} else {
|
||||||
|
description += msgData.content || "*no text*";
|
||||||
|
}
|
||||||
|
|
||||||
|
description += `\n\n${messageLink}`;
|
||||||
|
|
||||||
|
const footer = `${new Date(quoteMessage.createdTimestamp).toDateString()} #${quoteMessage.id}`;
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setThumbnail(msgData.author.displayAvatarURL())
|
.setTitle("- Quote Added! -")
|
||||||
.setURL(messageLink)
|
.setURL(messageLink)
|
||||||
.setTitle(`- Quote Added! -`)
|
.setThumbnail(msgData.author.displayAvatarURL())
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.setFooter({ text: (footer + ' #' + quoteMessage.id) })
|
.setFooter({ text: footer });
|
||||||
await message.reply({ embeds: [embed] })
|
|
||||||
}
|
return message.reply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@@ -3,12 +3,12 @@ Random By Year?
|
|||||||
Counter (Leaderboard)
|
Counter (Leaderboard)
|
||||||
*/
|
*/
|
||||||
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder, MessageFlags } = require('discord.js')
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder, MessageFlags } = require('discord.js')
|
||||||
const { mClient } = require('../../../index')
|
const { mClient, client } = require('../../../index')
|
||||||
|
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
||||||
|
|
||||||
async function quotesAdd(interaction) {
|
async function quotesAdd(interaction) {
|
||||||
|
|
||||||
const messageLink = await interaction.options.getString('link')
|
const messageLink = await interaction.options.getString('link')
|
||||||
//regex for message link
|
//regex for message link
|
||||||
const regex = /^https:\/\/discord\.com\/channels\/\d+\/\d+\/\d+$/
|
const regex = /^https:\/\/discord\.com\/channels\/\d+\/\d+\/\d+$/
|
||||||
@@ -25,23 +25,26 @@ async function quotesAdd(interaction) {
|
|||||||
let channelID = temp[temp.length - 2]
|
let channelID = temp[temp.length - 2]
|
||||||
let guildID = temp[temp.length - 3]
|
let guildID = temp[temp.length - 3]
|
||||||
|
|
||||||
const guild = await interaction.client.guilds.fetch(guildID)
|
const guild = await client.guilds.fetch(guildID)
|
||||||
const channel = await guild.channels.fetch(channelID)
|
const channel = await guild.channels.fetch(channelID)
|
||||||
const message = await channel.messages.fetch(messageID)
|
const message = await channel.messages.fetch(messageID)
|
||||||
|
|
||||||
var msgData = {
|
let refData = null
|
||||||
|
|
||||||
|
let msgData = {
|
||||||
content: message.content,
|
content: message.content,
|
||||||
author: await message.author,
|
author: message.author,
|
||||||
reference: await message.reference,
|
reference: message.reference,
|
||||||
embed: await message.embeds ? 'embed' : null
|
embed: message.embeds.length > 0 ? 'embed' : null
|
||||||
} // debug
|
}
|
||||||
|
|
||||||
if (msgData.reference) {
|
if (msgData.reference) {
|
||||||
let refGuild = await interaction.client.guilds.fetch(msgData.reference.guildId)
|
let refGuild = await client.guilds.fetch(msgData.reference.guildId)
|
||||||
let refChannel = await refGuild.channels.fetch(msgData.reference.channelId)
|
let refChannel = await refGuild.channels.fetch(msgData.reference.channelId)
|
||||||
let refMessage = await refChannel.messages.fetch(msgData.reference.messageId)
|
let refMessage = await refChannel.messages.fetch(msgData.reference.messageId)
|
||||||
|
|
||||||
|
|
||||||
var refData = {
|
refData = {
|
||||||
content: refMessage.content,
|
content: refMessage.content,
|
||||||
author: await refMessage.author,
|
author: await refMessage.author,
|
||||||
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
||||||
@@ -104,16 +107,18 @@ async function quotesSearch(interaction) {
|
|||||||
if (!found) { return await interaction.reply({ content: 'ID not found!', flags: MessageFlags.Ephemeral }) }
|
if (!found) { return await interaction.reply({ content: 'ID not found!', flags: MessageFlags.Ephemeral }) }
|
||||||
|
|
||||||
|
|
||||||
const guild = await interaction.client.guilds.fetch(found.guildID)
|
const guild = await client.guilds.fetch(found.guildID)
|
||||||
const channel = await guild.channels.fetch(found.channelID)
|
const channel = await guild.channels.fetch(found.channelID)
|
||||||
const message = await channel.messages.fetch(found.messageID)
|
const message = await channel.messages.fetch(found.messageID)
|
||||||
|
|
||||||
var msgData = {
|
let refData = null
|
||||||
|
|
||||||
|
let msgData = {
|
||||||
content: message.content,
|
content: message.content,
|
||||||
author: await message.author,
|
author: message.author,
|
||||||
reference: await message.reference,
|
reference: message.reference,
|
||||||
embed: await message.embeds ? 'embed' : null
|
embed: message.embeds.length > 0 ? 'embed' : null
|
||||||
} // debug
|
}
|
||||||
|
|
||||||
quotesColl.findOneAndUpdate({
|
quotesColl.findOneAndUpdate({
|
||||||
messageID: found.messageID
|
messageID: found.messageID
|
||||||
@@ -123,9 +128,12 @@ async function quotesSearch(interaction) {
|
|||||||
upsert: true
|
upsert: true
|
||||||
})
|
})
|
||||||
|
|
||||||
if (msgData.reference) {
|
if (msgData.reference?.messageId) {
|
||||||
let refMessage = await channel.messages.fetch(msgData.reference.messageId)
|
let refGuild = await client.guilds.fetch(msgData.reference.guildId)
|
||||||
var refData = {
|
let refChannel = await refGuild.channels.fetch(msgData.reference.channelId)
|
||||||
|
let refMessage = await refChannel.messages.fetch(msgData.reference.messageId)
|
||||||
|
|
||||||
|
refData = {
|
||||||
content: refMessage.content,
|
content: refMessage.content,
|
||||||
author: await refMessage.author,
|
author: await refMessage.author,
|
||||||
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
||||||
@@ -178,16 +186,18 @@ async function quotesRandom(interaction) {
|
|||||||
}
|
}
|
||||||
const found = rdm[0]
|
const found = rdm[0]
|
||||||
if (!found) { return await interaction.reply({ content: 'No Entry Found.', flags: MessageFlags.Ephemeral }) }
|
if (!found) { return await interaction.reply({ content: 'No Entry Found.', flags: MessageFlags.Ephemeral }) }
|
||||||
const guild = await interaction.client.guilds.fetch(found.guildID)
|
const guild = await client.guilds.fetch(found.guildID)
|
||||||
const channel = await guild.channels.fetch(found.channelID)
|
const channel = await guild.channels.fetch(found.channelID)
|
||||||
const message = await channel.messages.fetch(found.messageID)
|
const message = await channel.messages.fetch(found.messageID)
|
||||||
|
|
||||||
var msgData = {
|
let refData = null
|
||||||
|
|
||||||
|
let msgData = {
|
||||||
content: message.content,
|
content: message.content,
|
||||||
author: await message.author,
|
author: message.author,
|
||||||
reference: await message.reference,
|
reference: message.reference,
|
||||||
embed: await message.embeds ? 'embed' : null
|
embed: message.embeds.length > 0 ? 'embed' : null
|
||||||
} // debug
|
}
|
||||||
|
|
||||||
quotesColl.findOneAndUpdate({
|
quotesColl.findOneAndUpdate({
|
||||||
messageID: found.messageID
|
messageID: found.messageID
|
||||||
@@ -197,9 +207,11 @@ async function quotesRandom(interaction) {
|
|||||||
upsert: true
|
upsert: true
|
||||||
})
|
})
|
||||||
|
|
||||||
if (msgData.reference) {
|
if (msgData.reference?.messageId) {
|
||||||
let refMessage = await channel.messages.fetch(msgData.reference.messageId)
|
let refGuild = await client.guilds.fetch(msgData.reference.guildId)
|
||||||
var refData = {
|
let refChannel = await refGuild.channels.fetch(msgData.reference.channelId)
|
||||||
|
let refMessage = await refChannel.messages.fetch(msgData.reference.messageId)
|
||||||
|
refData = {
|
||||||
content: refMessage.content,
|
content: refMessage.content,
|
||||||
author: await refMessage.author,
|
author: await refMessage.author,
|
||||||
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
embed: await refMessage.embeds.length > 0 ? 'embed' : null
|
||||||
@@ -295,7 +307,7 @@ async function quotesLeaderboard(interaction, page = 1, limit = 5) {
|
|||||||
return interaction.editReply({ content: 'No quotes found for this server yet!', components: [] });
|
return interaction.editReply({ content: 'No quotes found for this server yet!', components: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const guild = await interaction.client.guilds.fetch(interaction.guild.id);
|
const guild = await client.guilds.fetch(interaction.guild.id);
|
||||||
|
|
||||||
// Fetch all messages concurrently
|
// Fetch all messages concurrently
|
||||||
const fields = await Promise.all(
|
const fields = await Promise.all(
|
||||||
@@ -387,23 +399,23 @@ module.exports = {
|
|||||||
switch (interaction.options._subcommand) {
|
switch (interaction.options._subcommand) {
|
||||||
case 'add':
|
case 'add':
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
quotesAdd(interaction)
|
await quotesAdd(interaction)
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove':
|
||||||
quotesRemove(interaction)
|
awaitquotesRemove(interaction)
|
||||||
break;
|
break;
|
||||||
case 'search':
|
case 'search':
|
||||||
quotesSearch(interaction)
|
awaitquotesSearch(interaction)
|
||||||
break;
|
break;
|
||||||
case 'random':
|
case 'random':
|
||||||
quotesRandom(interaction)
|
awaitquotesRandom(interaction)
|
||||||
break;
|
break;
|
||||||
case 'leaderboard':
|
case 'leaderboard':
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
quotesLeaderboard(interaction)
|
awaitquotesLeaderboard(interaction)
|
||||||
break;
|
break;
|
||||||
case 'list':
|
case 'list':
|
||||||
quotesList(interaction)
|
await quotesList(interaction)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
+71
-50
@@ -59,55 +59,78 @@ async function selectMenuHandler(interaction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function modalSubmitHandler(interaction) {
|
async function modalSubmitHandler(interaction) {
|
||||||
if (interaction.customId === 'wgeBaseModal') {
|
if (interaction.customId !== 'wgeBaseModal') return;
|
||||||
const db = mClient.db('neo-db')
|
|
||||||
const wgeColl = db.collection('timer_wge')
|
|
||||||
const participateColl = db.collection('items_wge')
|
|
||||||
|
|
||||||
// Get the data entered by the user
|
const db = mClient.db('neo-db');
|
||||||
|
const wgeColl = db.collection('timer_wge');
|
||||||
|
const participateColl = db.collection('items_wge');
|
||||||
|
const historyWgeColl = db.collection('history_wge');
|
||||||
|
|
||||||
var wgeAssignedUser = {}
|
const assigningUser = interaction.user;
|
||||||
wgeAssignedUser.id = interaction.components[0].component.values[0]
|
const selectedUserId = interaction.components[0].component.values[0];
|
||||||
|
const topic = interaction.fields.getTextInputValue('wgeTopicInput');
|
||||||
|
const defaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||||
|
|
||||||
const wgeAssigningUser = interaction.user
|
// Get current running WGE so we can exclude the current expert
|
||||||
if (wgeAssignedUser.id === process.env.D_ID) {
|
const prevWge = await wgeColl.findOne({
|
||||||
// Randomizer Function
|
debug: false,
|
||||||
|
state: 'running'
|
||||||
|
});
|
||||||
|
|
||||||
|
let assignedUser;
|
||||||
|
|
||||||
|
// Random assignment
|
||||||
|
if (selectedUserId === process.env.D_ID) {
|
||||||
const randomParticipant = await participateColl.aggregate([
|
const randomParticipant = await participateColl.aggregate([
|
||||||
{ $match: { status: true } },
|
{
|
||||||
{ $sample: { size: 1 } }
|
$match: {
|
||||||
]).toArray()
|
status: true,
|
||||||
|
...(prevWge && {
|
||||||
if (!randomParticipant) { return interaction.followUp({ content: 'No User is participating!' }) }
|
userID: { $ne: prevWge.assignedUser }
|
||||||
|
|
||||||
random = await interaction.guild.members.fetch(randomParticipant[0].userID)
|
|
||||||
wgeAssignedUser = random.user
|
|
||||||
} else {
|
|
||||||
// validate non-random user
|
|
||||||
const foundParticipant = await participateColl.findOne({
|
|
||||||
$and: [
|
|
||||||
{ assignedUser: wgeAssignedUser.id },
|
|
||||||
{ status: true}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ $sample: { size: 1 } }
|
||||||
|
]).toArray();
|
||||||
|
|
||||||
if(!foundParticipant || foundParticipant == null){ return interaction.reply({
|
if (randomParticipant.length === 0) {
|
||||||
content: `<@${wgeAssignedUser.id}> is not participating!`,
|
return interaction.reply({
|
||||||
|
content: 'There are no eligible participants available.',
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
})}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const member = await interaction.guild.members.fetch(randomParticipant[0].userID);
|
||||||
|
assignedUser = member.user;
|
||||||
|
}
|
||||||
|
// Manual assignment
|
||||||
|
else {
|
||||||
|
const participant = await participateColl.findOne({
|
||||||
|
userID: selectedUserId,
|
||||||
|
status: true
|
||||||
|
});
|
||||||
|
|
||||||
const prevWge = await wgeColl.findOne({
|
if (!participant) {
|
||||||
$and: [
|
return interaction.reply({
|
||||||
{ debug: false },
|
content: `<@${selectedUserId}> is not participating!`,
|
||||||
{ state: 'running' }
|
flags: MessageFlags.Ephemeral
|
||||||
]
|
});
|
||||||
})
|
}
|
||||||
|
|
||||||
if (prevWge != null) {
|
if (prevWge && selectedUserId === prevWge.assignedUser) {
|
||||||
// Save previous run in history_wge
|
return interaction.reply({
|
||||||
const historyWgeColl = db.collection('history_wge')
|
content: `<@${selectedUserId}> was the previous expert and cannot be selected again this round.`,
|
||||||
|
flags: MessageFlags.Ephemeral
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
assignedUser = { id: selectedUserId };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Archive previous WGE
|
||||||
|
if (prevWge) {
|
||||||
await historyWgeColl.insertOne({
|
await historyWgeColl.insertOne({
|
||||||
assignedUser: prevWge.assignedUser,
|
assignedUser: prevWge.assignedUser,
|
||||||
assigningUser: prevWge.assigningUser,
|
assigningUser: prevWge.assigningUser,
|
||||||
@@ -118,25 +141,22 @@ async function modalSubmitHandler(interaction) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log({
|
console.log({
|
||||||
message: 'saved previous wge in history_wge',
|
message: 'Saved previous WGE to history_wge',
|
||||||
data: prevWge
|
data: prevWge
|
||||||
})
|
});
|
||||||
|
|
||||||
await wgeColl.deleteOne({
|
await wgeColl.deleteOne({
|
||||||
_id: prevWge._id
|
_id: prevWge._id
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const wgeAssignedTopic = interaction.fields.getTextInputValue('wgeTopicInput');
|
// Create new WGE
|
||||||
|
|
||||||
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
|
|
||||||
|
|
||||||
await wgeColl.insertOne({
|
await wgeColl.insertOne({
|
||||||
assignedUser: wgeAssignedUser.id,
|
assignedUser: assignedUser.id,
|
||||||
assigningUser: wgeAssigningUser.id,
|
assigningUser: assigningUser.id,
|
||||||
|
|
||||||
startedAt: Date.now(),
|
startedAt: Date.now(),
|
||||||
timeRemaining: wgeDefaultAssignedTime,
|
timeRemaining: defaultAssignedTime,
|
||||||
|
|
||||||
state: 'running',
|
state: 'running',
|
||||||
|
|
||||||
@@ -146,12 +166,13 @@ async function modalSubmitHandler(interaction) {
|
|||||||
complete: false
|
complete: false
|
||||||
},
|
},
|
||||||
|
|
||||||
topic: wgeAssignedTopic,
|
topic,
|
||||||
debug: false,
|
debug: false,
|
||||||
|
|
||||||
createdAt: new Date()
|
createdAt: new Date()
|
||||||
});
|
});
|
||||||
|
|
||||||
return interaction.reply({ content: `<@${wgeAssignedUser.id}> is the next expert! Their topic is **${wgeAssignedTopic}**` })
|
return interaction.reply({
|
||||||
}
|
content: `<@${assignedUser.id}> is the next expert! Their topic is **${topic}**`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
+50
-33
@@ -1,17 +1,23 @@
|
|||||||
const { Events, MessageFlags } = require('discord.js')
|
const { Events, MessageFlags } = require("discord.js");
|
||||||
require('dotenv').config()
|
require("dotenv").config();
|
||||||
const { client, mClient } = require('../index')
|
|
||||||
const prefix = process.env.D_Prefix
|
const { client, mClient } = require("../index");
|
||||||
const db = mClient.db(process.env.M_DB)
|
|
||||||
|
const prefix = process.env.D_Prefix;
|
||||||
|
const db = mClient.db(process.env.M_DB);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.MessageCreate,
|
name: Events.MessageCreate,
|
||||||
once: false,
|
once: false,
|
||||||
async execute(message) {
|
|
||||||
if (message.author.bot) { return }
|
|
||||||
|
|
||||||
// Erster/Zweiter/Dritter Handler
|
async execute(message) {
|
||||||
if (message.channelId === '353902391021535244' || message.channelId === '471058991481487361') {
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Daily number handler
|
||||||
|
* Only does something if Ersti/Zweiti/Dritti is detected.
|
||||||
|
*/
|
||||||
|
if (message.channelId === "353902391021535244") {
|
||||||
const numbered = {
|
const numbered = {
|
||||||
Erst: "Ersti",
|
Erst: "Ersti",
|
||||||
Zweit: "Zweiti",
|
Zweit: "Zweiti",
|
||||||
@@ -22,14 +28,13 @@ module.exports = {
|
|||||||
new RegExp(`\\b\\w*${stem}\\w*\\b`, "i").test(message.content)
|
new RegExp(`\\b\\w*${stem}\\w*\\b`, "i").test(message.content)
|
||||||
)?.[1];
|
)?.[1];
|
||||||
|
|
||||||
if (!found) return;
|
if (found) {
|
||||||
|
const numberedColl = db.collection("items_daily_numbers");
|
||||||
|
|
||||||
const numberedColl = db.collection('items_daily_numbers');
|
|
||||||
const today = new Date().toLocaleDateString("en-CA", {
|
const today = new Date().toLocaleDateString("en-CA", {
|
||||||
timeZone: "Europe/Berlin"
|
timeZone: "Europe/Berlin"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tages-Dokument sicherstellen
|
|
||||||
await numberedColl.findOneAndUpdate(
|
await numberedColl.findOneAndUpdate(
|
||||||
{ date: today },
|
{ date: today },
|
||||||
{
|
{
|
||||||
@@ -45,14 +50,10 @@ module.exports = {
|
|||||||
{ upsert: true }
|
{ upsert: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
// 🔒 Atomarer Claim:
|
|
||||||
// - Position muss frei sein
|
|
||||||
// - User darf noch keine Position heute haben
|
|
||||||
const result = await numberedColl.findOneAndUpdate(
|
const result = await numberedColl.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
date: today,
|
date: today,
|
||||||
[`positions.${found}`]: null,
|
[`positions.${found}`]: null,
|
||||||
|
|
||||||
"positions.Ersti.userId": { $ne: message.author.id },
|
"positions.Ersti.userId": { $ne: message.author.id },
|
||||||
"positions.Zweiti.userId": { $ne: message.author.id },
|
"positions.Zweiti.userId": { $ne: message.author.id },
|
||||||
"positions.Dritti.userId": { $ne: message.author.id }
|
"positions.Dritti.userId": { $ne: message.author.id }
|
||||||
@@ -65,39 +66,55 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ returnDocument: "after" }
|
{
|
||||||
|
returnDocument: "after"
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// ❌ bereits vergeben oder schon eine Position
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return message.reply({
|
await message.reply({
|
||||||
content: `❌ Du kannst pro Tag nur eine Position beanspruchen, und sie muss noch frei sein.`,
|
content:
|
||||||
|
"❌ Du kannst pro Tag nur eine Position beanspruchen, und sie muss noch frei sein.",
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
await message.reply({
|
||||||
// ✅ Erfolg
|
|
||||||
return message.reply({
|
|
||||||
content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
|
content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command Handler
|
// Only stop here if this was actually a number claim.
|
||||||
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command handler
|
||||||
|
*/
|
||||||
if (!message.content.startsWith(prefix)) return;
|
if (!message.content.startsWith(prefix)) return;
|
||||||
|
|
||||||
|
const args = message.content
|
||||||
|
.slice(prefix.length)
|
||||||
|
.trim()
|
||||||
|
.split(/ +/);
|
||||||
|
|
||||||
const cmd = args.shift().toLowerCase();
|
const cmd = args.shift().toLowerCase();
|
||||||
let command = client.legacyCommands.get(cmd)
|
|
||||||
|
|
||||||
|
let command = client.legacyCommands.get(cmd);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
command = client.aliases.get(cmd)
|
||||||
|
? client.legacyCommands.get(client.aliases.get(cmd))
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!command) return;
|
||||||
|
|
||||||
if (!command) command = client.legacyCommands.get(client.aliases.get(cmd))
|
|
||||||
if (!command) return
|
|
||||||
try {
|
try {
|
||||||
client.legacyCommands.get(command.name).execute(message, args)
|
await command.execute(message, args);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
+8
-1
@@ -20,8 +20,15 @@ module.exports = {
|
|||||||
const member = await getMember(client, timer.assignedUser);
|
const member = await getMember(client, timer.assignedUser);
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
|
|
||||||
|
console.log(`⚠️ Less than 24 hours remaining for ${member.user.username}, notifying...`)
|
||||||
|
|
||||||
|
try {
|
||||||
await member.send(
|
await member.send(
|
||||||
`⚠️ Less than 24 hours remaining for: **${timer.topic}**`
|
`⚠️ Less than 24 hours remaining for: **${timer.topic}**`
|
||||||
).catch(() => {});
|
)
|
||||||
|
console.log('notified successfully!')
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`notification failed, errorr ${e}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
+7
-1
@@ -20,8 +20,14 @@ module.exports = {
|
|||||||
const member = await getMember(client, timer.assignedUser);
|
const member = await getMember(client, timer.assignedUser);
|
||||||
if (!member) return;
|
if (!member) return;
|
||||||
|
|
||||||
|
console.log(`⏳ Half time reached for: ${member.user.username}, notifying...`)
|
||||||
|
try {
|
||||||
await member.send(
|
await member.send(
|
||||||
`⏳ Half time reached for: **${timer.topic}**`
|
`⏳ Half time reached for: **${timer.topic}**`
|
||||||
).catch(() => {});
|
)
|
||||||
|
console.log('notified successfully!')
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`notification failed, errorr ${e}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user