AeThex-Bot-Master/aethex-bot/commands/afk.js
sirpiglr c2a34f398e Add server mode configuration and dynamic status updates
Introduces a new server mode configuration system (Federation/Standalone) with associated command changes, dynamic status rotation for the bot, and adds new commands and features.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: b08e6ba5-7498-4b9f-b1c9-7dc11b362ddd
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/R9PkDi8
Replit-Helium-Checkpoint-Created: true
2025-12-09 23:26:33 +00:00

96 lines
3 KiB
JavaScript

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getServerMode, getEmbedColor } = require('../utils/modeHelper');
const afkUsers = new Map();
module.exports = {
data: new SlashCommandBuilder()
.setName('afk')
.setDescription('Set your AFK status')
.addStringOption(option =>
option.setName('reason')
.setDescription('Reason for being AFK')
.setRequired(false)
.setMaxLength(200)
),
afkUsers,
async execute(interaction, supabase, client) {
const reason = interaction.options.getString('reason') || 'AFK';
const userId = interaction.user.id;
const guildId = interaction.guildId;
const mode = await getServerMode(supabase, interaction.guildId);
if (afkUsers.has(`${guildId}-${userId}`)) {
afkUsers.delete(`${guildId}-${userId}`);
const embed = new EmbedBuilder()
.setColor(0x22C55E)
.setTitle('👋 Welcome Back!')
.setDescription('Your AFK status has been removed.')
.setTimestamp();
return interaction.reply({ embeds: [embed], ephemeral: true });
}
afkUsers.set(`${guildId}-${userId}`, {
reason,
timestamp: Date.now(),
username: interaction.user.username
});
const embed = new EmbedBuilder()
.setColor(getEmbedColor(mode))
.setTitle('💤 AFK Status Set')
.setDescription(`You are now AFK: **${reason}**`)
.addFields({
name: '💡 Tip',
value: 'Use `/afk` again or send a message to remove your AFK status.'
})
.setTimestamp();
await interaction.reply({ embeds: [embed] });
},
checkAfk(message) {
const guildId = message.guildId;
const userId = message.author.id;
const key = `${guildId}-${userId}`;
if (afkUsers.has(key)) {
const afkData = afkUsers.get(key);
afkUsers.delete(key);
const duration = Math.floor((Date.now() - afkData.timestamp) / 1000);
let timeStr;
if (duration < 60) timeStr = `${duration} seconds`;
else if (duration < 3600) timeStr = `${Math.floor(duration / 60)} minutes`;
else timeStr = `${Math.floor(duration / 3600)} hours`;
message.reply({
content: `👋 Welcome back! You were AFK for ${timeStr}.`,
allowedMentions: { repliedUser: false }
}).catch(() => {});
}
const mentions = message.mentions.users;
mentions.forEach(user => {
const mentionKey = `${guildId}-${user.id}`;
if (afkUsers.has(mentionKey)) {
const afkData = afkUsers.get(mentionKey);
const ago = Math.floor((Date.now() - afkData.timestamp) / 1000);
let timeStr;
if (ago < 60) timeStr = `${ago} seconds ago`;
else if (ago < 3600) timeStr = `${Math.floor(ago / 60)} minutes ago`;
else timeStr = `${Math.floor(ago / 3600)} hours ago`;
message.reply({
content: `💤 **${afkData.username}** is AFK: ${afkData.reason} (set ${timeStr})`,
allowedMentions: { repliedUser: false }
}).catch(() => {});
}
});
}
};