Gavrilskibidi

hi can i get help changing this index js

๐Ÿ“Ž 1 file 21,851 chars
๐Ÿ“„
pasted-code-1792073619097.txt
txt 555 lines
โ–ถ
const { 
  Client, 
  GatewayIntentBits, 
  ActionRowBuilder, 
  ButtonBuilder, 
  ButtonStyle, 
  EmbedBuilder, 
  ModalBuilder, 
  TextInputBuilder, 
  TextInputStyle, 
  StringSelectMenuBuilder, 
  StringSelectMenuOptionBuilder, 
  REST, 
  Routes, 
  SlashCommandBuilder, 
  PermissionFlagsBits 
} = require('discord.js');
const OpenAI = require('openai');
const http = require('http');

// Hardcoded Credentials
const DISCORD_TOKEN = '';
const CLIENT_ID = '1553141000614973511';
const OPENAI_API_KEY = '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';

// Web server to satisfy Render's port check for Web Services
const PORT = process.env.PORT || 10000;
http.createServer((req, res) => res.end('Screensharer Bot is active!')).listen(PORT, () => {
  console.log(`Port binding established on ${PORT}`);
});

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessages
  ]
});

const openai = new OpenAI({
  apiKey: OPENAI_API_KEY
});

// Configuration IDs
const CONFIG = {
  APP_CHANNEL_ID: '1553115004369117204',
  SSER_ROLE_ID: '1548202757213786122',
  REVIEWER_ROLES: ['1548202742328066058', '1553107658637053982']
};

const applicationDrafts = new Map();
const applicationHistory = new Map();

// Slash Command Registration
const commands = [
  new SlashCommandBuilder()
    .setName('setup-apply')
    .setDescription('Sends the Screensharer Application panel to this channel')
    .setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
].map(cmd => cmd.toJSON());

client.once('ready', async () => {
  console.log(`Logged in as ${client.user.tag}!`);
  
  const rest = new REST({ version: '10' }).setToken(DISCORD_TOKEN);
  try {
    console.log('Registering slash commands...');
    await rest.put(
      Routes.applicationCommands(CLIENT_ID),
      { body: commands }
    );
    console.log('Slash commands registered successfully.');
  } catch (err) {
    console.error('Failed to register slash commands:', err);
  }
});

// Execute /setup-apply
client.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand()) return;

  if (interaction.commandName === 'setup-apply') {
    const embed = new EmbedBuilder()
      .setTitle('๐Ÿ›ก๏ธ Screensharer Application')
      .setColor('#5865F2')
      .setDescription(
        '> Think you have what it takes to join the Screenshare (SSer) team?\n' +
        '> Click the button below to start your application process.\n\n' +
        '**Requirements & Info:**\n' +
        'โ€ข Make sure your Direct Messages (DMs) are open to receive the application outcome.\n' +
        'โ€ข You will answer technical questions across 4 short steps plus a region selection.\n' +
        'โ€ข Take your time and answer honestly.\n\n' +
        `*Target Role:* <@&${CONFIG.SSER_ROLE_ID}>`
      )
      .setFooter({ text: 'Screensharer Recruitment System' });

    const row = new ActionRowBuilder().addComponents(
      new ButtonBuilder()
        .setCustomId('app_start')
        .setLabel('Apply Now')
        .setEmoji('๐Ÿ“‹')
        .setStyle(ButtonStyle.Success)
    );

    await interaction.reply({ content: 'Application panel deployed!', ephemeral: true });
    await interaction.channel.send({ embeds: [embed], components: [row] });
  }
});

