// commands/lawcodes.js const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); // Mapping: short code -> full name const lawCodeMapping = { BPC: 'Business and Professions Code', CIV: 'Civil Code', CCP: 'Code of Civil Procedure', COM: 'Commercial Code', CORP: 'Corporations Code', EDC: 'Education Code', ELEC: 'Elections Code', EVID: 'Evidence Code', FAM: 'Family Code', FIN: 'Financial Code', FGC: 'Fish and Game Code', GOV: 'Government Code', HSC: 'Health and Safety Code', INS: 'Insurance Code', LAB: 'Labor Code', MVC: 'Military and Veterans Code', PEN: 'Penal Code', PRC: 'Public Resources Code', PUC: 'Public Utilities Code', RTC: 'Revenue and Taxation Code', SHC: 'Street and Highway Code', UIC: 'Unemployment Insurance Code', VEH: 'Vehicle Code', WIC: 'Welfare and Institutions Code' }; module.exports = { data: new SlashCommandBuilder() .setName('lawcodes') .setDescription('Get a link to a California law code section in a nicely formatted embed.') .addStringOption(option => option.setName('code') .setDescription('Choose a law code by its full name.') .setRequired(true) .addChoices( { name: 'Business and Professions Code', value: 'BPC' }, { name: 'Civil Code', value: 'CIV' }, { name: 'Code of Civil Procedure', value: 'CCP' }, { name: 'Commercial Code', value: 'COM' }, { name: 'Corporations Code', value: 'CORP' }, { name: 'Education Code', value: 'EDC' }, { name: 'Elections Code', value: 'ELEC' }, { name: 'Evidence Code', value: 'EVID' }, { name: 'Family Code', value: 'FAM' }, { name: 'Financial Code', value: 'FIN' }, { name: 'Fish and Game Code', value: 'FGC' }, { name: 'Government Code', value: 'GOV' }, { name: 'Health and Safety Code', value: 'HSC' }, { name: 'Insurance Code', value: 'INS' }, { name: 'Labor Code', value: 'LAB' }, { name: 'Military and Veterans Code', value: 'MVC' }, { name: 'Penal Code', value: 'PEN' }, { name: 'Public Resources Code', value: 'PRC' }, { name: 'Public Utilities Code', value: 'PUC' }, { name: 'Revenue and Taxation Code', value: 'RTC' }, { name: 'Street and Highway Code', value: 'SHC' }, { name: 'Unemployment Insurance Code', value: 'UIC' }, { name: 'Vehicle Code', value: 'VEH' }, { name: 'Welfare and Institutions Code', value: 'WIC' } ) ) .addStringOption(option => option.setName('section') .setDescription('The section number to look up.') .setRequired(true) ), async execute(interaction) { const shortCode = interaction.options.getString('code'); const section = interaction.options.getString('section'); const fullName = lawCodeMapping[shortCode]; // Get full name from mapping const url = `https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?sectionNum= ${encodeURIComponent(section)}&lawCode=${encodeURIComponent(shortCode)}`; const lawEmbed = new EmbedBuilder() .setColor(0x0099FF) .setTitle(`โš–๏ธ ${fullName} ยง${section}`) .setURL(url) .setAuthor({ name: 'California Law Code', iconURL: interaction.client.user.displayAvatarURL(), url: 'https://leginfo.legislature.ca.gov/ ' }) .setDescription( `**๐Ÿ“˜ Law Code:** ${fullName}\n` + `**๐Ÿ”ข Section:** ${section}\n\n` + `- *Be aware that if the code is not found, it may be due to a typo or the section not existing. Please double-check the code and section number.*` ) .setTimestamp() .setFooter({ text: 'Gas Station Support', iconURL: interaction.client.user.displayAvatarURL() }); await interaction.reply({ embeds: [lawEmbed] }); } };