Add countChars function
This commit is contained in:
parent
9d5ef6f883
commit
03935a0cee
@ -18,7 +18,7 @@ module.exports = {
|
|||||||
.setDescription("The phrase that the abbreviation shortens")
|
.setDescription("The phrase that the abbreviation shortens")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction, client) {
|
||||||
var abbreviation = interaction.options.getString('abbreviation').toLowerCase();
|
var abbreviation = interaction.options.getString('abbreviation').toLowerCase();
|
||||||
var phrase = interaction.options.getString('phrase');
|
var phrase = interaction.options.getString('phrase');
|
||||||
await interaction.reply('Adding abbreviation `' + abbreviation + "` to target list. This will complete to the phrase `" + phrase + "`");
|
await interaction.reply('Adding abbreviation `' + abbreviation + "` to target list. This will complete to the phrase `" + phrase + "`");
|
||||||
|
@ -4,17 +4,17 @@ module.exports = {
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('count_chars')
|
.setName('count_chars')
|
||||||
.setDescription('Counts the number of characters in a string')
|
.setDescription('Counts the number of characters in a string')
|
||||||
.addStringOption( option =>
|
.addStringOption(option =>
|
||||||
option.setName('string')
|
option.setName('string')
|
||||||
.setDescription("String to count characters in")
|
.setDescription("String to count characters in")
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
)
|
)
|
||||||
.addStringOption( option =>
|
.addStringOption(option =>
|
||||||
option.setName('messageid')
|
option.setName('messageid')
|
||||||
.setDescription("Message ID of message to count characters in")
|
.setDescription("Message ID of message to count characters in")
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction, client) {
|
||||||
var inputString;
|
var inputString;
|
||||||
|
|
||||||
if (interaction.options.getString('string') !== null) {
|
if (interaction.options.getString('string') !== null) {
|
||||||
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await interaction.reply("Input: `" + inputString + "`\n" + "Output: " + codeBlock("", countChars(inputString)));
|
await interaction.reply("Input: `" + inputString + "`\n" + "Output: " + codeBlock("", countChars(inputString)));
|
||||||
console.log("User " + interaction.user.tag + " ran /count_chars");
|
console.log("User " + interaction.user.tag + " ran /count_chars");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,13 +37,13 @@ function countChars(string) {
|
|||||||
for (let i = 0; i < string.length; ++i) {
|
for (let i = 0; i < string.length; ++i) {
|
||||||
let currentChar = string.charAt(i);
|
let currentChar = string.charAt(i);
|
||||||
let arrayIndex = currentChar.charCodeAt(0) - 97;
|
let arrayIndex = currentChar.charCodeAt(0) - 97;
|
||||||
if (string.charAt(i).search(/^[a-z]+$/) === 0) {
|
if (string.charAt(i).search(/^[a-z]+$/) === 0) {
|
||||||
letterCount[arrayIndex]++;
|
letterCount[arrayIndex]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < letterCount.length; ++i) {
|
for (let i = 0; i < letterCount.length; ++i) {
|
||||||
if (letterCount[i] > 0) {
|
if (letterCount[i] > 0) {
|
||||||
outputString += "Number of " + String.fromCharCode(i + 97).toUpperCase() + "'s: " + letterCount[i] + "\n";
|
outputString += "Number of " + String.fromCharCode(i + 97).toUpperCase() + "'s: " + letterCount[i] + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outputString;
|
return outputString;
|
||||||
|
@ -7,8 +7,8 @@ module.exports = {
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('list_phrases')
|
.setName('list_phrases')
|
||||||
.setDescription('Lists phrases in target phrases.'),
|
.setDescription('Lists phrases in target phrases.'),
|
||||||
async execute(interaction) {
|
async execute(interaction, client) {
|
||||||
await interaction.reply("Here are the current phrases in the phrase list:" + codeBlock("json", JSON.stringify(abbreviationKey.target_phrases, null, " ")));
|
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");
|
console.log("User " + interaction.user.tag + " ran /list_phrases");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -4,8 +4,8 @@ module.exports = {
|
|||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('ping')
|
.setName('ping')
|
||||||
.setDescription('Replies with Pong!'),
|
.setDescription('Replies with Pong!'),
|
||||||
async execute(interaction) {
|
async execute(interaction, client) {
|
||||||
await interaction.reply('Pong!');
|
await interaction.reply('Pong!');
|
||||||
console.log("User " + interaction.user.tag + " ran /ping");
|
console.log("User " + interaction.user.tag + " ran /ping");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user