// Handle Buttons and Modals
client.on('interactionCreate', async (interaction) => {
  const userId = interaction.user.id;

  // 1. START APPLICATION BUTTON
  if (interaction.isButton() && interaction.customId === 'app_start') {
    applicationDrafts.set(userId, {});

    const modal = new ModalBuilder()
      .setCustomId('app_step_1')
      .setTitle('Page 1/4: General Questions');

    modal.addComponents(
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_injectable')
          .setLabel('What is an "injectable"?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_cheat_clients')
          .setLabel('Whats the most common cheat clients?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_hidden_cheats')
          .setLabel('How are cheats commonly hidden?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_previous_experience')
          .setLabel('SS staff in another server? If so, where?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      )
    );

    return await interaction.showModal(modal);
  }

  // 2. MODAL SUBMIT: STEP 1 -> STEP 2
  if (interaction.isModalSubmit() && interaction.customId === 'app_step_1') {
    const draft = applicationDrafts.get(userId) || {};
    draft.injectable = interaction.fields.getTextInputValue('q_injectable');
    draft.cheat_clients = interaction.fields.getTextInputValue('q_cheat_clients');
    draft.hidden_cheats = interaction.fields.getTextInputValue('q_hidden_cheats');
    draft.previous_experience = interaction.fields.getTextInputValue('q_previous_experience');
    applicationDrafts.set(userId, draft);

    const modal = new ModalBuilder()
      .setCustomId('app_step_2')
      .setTitle('Page 2/4: Event Viewer');

    modal.addComponents(
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_eventvwr')
          .setLabel('What is eventvwr?')
          .setStyle(TextInputStyle.Short)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_eventvwr_use')
          .setLabel('What would u use it for in forensic analysis?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_eventvwr_service')
          .setLabel('What service is it connected to?')
          .setStyle(TextInputStyle.Short)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_eventvwr_ids')
          .setLabel('What are the most relevant IDs looking at?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      )
    );

    return await interaction.showModal(modal);
  }

  // 3. MODAL SUBMIT: STEP 2 -> STEP 3
  if (interaction.isModalSubmit() && interaction.customId === 'app_step_2') {
    const draft = applicationDrafts.get(userId) || {};
    draft.eventvwr = interaction.fields.getTextInputValue('q_eventvwr');
    draft.eventvwr_use = interaction.fields.getTextInputValue('q_eventvwr_use');
    draft.eventvwr_service = interaction.fields.getTextInputValue('q_eventvwr_service');
    draft.eventvwr_ids = interaction.fields.getTextInputValue('q_eventvwr_ids');
    applicationDrafts.set(userId, draft);

    const modal = new ModalBuilder()
      .setCustomId('app_step_3')
      .setTitle('Page 3/4: Suspicious Files');

    modal.addComponents(
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_unopenable')
          .setLabel('If a suspicious file refuses to open?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_analyze')
          .setLabel('How would you analyze that file?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_tools')
          .setLabel('What tools would you use?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_illegitimate')
          .setLabel('What to look for to determine illegitimate?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      )
    );

    return await interaction.showModal(modal);
  }

  // 4. MODAL SUBMIT: STEP 3 -> STEP 4
  if (interaction.isModalSubmit() && interaction.customId === 'app_step_3') {
    const draft = applicationDrafts.get(userId) || {};
    draft.unopenable = interaction.fields.getTextInputValue('q_unopenable');
    draft.analyze = interaction.fields.getTextInputValue('q_analyze');
    draft.tools = interaction.fields.getTextInputValue('q_tools');
    draft.illegitimate = interaction.fields.getTextInputValue('q_illegitimate');
    applicationDrafts.set(userId, draft);

    const modal = new ModalBuilder()
      .setCustomId('app_step_4')
      .setTitle('Page 4/4: Replaces, Prefetch & Details');

    modal.addComponents(
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_replaces_types')
          .setLabel('Explains all types of replaces u know & reasons')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_replaces_detect')
          .setLabel('How to detect replaces?')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_prefetch')
          .setLabel('Prefetch artifact bypass methods & detection')
          .setStyle(TextInputStyle.Paragraph)
          .setRequired(true)
      ),
      new ActionRowBuilder().addComponents(
        new TextInputBuilder()
          .setCustomId('q_age')
          .setLabel('Your Age')
          .setStyle(TextInputStyle.Short)
          .setRequired(true)
      )
    );

    return await interaction.showModal(modal);
  }

  // 5. MODAL SUBMIT: STEP 4 -> REGION SELECT
  if (interaction.isModalSubmit() && interaction.customId === 'app_step_4') {
    const draft = applicationDrafts.get(userId) || {};
    draft.replaces_types = interaction.fields.getTextInputValue('q_replaces_types');
    draft.replaces_detect = interaction.fields.getTextInputValue('q_replaces_detect');
    draft.prefetch = interaction.fields.getTextInputValue('q_prefetch');
    draft.age = interaction.fields.getTextInputValue('q_age');
    applicationDrafts.set(userId, draft);

    const selectMenu = new StringSelectMenuBuilder()
      .setCustomId('app_region_select')
      .setPlaceholder('Select your Region')
      .addOptions(
        new StringSelectMenuOptionBuilder().setLabel('North America (NA)').setValue('NA').setEmoji('๐ŸŒŽ'),
        new StringSelectMenuOptionBuilder().setLabel('Europe (EU)').setValue('EU').setEmoji('๐ŸŒ')
      );

    const row = new ActionRowBuilder().addComponents(selectMenu);

    return await interaction.reply({
      content: 'Almost done! Select your region below to finish submitting your application:',
      components: [row],
      ephemeral: true
    });
  }

  // 6. REGION SELECT -> SUBMIT TO REVIEW CHANNEL
  if (interaction.isStringSelectMenu() && interaction.customId === 'app_region_select') {
    const region = interaction.values[0];
    const draft = applicationDrafts.get(userId);

    if (!draft) {
      return await interaction.reply({ content: 'Session expired. Please restart the application.', ephemeral: true });
    }

    draft.region = region;

    const appEmbed = new EmbedBuilder()
      .setTitle(`๐Ÿ“‹ Screensharer Application โ€” ${interaction.user.tag}`)
      .setThumbnail(interaction.user.displayAvatarURL({ dynamic: true }))
      .setColor('#2F3136')
      .setFields(
        { name: '๐Ÿ‘ค Applicant', value: `<@${userId}> (${userId})`, inline: true },
        { name: '๐ŸŽ‚ Age', value: draft.age, inline: true },
        { name: '๐ŸŒ Region', value: draft.region, inline: true },
        { name: '๐Ÿ’ฌ Previous SS Experience', value: draft.previous_experience },
        { name: '๐Ÿ’‰ Injectables', value: draft.injectable },
        { name: '๐ŸŽฎ Common Cheat Clients', value: draft.cheat_clients },
        { name: '๐Ÿ” How Cheats are Hidden', value: draft.hidden_cheats },
        { name: '๐Ÿ“Š Eventvwr', value: `**Def:** ${draft.eventvwr}\n**Use:** ${draft.eventvwr_use}\n**Service:** ${draft.eventvwr_service}\n**IDs:** ${draft.eventvwr_ids}` },
        { name: '๐Ÿ“ Suspicious Files', value: `**Refuses Open:** ${draft.unopenable}\n**Analysis:** ${draft.analyze}\n**Tools:** ${draft.tools}\n**Illegitimate:** ${draft.illegitimate}` },
        { name: '๐Ÿ”„ Replaces', value: `**Types & Reasons:** ${draft.replaces_types}\n**Detection:** ${draft.replaces_detect}` },
        { name: 'โšก Prefetch', value: draft.prefetch }
      )
      .setTimestamp()
      .setFooter({ text: `User ID: ${userId}` });

    const reviewButtons = new ActionRowBuilder().addComponents(
      new ButtonBuilder().setCustomId(`rev_accept_${userId}`).setLabel('Accept').setStyle(ButtonStyle.Success),
      new ButtonBuilder().setCustomId(`rev_deny_${userId}`).setLabel('Deny').setStyle(ButtonStyle.Danger),
      new ButtonBuilder().setCustomId(`rev_accept_reason_${userId}`).setLabel('Accept w/ Reason').setStyle(ButtonStyle.Primary),
      new ButtonBuilder().setCustomId(`rev_deny_reason_${userId}`).setLabel('Deny w/ Reason').setStyle(ButtonStyle.Secondary),
      new ButtonBuilder().setCustomId(`rev_ask_ai_${userId}`).setLabel('Ask AI').setStyle(ButtonStyle.Primary).setEmoji('๐Ÿค–'),
      new ButtonBuilder().setCustomId(`rev_history_${userId}`).setLabel('History').setStyle(ButtonStyle.Secondary).setEmoji('๐Ÿ“œ')
    );

    const appChannel = await client.channels.fetch(CONFIG.APP_CHANNEL_ID);
    await appChannel.send({ embeds: [appEmbed], components: [reviewButtons] });

    const userHist = applicationHistory.get(userId) || [];
    userHist.push({ date: new Date().toISOString().split('T')[0], status: 'Pending Review' });
    applicationHistory.set(userId, userHist);

    applicationDrafts.delete(userId);

    return await interaction.update({
      content: 'โœ… Your application has been submitted successfully! The SS staff team will review it shortly.',
      components: [],
      ephemeral: true
    });
  }

  // 7. REVIEW BUTTONS
  if (interaction.isButton() && interaction.customId.startsWith('rev_')) {
    const hasRole = interaction.member.roles.cache.some(r => CONFIG.REVIEWER_ROLES.includes(r.id));
    if (!hasRole && !interaction.member.permissions.has(PermissionFlagsBits.Administrator)) {
      return await interaction.reply({ content: 'โŒ You do not have permission to review applications.', ephemeral: true });
    }

    const [, action, targetUserId] = interaction.customId.match(/^rev_([a_z_]+)_(\d+)$/) || [];
    if (!action || !targetUserId) return;

    const guild = interaction.guild;
    const targetMember = await guild.members.fetch(targetUserId).catch(() => null);

    // ACCEPT
    if (action === 'accept') {
      if (targetMember) {
        await targetMember.roles.add(CONFIG.SSER_ROLE_ID).catch(() => null);
        await targetMember.send('๐ŸŽ‰ Congratulations! Your Screensharer Application has been **ACCEPTED**. Welcome to the team!').catch(() => null);
      }

      const updatedEmbed = EmbedBuilder.from(interaction.message.embeds[0])
        .setColor('#57F287')
        .addFields({ name: ' Outcome', value: `Accepted by <@${interaction.user.id}>` });

      await interaction.update({ embeds: [updatedEmbed], components: [] });
      
      const userHist = applicationHistory.get(targetUserId) || [];
      if (userHist.length) userHist[userHist.length - 1].status = 'Accepted';
    }

    // DENY
    if (action === 'deny') {
      if (targetMember) {
        await targetMember.send('โŒ Hello, your Screensharer Application has been **DENIED** after review. You may reapply in the future.').catch(() => null);
      }

      const updatedEmbed = EmbedBuilder.from(interaction.message.embeds[0])
        .setColor('#ED4245')
        .addFields({ name: ' Outcome', value: `Denied by <@${interaction.user.id}>` });

      await interaction.update({ embeds: [updatedEmbed], components: [] });

      const userHist = applicationHistory.get(targetUserId) || [];
      if (userHist.length) userHist[userHist.length - 1].status = 'Denied';
    }

    // ACCEPT WITH REASON
    if (action === 'accept_reason') {
      const modal = new ModalBuilder()
        .setCustomId(`rev_modal_accept_${targetUserId}`)
        .setTitle('Accept with Custom Reason');

      modal.addComponents(
        new ActionRowBuilder().addComponents(
          new TextInputBuilder()
            .setCustomId('reason')
            .setLabel('Acceptance Reason / Notes')
            .setStyle(TextInputStyle.Paragraph)
            .setRequired(true)
        )
      );

      return await interaction.showModal(modal);
    }

    // DENY WITH REASON
    if (action === 'deny_reason') {
      const modal = new ModalBuilder()
        .setCustomId(`rev_modal_deny_${targetUserId}`)
        .setTitle('Deny with Custom Reason');

      modal.addComponents(
        new ActionRowBuilder().addComponents(
          new TextInputBuilder()
            .setCustomId('reason')
            .setLabel('Rejection Reason')
            .setStyle(TextInputStyle.Paragraph)
            .setRequired(true)
        )
      );

      return await interaction.showModal(modal);
    }

    // ASK AI
    if (action === 'ask_ai') {
      await interaction.deferReply({ ephemeral: true });

      const fields = interaction.message.embeds[0].fields;
      const appContent = fields.map(f => `${f.name}:${f.value}`).join('\n\n');

      try {
        const prompt = `You are an expert Minecraft forensic screenshare auditor reviewing a staff application. Analyze the following responses for:
1. Probability of being AI-generated (0-100%).
2. Technical correctness regarding Windows forensics, eventvwr, prefetch, and cheat detection.
3. Concise recommendation (Accept or Deny).

Application Content:
${appContent}`;

        const response = await openai.chat.completions.create({
          model: 'gpt-4o-mini',
          messages: [{ role: 'user', content: prompt }],
          max_tokens: 500
        });

        const aiAnalysis = response.choices[0].message.content;

        const aiEmbed = new EmbedBuilder()
          .setTitle('๐Ÿค– AI Forensic & Authenticity Review')
          .setColor('#EB459E')
          .setDescription(aiAnalysis)
          .setFooter({ text: 'Visible only to reviewers' });

        return await interaction.editReply({ embeds: [aiEmbed] });
      } catch (err) {
        console.error('AI Error:', err);
        return await interaction.editReply({ content: 'โš ๏ธ Failed to connect to OpenAI API for evaluation.' });
      }
    }

    // HISTORY
    if (action === 'history') {
      const userHist = applicationHistory.get(targetUserId) || [];
      if (userHist.length === 0) {
        return await interaction.reply({ content: '๐Ÿ“œ No prior application history found for this user.', ephemeral: true });
      }

      const historyText = userHist.map((h, i) => `**#${i + 1}** โ€”${h.date} | Status: \`${h.status}\``).join('\n');
      return await interaction.reply({
        content: `๐Ÿ“œ **Application History for <@${targetUserId}>:**\n${historyText}`,
        ephemeral: true
      });
    }
  }

  // 8. REASON MODAL SUBMITS
  if (interaction.isModalSubmit() && interaction.customId.startsWith('rev_modal_')) {
    const [, modalAction, targetUserId] = interaction.customId.match(/^rev_modal_([a_z_]+)_(\d+)$/) || [];
    const reason = interaction.fields.getTextInputValue('reason');
    const guild = interaction.guild;
    const targetMember = await guild.members.fetch(targetUserId).catch(() => null);

    if (modalAction === 'accept') {
      if (targetMember) {
        await targetMember.roles.add(CONFIG.SSER_ROLE_ID).catch(() => null);
        await targetMember.send(`๐ŸŽ‰ Congratulations! Your Screensharer Application has been **ACCEPTED**.\n\n**Reason / Note:** ${reason}`).catch(() => null);
      }

      const updatedEmbed = EmbedBuilder.from(interaction.message.embeds[0])
        .setColor('#57F287')
        .addFields(
          { name: ' Outcome', value: `Accepted by <@${interaction.user.id}>` },
          { name: '๐Ÿ“ Reason', value: reason }
        );

      await interaction.update({ embeds: [updatedEmbed], components: [] });
    }

    if (modalAction === 'deny') {
      if (targetMember) {
        await targetMember.send(`โŒ Your Screensharer Application has been **DENIED**.\n\n**Reason:** ${reason}`).catch(() => null);
      }

      const updatedEmbed = EmbedBuilder.from(interaction.message.embeds[0])
        .setColor('#ED4245')
        .addFields(
          { name: ' Outcome', value: `Denied by <@${interaction.user.id}>` },
          { name: '๐Ÿ“ Reason', value: reason }
        );

      await interaction.update({ embeds: [updatedEmbed], components: [] });
    }
  }
});

client.login(DISCORD_TOKEN);
Kodari AI
KodariOct 15 at 2:14 pm 1
ScreensharerBot
A Discord bot that manages a multi-step staff application process for a screenshare (SSer) team. It features a four-page modal-based questionnaire covering technical forensics topics, region selection, and automated submission to a review channel. Reviewers can accept, deny, or provide custom reasons, with optional AI-powered analysis of applicant responses for authenticity and technical accuracy. The bot tracks application history and manages role assignments.

Yes. First, the pasted file contains a Discord bot token and an OpenAI API key. Revoke and replace both nowโ€”the Discord token in the Developer Portal, and the OpenAI key in your OpenAI account. Then store replacements in .env rather than in index.js.

What would you like changed in the bot? Describe the behavior you want, and I can update the file.

Kodari can make mistakes. Review important code before using.
Files

No files in this session

Code