mobile update

This commit is contained in:
2026-08-11 12:30:43 +02:00
parent 878e8fcdaa
commit c99a96c201
6 changed files with 373 additions and 256 deletions
+104 -83
View File
@@ -59,99 +59,120 @@ async function selectMenuHandler(interaction) {
}
}
}
async function modalSubmitHandler(interaction) {
if (interaction.customId === 'wgeBaseModal') {
const db = mClient.db('neo-db')
const wgeColl = db.collection('timer_wge')
const participateColl = db.collection('items_wge')
if (interaction.customId !== 'wgeBaseModal') return;
// 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 = {}
wgeAssignedUser.id = interaction.components[0].component.values[0]
const assigningUser = interaction.user;
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
if (wgeAssignedUser.id === process.env.D_ID) {
// Randomizer Function
const randomParticipant = await participateColl.aggregate([
{ $match: { status: true } },
{ $sample: { size: 1 } }
]).toArray()
// Get current running WGE so we can exclude the current expert
const prevWge = await wgeColl.findOne({
debug: false,
state: 'running'
});
if (!randomParticipant) { return interaction.followUp({ content: 'No User is participating!' }) }
let 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}
]
})
if(!foundParticipant || foundParticipant == null){ return interaction.reply({
content: `<@${wgeAssignedUser.id}> is not participating!`,
flags: MessageFlags.Ephemeral
})}
}
const prevWge = await wgeColl.findOne({
$and: [
{ debug: false },
{ state: 'running' }
]
})
if (prevWge != null) {
// Save previous run in history_wge
const historyWgeColl = db.collection('history_wge')
await historyWgeColl.insertOne({
assignedUser: prevWge.assignedUser,
assigningUser: prevWge.assigningUser,
timeRemaining: prevWge.timeRemaining,
topic: prevWge.topic,
debug: prevWge.debug,
createdAt: prevWge.createdAt
});
console.log({
message: 'saved previous wge in history_wge',
data: prevWge
})
await wgeColl.deleteOne({
_id: prevWge._id
})
}
const wgeAssignedTopic = interaction.fields.getTextInputValue('wgeTopicInput');
const wgeDefaultAssignedTime = 7 * 24 * 60 * 60 * 1000; // 7 days in ms
await wgeColl.insertOne({
assignedUser: wgeAssignedUser.id,
assigningUser: wgeAssigningUser.id,
startedAt: Date.now(),
timeRemaining: wgeDefaultAssignedTime,
state: 'running',
notifications: {
half: false,
day24: false,
complete: false
// Random assignment
if (selectedUserId === process.env.D_ID) {
const randomParticipant = await participateColl.aggregate([
{
$match: {
status: true,
...(prevWge && {
userID: { $ne: prevWge.assignedUser }
})
}
},
{ $sample: { size: 1 } }
]).toArray();
topic: wgeAssignedTopic,
debug: false,
if (randomParticipant.length === 0) {
return interaction.reply({
content: 'There are no eligible participants available.',
flags: MessageFlags.Ephemeral
});
}
createdAt: new Date()
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
});
return interaction.reply({ content: `<@${wgeAssignedUser.id}> is the next expert! Their topic is **${wgeAssignedTopic}**` })
if (!participant) {
return interaction.reply({
content: `<@${selectedUserId}> is not participating!`,
flags: MessageFlags.Ephemeral
});
}
if (prevWge && selectedUserId === prevWge.assignedUser) {
return interaction.reply({
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({
assignedUser: prevWge.assignedUser,
assigningUser: prevWge.assigningUser,
timeRemaining: prevWge.timeRemaining,
topic: prevWge.topic,
debug: prevWge.debug,
createdAt: prevWge.createdAt
});
console.log({
message: 'Saved previous WGE to history_wge',
data: prevWge
});
await wgeColl.deleteOne({
_id: prevWge._id
});
}
// Create new WGE
await wgeColl.insertOne({
assignedUser: assignedUser.id,
assigningUser: assigningUser.id,
startedAt: Date.now(),
timeRemaining: defaultAssignedTime,
state: 'running',
notifications: {
half: false,
day24: false,
complete: false
},
topic,
debug: false,
createdAt: new Date()
});
return interaction.reply({
content: `<@${assignedUser.id}> is the next expert! Their topic is **${topic}**`
});
}
+92 -75
View File
@@ -1,17 +1,23 @@
const { Events, MessageFlags } = require('discord.js')
require('dotenv').config()
const { client, mClient } = require('../index')
const prefix = process.env.D_Prefix
const db = mClient.db(process.env.M_DB)
const { Events, MessageFlags } = require("discord.js");
require("dotenv").config();
const { client, mClient } = require("../index");
const prefix = process.env.D_Prefix;
const db = mClient.db(process.env.M_DB);
module.exports = {
name: Events.MessageCreate,
once: false,
async execute(message) {
if (message.author.bot) { return }
// Erster/Zweiter/Dritter Handler
if (message.channelId === '353902391021535244' || message.channelId === '471058991481487361') {
async execute(message) {
if (message.author.bot) return;
/*
* Daily number handler
* Only does something if Ersti/Zweiti/Dritti is detected.
*/
if (message.channelId === "353902391021535244") {
const numbered = {
Erst: "Ersti",
Zweit: "Zweiti",
@@ -22,82 +28,93 @@ module.exports = {
new RegExp(`\\b\\w*${stem}\\w*\\b`, "i").test(message.content)
)?.[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", {
timeZone: "Europe/Berlin"
});
// Tages-Dokument sicherstellen
await numberedColl.findOneAndUpdate(
{ date: today },
{
$setOnInsert: {
date: today,
positions: {
Ersti: null,
Zweiti: null,
Dritti: null
}
}
},
{ upsert: true }
);
// 🔒 Atomarer Claim:
// - Position muss frei sein
// - User darf noch keine Position heute haben
const result = await numberedColl.findOneAndUpdate(
{
date: today,
[`positions.${found}`]: null,
"positions.Ersti.userId": { $ne: message.author.id },
"positions.Zweiti.userId": { $ne: message.author.id },
"positions.Dritti.userId": { $ne: message.author.id }
},
{
$set: {
[`positions.${found}`]: {
userId: message.author.id,
timestamp: new Date()
}
}
},
{ returnDocument: "after" }
);
// ❌ bereits vergeben oder schon eine Position
if (!result) {
return message.reply({
content: `❌ Du kannst pro Tag nur eine Position beanspruchen, und sie muss noch frei sein.`,
flags: MessageFlags.Ephemeral
const today = new Date().toLocaleDateString("en-CA", {
timeZone: "Europe/Berlin"
});
}
// ✅ Erfolg
return message.reply({
content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
flags: MessageFlags.Ephemeral
});
await numberedColl.findOneAndUpdate(
{ date: today },
{
$setOnInsert: {
date: today,
positions: {
Ersti: null,
Zweiti: null,
Dritti: null
}
}
},
{ upsert: true }
);
const result = await numberedColl.findOneAndUpdate(
{
date: today,
[`positions.${found}`]: null,
"positions.Ersti.userId": { $ne: message.author.id },
"positions.Zweiti.userId": { $ne: message.author.id },
"positions.Dritti.userId": { $ne: message.author.id }
},
{
$set: {
[`positions.${found}`]: {
userId: message.author.id,
timestamp: new Date()
}
}
},
{
returnDocument: "after"
}
);
if (!result) {
await message.reply({
content:
"❌ Du kannst pro Tag nur eine Position beanspruchen, und sie muss noch frei sein.",
flags: MessageFlags.Ephemeral
});
} else {
await message.reply({
content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
flags: MessageFlags.Ephemeral
});
}
// Only stop here if this was actually a number claim.
return;
}
}
// Command Handler
const args = message.content.slice(prefix.length).trim().split(/ +/);
/*
* Command handler
*/
if (!message.content.startsWith(prefix)) return;
const args = message.content
.slice(prefix.length)
.trim()
.split(/ +/);
const cmd = args.shift().toLowerCase();
let command = client.legacyCommands.get(cmd)
let command = client.legacyCommands.get(cmd);
if (!command) command = client.legacyCommands.get(client.aliases.get(cmd))
if (!command) return
try {
client.legacyCommands.get(command.name).execute(message, args)
} catch (error) {
console.error(error)
if (!command) {
command = client.aliases.get(cmd)
? client.legacyCommands.get(client.aliases.get(cmd))
: null;
}
if (!command) return;
try {
await command.execute(message, args);
} catch (error) {
console.error(error);
}
}
}
};
+10 -3
View File
@@ -20,8 +20,15 @@ module.exports = {
const member = await getMember(client, timer.assignedUser);
if (!member) return;
await member.send(
`⚠️ Less than 24 hours remaining for: **${timer.topic}**`
).catch(() => {});
console.log(`⚠️ Less than 24 hours remaining for ${member.user.username}, notifying...`)
try {
await member.send(
`⚠️ Less than 24 hours remaining for: **${timer.topic}**`
)
console.log('notified successfully!')
} catch (e) {
console.error(`notification failed, errorr ${e}`)
}
}
};
+8 -2
View File
@@ -20,8 +20,14 @@ module.exports = {
const member = await getMember(client, timer.assignedUser);
if (!member) return;
await member.send(
console.log(`⏳ Half time reached for: ${member.user.username}, notifying...`)
try {
await member.send(
`⏳ Half time reached for: **${timer.topic}**`
).catch(() => {});
)
console.log('notified successfully!')
} catch (e) {
console.error(`notification failed, errorr ${e}`)
}
}
};