Initial work is done
This commit is contained in:
47
commands/addPhrase.ts
Normal file
47
commands/addPhrase.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
var abbreviationKey = require("../abbreviation_key.json");
|
||||
const fs = require('node:fs');
|
||||
var path = require('node:path');;
|
||||
console.log(abbreviationKey);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("add_phrase")
|
||||
.setDescription("adds_abbreviation_to_respond_to")
|
||||
.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');
|
||||
var phrase = interaction.options.getString('phrase');
|
||||
await interaction.reply('Adding phrase `' + abbreviation + "` to target list. This will complete to the phrase `" + phrase + "`");
|
||||
addPhrase(abbreviation, phrase);
|
||||
},
|
||||
};
|
||||
|
||||
function addPhrase(abbrevation, phrase) {
|
||||
console.log(abbrevation, phrase);
|
||||
abbreviationKey.target_phrases[abbrevation] = phrase;
|
||||
console.log(abbreviationKey);
|
||||
updatePhraseList();
|
||||
|
||||
// Write data to file
|
||||
var jsonString = JSON.stringify(abbreviationKey);
|
||||
try {
|
||||
//console.log(fs.existsSync("../abbreviation_key.json"));
|
||||
var jsonPath = path.join(__dirname, '..', 'abbreviation_key.json');
|
||||
fs.unlinkSync(jsonPath);
|
||||
fs.writeFileSync(jsonPath, jsonString, { encoding: 'utf8' }, "\t");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user