From d078d12a7959655a1f17dc0194991b78658fc099 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sat, 1 Apr 2023 11:29:41 -0500 Subject: [PATCH] added listPhrases --- abbreviation_key.json | 2 +- commands/listPhrases.ts | 14 ++++++++++++++ commands/removePhrase.ts | 13 ++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 commands/listPhrases.ts diff --git a/abbreviation_key.json b/abbreviation_key.json index 7bd4bcb..5204363 100644 --- a/abbreviation_key.json +++ b/abbreviation_key.json @@ -1 +1 @@ -{"target_phrases":{"idk":"I don't know","hoco":"homecoming","bbl":"be back later","bbg":"baby girl","mb":"my bad","mfw":"my face when","tfw":"that face when","ebr":"East Baton Rouge","ttyl":"talk to you later","ab":"about","w":"with","abt":"about","dk":"don't know","prolly":"probably","tbh":"to be honest","smh":"shaking my head","btw":"by the way","ngl":"not gonna lie","fr":"for real","yessss":"yes","bc":"because","u":"you","thru":"through","lmao":"laughing my ass off","tldr":"too long; didn't read","tl;dr":"too long; didn't read","ofc":"of course","linux":"GNU/Linux","xfl":"Extreme Football League","bi":"bisexual","abbr":"abbreviation","jk":"just kidding","gm":"good morning","mc":"Minecraft"}} \ No newline at end of file +{"target_phrases":{"idk":"I don't know","hoco":"homecoming","bbl":"be back later","bbg":"baby girl","mb":"my bad","mfw":"my face when","tfw":"that face when","ebr":"East Baton Rouge","ttyl":"talk to you later","ab":"about","abt":"about","dk":"don't know","prolly":"probably","tbh":"to be honest","smh":"shaking my head","btw":"by the way","ngl":"not gonna lie","fr":"for real","yessss":"yes","bc":"because","u":"you","thru":"through","lmao":"laughing my ass off","tldr":"too long; didn't read","ofc":"of course","linux":"GNU/Linux","xfl":"Extreme Football League","bi":"bisexual","abbr":"abbreviation","jk":"just kidding","gm":"good morning","mc":"Minecraft","nfl":"National Football League","ygd":"you're gonna die","gn":"goodnight"}} \ No newline at end of file diff --git a/commands/listPhrases.ts b/commands/listPhrases.ts new file mode 100644 index 0000000..bbce657 --- /dev/null +++ b/commands/listPhrases.ts @@ -0,0 +1,14 @@ +const { codeBlock } = require("discord.js"); + +const { SlashCommandBuilder, Discord } = require('discord.js'); +var abbreviationKey = require("../abbreviation_key.json"); + +module.exports = { + data: new SlashCommandBuilder() + .setName('list_phrases') + .setDescription('Lists phrases in target phrases.'), + async execute(interaction) { + await interaction.reply("Here are the current phrases in the phrase list:" + codeBlock("json", JSON.stringify(abbreviationKey.target_phrases, null, " "))); + console.log("User " + interaction.user.tag + " ran /list_phrases"); + }, +}; diff --git a/commands/removePhrase.ts b/commands/removePhrase.ts index 496908f..c618099 100644 --- a/commands/removePhrase.ts +++ b/commands/removePhrase.ts @@ -6,22 +6,17 @@ console.log(abbreviationKey); module.exports = { data: new SlashCommandBuilder() - .setName("add_phrase") - .setDescription("adds abbreviation to respond to") + .setName("remove_phrase") + .setDescription("removes abbreviation") .addStringOption( (option) => option.setName("abbreviation") .setDescription("The abbreviation to target") .setRequired(true) - ) - .addStringOption( option => - option.setName('phrase') - .setDescription("The phrase that the abbreviation shortens") - .setRequired(true) ), async execute(interaction) { var abbreviation = interaction.options.getString('abbreviation').toLowerCase(); //var phrase = interaction.options.getString('phrase'); - await interaction.reply('Removing abbreviation `' + abbreviation + "` from the target list... `"); + await interaction.reply('Removing abbreviation `' + abbreviation + "` from the target list..."); removePhrase(abbreviation); }, }; @@ -38,7 +33,7 @@ function removePhrase(abbrevation) { var jsonPath = path.join(__dirname, '..', 'abbreviation_key.json'); fs.unlinkSync(jsonPath); fs.writeFileSync(jsonPath, jsonString, { encoding: 'utf8' }, "\t"); - console.log("Removed abbreviation from list. JSON now contains:" + abbreviationKey); + console.log("Removed abbreviation from list. JSON now contains:" + abbreviationKey.target_phrases); } catch (err) { console.error(err); }