Files
configManager.js
index.js
package.json
phoneCore.js
phoneSetup.js
schemas.js
Code
6 1,309
index.js
require('dotenv').config();
const {
Client,
GatewayIntentBits,
Partials,
SlashCommandBuilder
} = require('discord.js');
const mongoose = require('mongoose');
const { handleConfigInteraction, requirePhoneRole, requirePoliceRole } = require('./configManager');
const { handleCoreCommand, handleCoreInteraction, onVoiceStateUpdate } = require('./phoneCore');
const { handlePhoneInteraction, handlePhoneModalAction, openPhone } = require('./phoneSetup');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages],
partials: [Partials.Channel]
});
const commands = [
new SlashCommandBuilder().setName('phone').setDescription('Open or set up your private roleplay phone'),
new SlashCommandBuilder().setName('phone-charge').setDescription('Recharge your phone using a Power Bank'),
new SlashCommandBuilder().setName('call').setDescription('Call a registered phone number')
.addStringOption(option => option.setName('number').setDescription('Phone number, e.g. 555-4821').setRequired(true)),
new SlashCommandBuilder().setName('911').setDescription('Send an emergency dispatch')
.addStringOption(option => option.setName('location').setDescription('Incident location (you will confirm it in a private form)').setRequired(false))
.addStringOption(option => option.setName('incident').setDescription('Incident type').setRequired(false)),
new SlashCommandBuilder().setName('police').setDescription('Law-enforcement phone tools')
.addSubcommand(command => command.setName('wiretap').setDescription('Activate a wiretap on a SIM').addStringOption(option => option.setName('number').setDescription('Target number, e.g. 555-4821').setRequired(true)))
.addSubcommand(command => command.setName('trace').setDescription('Trace a SIM or active call').addStringOption(option => option.setName('number').setDescription('Target number, e.g. 555-4821').setRequired(true)))
.addSubcommand(command => command.setName('cyber-trace').setDescription('Bypass VPN masking and identify a SIM').addStringOption(option => option.setName('number').setDescription('Target number, e.g. 555-4821').setRequired(true))),
new SlashCommandBuilder().setName('burnersim').setDescription('Destroy the active burner SIM')
.addSubcommand(command => command.setName('snap').setDescription('Destroy the SIM and erase associated communications')),
new SlashCommandBuilder().setName('phone-config').setDescription('Configure phone roles and private audit/dispatch logs')
].map(command => command.toJSON());
client.once('clientReady', async () => {
try {
await client.application.commands.set(commands);
console.log(`Bot is ready! Logged in as ${client.user.tag}`);
console.log('KODARI_READY');
} catch (error) {
console.error('Failed to register slash commands:', error);
process.exitCode = 1;
}
});
client.on('interactionCreate', async interaction => {
try {
if (await handleConfigInteraction(interaction)) return;
if (interaction.isChatInputCommand()) {
if (interaction.commandName === 'phone-config') return;
if (!await requirePhoneRole(interaction)) return;
if (interaction.commandName === 'police' && !await requirePoliceRole(interaction)) return;
if (interaction.commandName === 'phone') return await openPhone(interaction);
return await handleCoreCommand(interaction);
}
if (interaction.isModalSubmit()) {
if (interaction.customId.startsWith('phone:')) {
if (!await requirePhoneRole(interaction)) return;
if (await handlePhoneModalAction(interaction)) return;
return await handlePhoneInteraction(interaction);
}
if (interaction.customId.startsWith('core:911:')) {
if (!await requirePhoneRole(interaction)) return;
return await handleCoreInteraction(interaction);
}
return;
}
if (interaction.isButton() || interaction.isStringSelectMenu()) {
if (interaction.customId.startsWith('phone:')) {
if (!await requirePhoneRole(interaction)) return;
return await handlePhoneInteraction(interaction);
}
if (interaction.customId.startsWith('call:')) return await handleCoreInteraction(interaction);
if (interaction.customId.startsWith('dispatch:')) return await handleCoreInteraction(interaction);
}
} catch (error) {
console.error('Interaction handler failed:', error);
const payload = { content: '❌ Something went wrong while processing that phone action. Please try again.', ephemeral: true };
if (interaction.deferred || interaction.replied) {
await interaction.followUp(payload).catch(() => {});
} else {
await interaction.reply(payload).catch(() => {});
}
}
});
client.on('voiceStateUpdate', (oldState, newState) => {
onVoiceStateUpdate(oldState, newState).catch(error => console.error('Voice call cleanup failed:', error));
});
client.on('error', error => console.error('Discord client error:', error));
client.on('shardError', error => console.error('Discord gateway shard error:', error));
process.on('unhandledRejection', error => console.error('Unhandled promise rejection:', error));
async function start() {
if (!process.env.DISCORD_TOKEN) throw new Error('DISCORD_TOKEN is missing. Add it to the project environment.');
if (!process.env.MONGODB_URI) throw new Error('MONGODB_URI is missing. Add it to the project environment.');
await mongoose.connect(process.env.MONGODB_URI);
console.log('MongoDB connected.');
await client.login(process.env.DISCORD_TOKEN);
}
start().catch(error => {
console.error('Bot startup failed:', error);
process.exit(1);
});