Skip to content

Commit

Permalink
npc creation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Multarix committed Jul 13, 2023
1 parent 7b2c8d6 commit 0f17e63
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
1 change: 0 additions & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const main = async () => {
}
}

// console.log(client.commands.get("help"));
client.login(client.config.token);
cronEvents(client);
};
Expand Down
56 changes: 41 additions & 15 deletions commands/npc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlashCommandBuilder, Client, Message, ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import NPC from "dnd-npc";

import { findSmallestDistance, caseFix } from "../src/functions.js";
import { caseFix } from "../src/functions.js";


// Too many here to list
Expand Down Expand Up @@ -79,11 +79,12 @@ async function run(client, element, args = []){

const characterString =
`**Gender:** *${gender}*\n` +
`**Alignment:**\n*${alignment}*\n` +
`**Background:**\n*${background}*\n` +
`**Age:** *${age}*\n` +
`**Class:** *[${className}](${classLink} "${className} on dndbeyond.com")*\n\u200b`;
fields.push({ name: "Character Info", value: characterString, inline: true });
`**Class:**\n*[${className}](${classLink} "${className} on dndbeyond.com")*\n` +
`**Alignment:**\n*${alignment}*\n` +
`**Background:**\n*${background}*\n\u200b`;

fields.push({ name: "Misc Info", value: characterString, inline: true });
fields.push({ name: "\u200b", value: "\u200b", inline: true });

// <NPC>#Race
Expand All @@ -92,19 +93,16 @@ async function run(client, element, args = []){
const size = npc.race.size;
const speed = npc.race.speed;
const raceString =
`**Race:**${raceName.length > 8 ? "\n" : " "}*[${raceName}](${raceLink} "${raceName} on dndbeyond.com")*\n` +
`**Race:**\n*[${raceName}](${raceLink} "${raceName} on dndbeyond.com")*\n` +
`**Size:**\n*${size}*\n` +
`**Speed:** *${speed}*\n\u200b`;
fields.push({ name: "Race Info", value: raceString, inline: true });


// <NPC>#Inventory
const tools = npc.inventory.tools; // name, link
const shield = npc.inventory.shield;
const weapon = npc.inventory.weapon;
const armor = npc.inventory.armor;


// <NPC>#Inventory#Weapon
const weaponName = caseFix(weapon.name);
const weaponLink = weapon.link;
Expand All @@ -117,7 +115,7 @@ async function run(client, element, args = []){

const weaponString =
`**[${weaponName}](${weaponLink} "${weaponName} on dndbeyond.com")**\n` +
`**DMG:**\n*${weaponDamage}*\n` +
`**DMG:** *${weaponDamage}*\n` +
`**DMG Type:**\n*${weaponDamageType}*\n` +
`**Properties:**\n*${weaponProperties}*\n\u200b`;
fields.push({ name: "Weapon Info", value: weaponString, inline: true });
Expand All @@ -130,13 +128,13 @@ async function run(client, element, args = []){
const armorName = armor.name;
const armorLink = armor.link;
const armorType = caseFix(armor.type);
// const armorAC = armor.ac; // Need to impliment this in the lib
const armorAC = armor.armorClass;
const armorStrength = armor.strengthReq;
const armorStealth = armor.isStealthy;
// const armorStealth = armor.isStealthy;
armorString =
`**[${armorName}](${armorLink} "${armorName} on dndbeyond.com")**\n` +
`**Type:** *${armorType}*\n` +
`**AC:** *N/A*\n` +
`**AC:** *${armorAC}*\n` +
`**STR Req:** *${armorStrength}*\n\u200b`;
}
fields.push({ name: "Armor Info", value: armorString, inline: true });
Expand Down Expand Up @@ -182,7 +180,7 @@ function slash(client, funcs = false){
if(!funcs){ // We want to get the slash command data

const classes = [
// { name: "artificer", value: "artificer" },
{ name: "artificer", value: "artificer" },
{ name: "barbarian", value: "barbarian" },
{ name: "bard", value: "bard" },
{ name: "cleric", value: "cleric" },
Expand All @@ -198,13 +196,41 @@ function slash(client, funcs = false){
{ name: "random", value: "random" }
];

// This isn't all the races, but a trimmed down subset of reasonable ones
const races = [
{ name: "aarakocra", value: "aarakocra" },
{ name: "aasimar", value: "aasimar" },
{ name: "changeling", value: "changeling" },
{ name: "dragonborn", value: "dragonborn" },
{ name: "dwarf", value: "dwarf" },
{ name: "elf", value: "elf" },
{ name: "firbolg", value: "firbolg" },
{ name: "genasi", value: "genasi" },
{ name: "gnome", value: "gnome" },
{ name: "goliath", value: "goliath" },
{ name: "half-elf", value: "half-elf" },
{ name: "halfling", value: "halfling" },
{ name: "half-orc", value: "half-orc" },
{ name: "human", value: "human" },
{ name: "kalashtar", value: "kalashtar" },
{ name: "kenku", value: "kenku" },
{ name: "lizardfolk", value: "lizardfolk" },
{ name: "shifter", value: "shifter" },
{ name: "tabaxi", value: "tabaxi" },
{ name: "tiefling", value: "tiefling" },
{ name: "triton", value: "triton" },
{ name: "warforged", value: "warforged" },
{ name: "yuan-ti", value: "yuan-ti" },
{ name: "random", value: "random" }
];

return {
data: new SlashCommandBuilder()
.setName(info.name)
.setDescription(info.description)
.setDMPermission(info.dmCompatible)
.addStringOption(option => option.setRequired(false).setName("class").setDescription("The class of the NPC").addChoices(...classes))
.addStringOption(option => option.setRequired(false).setName("race").setDescription("The race of the NPC"))
.addStringOption(option => option.setRequired(false).setName("race").setDescription("The race of the NPC").addChoices(...races))
};
}

Expand Down
12 changes: 6 additions & 6 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ import { output, permLevel } from "../src/functions.js";
async function run(client, interaction){

if(!interaction.isChatInputCommand()) return;
// if(!interaction.channel.permissionsFor(interaction.guild.members.me).has([PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ViewChannel])) return;


const command = client.commands.get(interaction.commandName);
if(!command){
interaction.reply({ content: "Oops! That command doesn't seem to exist!\nPlease report the error here: https://github.com/Multarix/Guildbot/issues", ephemeral: true }).catch(e => { return; });
interaction.reply({ content: "Oops! That command doesn't seem to exist!\nPlease report the error here: https://github.com/Multarix/Guildbot/issues", ephemeral: true });
return output("error", `Command ${interaction.commandName} not found!`);
}

// Check if the command is enabled
if(!command.info.enabled) return interaction.reply({ content: "Oops! That command is currently disabled!", ephemeral: true }).catch(e => { return; });
if(!command.info.enabled) return interaction.reply({ content: "Oops! That command is currently disabled!", ephemeral: true });

// Check if the user has permission to run the command
const userPermLevel = permLevel(client, interaction.user, interaction.channel);
if(command.info.permLevel > userPermLevel) return interaction.reply({ content: "Oops! You don't have permission to use that command!", ephemeral: true }).catch(e => { return; });
if(command.info.permLevel > userPermLevel) return interaction.reply({ content: "Oops! You don't have permission to use that command!", ephemeral: true });

try {
await command.slash(client, true).execute(interaction);
} catch (e){
output("error", e);
let followUp = false;
if(interaction.replied || interaction.deferred){
await interaction.followUp({ content: "An error occurred while executing this command!", ephemeral: true }).catch(e => { return; });
await interaction.followUp({ content: "An error occurred while executing this command!", ephemeral: true });
followUp = true;
}

if(!followUp) await interaction.reply({ content: "An error occurred while executing this command!", ephemeral: true }).catch(e => { return; });
if(!followUp) await interaction.reply({ content: "An error occurred while executing this command!", ephemeral: true });
}
}

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": {
"colors": "^1.4.0",
"discord.js": "^14.9.0",
"dnd-npc": "^2.0.2",
"dnd-npc": "^2.0.10",
"node-cron": "^3.0.2",
"node-fetch": "^3.3.1"
},
Expand Down

0 comments on commit 0f17e63

Please sign in to comment.