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
+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);
}
}
}
};