Skip to content

Commit

Permalink
Minor clean
Browse files Browse the repository at this point in the history
Clean up some empty space, function declarations and redundant embed calls.
Haven't tested most of these changes but Should Work:tm:.
  • Loading branch information
Glazelf committed Jun 17, 2024
1 parent 46c5417 commit 671ac8b
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 126 deletions.
21 changes: 12 additions & 9 deletions commands/api/dqm3.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ export default async (client, interaction, ephemeral) => {
};
};
};
dqm3Embed.setTitle(monsterTitle);
dqm3Embed
.setTitle(monsterTitle)
.addFields([
{ name: "Rank", value: monsterData.rank, inline: true },
{ name: "Family", value: familiesJSON[monsterData.family].name, inline: true }
]);
if (monsterData.description) dqm3Embed.setDescription(monsterData.description);
dqm3Embed.addFields([
{ name: "Rank", value: monsterData.rank, inline: true },
{ name: "Family", value: familiesJSON[monsterData.family].name, inline: true }
]);
if (monsterData.talents) dqm3Embed.addFields([{ name: "Innate Talents:", value: innateTalentsString, inline: true }]);
if (monsterData.traits) dqm3Embed.addFields([{ name: "Traits: (Lvl)", value: monsterTraitsString, inline: true }]);
if (monsterData.growth) dqm3Embed.addFields([{ name: "Growth:", value: growthString, inline: false }]);
Expand Down Expand Up @@ -115,8 +116,10 @@ export default async (client, interaction, ephemeral) => {
dqm3Embed
.setTitle(skillData.name)
.setDescription(skillData.description)
.addFields([{ name: "Type:", value: skillData.type, inline: true }])
.addFields([{ name: "MP Cost:", value: mpCostString, inline: true }]);
.addFields([
{ name: "Type:", value: skillData.type, inline: true },
{ name: "MP Cost:", value: mpCostString, inline: true }
]);
if (skillTalents.length > 0) dqm3Embed.addFields([{ name: "Talents:", value: skillTalents.join("\n"), inline: false }]);
break;
case "trait":
Expand Down Expand Up @@ -205,10 +208,10 @@ export default async (client, interaction, ephemeral) => {
};
dqm3Embed
.setTitle("Synthesis")
.setDescription(`${parent1Name} + ${parent2Name} = ${targetName}`);
.setDescription(`${parent1Name} + ${parent2Name} = ${targetName}`)
.setFooter({ text: "Note: Monsters can always synthesize into their own species." });
if (familySynthesisString.length > 0) dqm3Embed.addFields([{ name: "Family Synthesis:", value: `${familySynthesisString}\n${familySynthesisNote}`, inline: false }]);
if (uniqueSynthesisString.length > 0) dqm3Embed.addFields([{ name: "Unique Synthesis:", value: uniqueSynthesisString, inline: false }]);
dqm3Embed.setFooter({ text: "Note: Monsters can always synthesize into their own species." });
} else {
return sendMessage({ client: client, interaction: interaction, content: `Coming soon.` });
};
Expand Down
34 changes: 17 additions & 17 deletions commands/api/persona5.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export default async (client, interaction, ephemeral) => {
p5Embed
.setTitle(`${personaInput} (${personaObject.arcana})`)
.setDescription(elementalMatchup)
.setImage(personaImage)
.addFields([
{ name: "Stats:", value: `Trait: ${personaObject.trait}\nLevel: ${personaObject.level}\n${personaStats}`, inline: true },
{ name: "Skills:", value: personaSkills, inline: true },
{ name: "Item:", value: personaItem, inline: false },
{ name: "Item (Fusion Alarm):", value: personaItemAlarm, inline: false }
])
.setImage(personaImage);
]);
break;
case "skill":
let skillInput = interaction.options.getString("skill");
Expand Down Expand Up @@ -104,26 +104,26 @@ export default async (client, interaction, ephemeral) => {
};
return sendMessage({ client: client, interaction: interaction, embeds: p5Embed, ephemeral: ephemeral, components: buttonArray });

function getWeaknessString(string) {
string = string.replace("wk", "Weak").replace("rs", "Resist").replace("nu", "Null").replace("ab", "Absorb").replace("rp", "Repel").replace("-", "Neutral");
return string;
};
function getItemString(string) {
let itemObject = itemMapRoyal[string];
if (!itemObject) return "None";
if (itemObject.type && itemObject.description) {
string = `${string} (${itemObject.type}): ${itemObject.description}`;
} else if (itemObject.skillCard) {
string = `${string} (Skill Card)`;
};
return string;
};

} catch (e) {
logger(e, client, interaction);
};
};

function getWeaknessString(string) {
string = string.replace("wk", "Weak").replace("rs", "Resist").replace("nu", "Null").replace("ab", "Absorb").replace("rp", "Repel").replace("-", "Neutral");
return string;
};
function getItemString(string) {
let itemObject = itemMapRoyal[string];
if (!itemObject) return "None";
if (itemObject.type && itemObject.description) {
string = `${string} (${itemObject.type}): ${itemObject.description}`;
} else if (itemObject.skillCard) {
string = `${string} (Skill Card)`;
};
return string;
};

export const config = {
name: "persona5",
description: "Shows Persona 5 data.",
Expand Down
61 changes: 30 additions & 31 deletions commands/api/splatoon3.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export default async (client, interaction, ephemeral) => {
splat3Embed
.setAuthor({ name: clothingAuthor, iconURL: brandImage })
.setThumbnail(abilityImage)
.setImage(clothingImage)
.setFooter({ text: `${versionString} | *Main abilities can differ because of SplatNet or Murch.` })
.addFields([
{ name: abilityTitle, value: `${languageJSON["CommonMsg/Gear/GearPowerName"][clothingObject.Skill]}*`, inline: true },
{ name: slotsTitle, value: (clothingObject.Rarity + 1).toString(), inline: true },
{ name: brandTitle, value: languageJSON["CommonMsg/Gear/GearBrandName"][clothingObject.Brand], inline: true },
{ name: "Obtain Method:", value: obtainMethod, inline: true }
])
.setImage(clothingImage)
.setFooter({ text: `${versionString} | *Main abilities can differ because of SplatNet or Murch.` });
]);
break;
case "weapon":
inputID = interaction.options.getString("weapon");
Expand Down Expand Up @@ -156,14 +156,14 @@ export default async (client, interaction, ephemeral) => {
splat3Embed
.setAuthor({ name: weaponAuthor, iconURL: subImage })
.setThumbnail(specialImage)
.setImage(weaponImage)
.setFooter({ text: versionString })
.addFields([
{ name: subTitle, value: languageJSON["CommonMsg/Weapon/WeaponName_Sub"][subID], inline: true },
{ name: specialTitle, value: languageJSON["CommonMsg/Weapon/WeaponName_Special"][specialID], inline: true },
{ name: shopTitle, value: weaponUnlockString, inline: true },
{ name: infoTitle, value: weaponStats, inline: false }
])
.setImage(weaponImage)
.setFooter({ text: versionString });
]);
break;
case "subweapon":
inputID = interaction.options.getString("subweapon");
Expand All @@ -189,8 +189,8 @@ export default async (client, interaction, ephemeral) => {
.setTitle(subName)
.setThumbnail(subThumbnail)
.setDescription(subDescription)
.addFields([{ name: weaponListTitle, value: allSubweaponMatchesNames, inline: false }])
.setFooter({ text: versionString });
.setFooter({ text: versionString })
.addFields([{ name: weaponListTitle, value: allSubweaponMatchesNames, inline: false }]);
break;
case "special":
inputID = interaction.options.getString("special");
Expand All @@ -215,8 +215,8 @@ export default async (client, interaction, ephemeral) => {
.setTitle(specialName)
.setThumbnail(specialThumbnail)
.setDescription(specialDescription)
.setFooter({ text: versionString })
.addFields([{ name: weaponListTitle, value: allSpecialWeaponMatchesNames, inline: false }])
.setFooter({ text: versionString });
break;
case "schedule":
let inputData = interaction.options.getString("mode");
Expand Down Expand Up @@ -329,8 +329,8 @@ export default async (client, interaction, ephemeral) => {
tricolorSchedule += `\n${currentFest.tricolorStage.name}`;
splat3Embed
.setDescription(splatfestScheduleDescription)
.addFields([{ name: "Tricolor Battle:", value: tricolorSchedule, inline: false }])
.setImage(splatfestData.image.url);
.setImage(splatfestData.image.url)
.addFields([{ name: "Tricolor Battle:", value: tricolorSchedule, inline: false }]);
};
if ([turfWarID, anarchyID, splatfestBattleID, xBattleID].includes(inputMode)) {
// Turf War, Anarchy, xBattle and SplatfestTW
Expand Down Expand Up @@ -371,7 +371,11 @@ export default async (client, interaction, ephemeral) => {
if (responseSplatnet.status != 200) return sendMessage({ client: client, interaction: interaction, content: `Error occurred getting SplatNet3 data. Please try again later.` });
let splatnetData = responseSplatnet.data.data.gesotown;
// Limited time brand
splat3Embed.addFields([{ name: `Daily Drop (${splatnetData.pickupBrand.brand.name})`, value: `${splatnetData.pickupBrand.brand.name} Common Ability: ${splatnetData.pickupBrand.brand.usualGearPower.name}\nDaily Drop (${splatnetData.pickupBrand.nextBrand.name}) starts <t:${Date.parse(splatnetData.pickupBrand.saleEndTime) / 1000}:R>.`, inline: false }]);
splat3Embed
.setTitle("SplatNet3 Shop")
.setImage(splatnetData.pickupBrand.image.url)
.setFooter({ text: `${splatnetData.pickupBrand.brand.name} promotional image.` })
.addFields([{ name: `Daily Drop (${splatnetData.pickupBrand.brand.name})`, value: `${splatnetData.pickupBrand.brand.name} Common Ability: ${splatnetData.pickupBrand.brand.usualGearPower.name}\nDaily Drop (${splatnetData.pickupBrand.nextBrand.name}) starts <t:${Date.parse(splatnetData.pickupBrand.saleEndTime) / 1000}:R>.`, inline: false }]);
await splatnetData.pickupBrand.brandGears.forEach(brandGear => {
let brandGearString = getGearString(brandGear, "brand");
splat3Embed.addFields([{ name: brandGear.gear.name, value: brandGearString, inline: true }]);
Expand All @@ -382,11 +386,6 @@ export default async (client, interaction, ephemeral) => {
let limitedGearString = getGearString(limitedGear, "limited");
splat3Embed.addFields([{ name: limitedGear.gear.name, value: limitedGearString, inline: true }]);
});

splat3Embed
.setTitle("SplatNet3 Shop")
.setImage(splatnetData.pickupBrand.image.url)
.setFooter({ text: `${splatnetData.pickupBrand.brand.name} promotional image.` });
break;
case "splatfests":
await interaction.deferReply({ ephemeral: ephemeral });
Expand Down Expand Up @@ -435,14 +434,14 @@ export default async (client, interaction, ephemeral) => {
.setTitle(replayMode)
.setThumbnail(replayData.player.weapon.image.url)
.setDescription(matchData)
.setFooter({ text: `Replay ID: ${replayResponse.data.replay.replayCode}` })
.addFields([
{ name: "Player Data:", value: playerData.join("\n"), inline: false },
{ name: `${replayData.player.headGear.name} Skills:`, value: headSkills.join("\n"), inline: true },
{ name: `${replayData.player.clothingGear.name} Skills:`, value: clothingSkills.join("\n"), inline: true },
{ name: `${replayData.player.shoesGear.name} Skills:`, value: shoesSkills.join("\n"), inline: true }
]);
if (replayAwards.length > 0) splat3Embed.addFields([{ name: "Awards:", value: replayAwards.join("\n"), inline: false }]);
splat3Embed.setFooter({ text: `Replay ID: ${replayResponse.data.replay.replayCode}` });
break;
case "splashtag-random":
let userTitle = interaction.member.nickname;
Expand Down Expand Up @@ -474,24 +473,24 @@ export default async (client, interaction, ephemeral) => {
};
return sendMessage({ client: client, interaction: interaction, embeds: splat3Embed, ephemeral: ephemeral });

function getGearString(gear, type) {
let limitedGearString = "";
if (type == "limited") limitedGearString += `Sale ends <t:${Date.parse(gear.saleEndTime) / 1000}:R>.\n`;
limitedGearString += `Ability: ${gear.gear.primaryGearPower.name}\n`;
let limitedGearStars = star.repeat(gear.gear.additionalGearPowers.length - 1);
let limitedGearStarString = `Slots: ${gear.gear.additionalGearPowers.length}`;
if (gear.gear.additionalGearPowers.length > 1) limitedGearStarString += ` (${limitedGearStars})`;
limitedGearString += `${limitedGearStarString}\n`;
limitedGearString += `Brand: ${gear.gear.brand.name}\n`;
limitedGearString += `Price: ${gear.price}\n`;
return limitedGearString;
};

} catch (e) {
logger(e, client, interaction);
};
};

function getGearString(gear, type) {
let limitedGearString = "";
if (type == "limited") limitedGearString += `Sale ends <t:${Date.parse(gear.saleEndTime) / 1000}:R>.\n`;
limitedGearString += `Ability: ${gear.gear.primaryGearPower.name}\n`;
let limitedGearStars = star.repeat(gear.gear.additionalGearPowers.length - 1);
let limitedGearStarString = `Slots: ${gear.gear.additionalGearPowers.length}`;
if (gear.gear.additionalGearPowers.length > 1) limitedGearStarString += ` (${limitedGearStars})`;
limitedGearString += `${limitedGearStarString}\n`;
limitedGearString += `Brand: ${gear.gear.brand.name}\n`;
limitedGearString += `Price: ${gear.price}\n`;
return limitedGearString;
};

export const config = {
name: "splatoon3",
description: `Shows Splatoon 3 data.`,
Expand Down
20 changes: 10 additions & 10 deletions commands/info/botinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async (client, interaction, ephemeral) => {

await client.guilds.fetch();
let totalGuilds = client.guilds.cache.size;
let totalMembers = await getUsers();
let totalMembers = await getUsers(client);
// Get latest commit
let githubURLVars = "Glazelf/NinigiBot";
let githubRepoResponse = null;
Expand Down Expand Up @@ -71,20 +71,20 @@ export default async (client, interaction, ephemeral) => {
.addComponents(new Discord.ButtonBuilder({ label: 'Support Server', style: Discord.ButtonStyle.Link, url: `https://discord.gg/${globalVars.ShinxServerInvite}` }))
return sendMessage({ client: client, interaction: interaction, embeds: botEmbed, components: botButtons, ephemeral: ephemeral });

async function getUsers() {
// Fast but inaccurate method
let userCount = 0;
await client.guilds.cache.forEach(guild => {
if (guild.memberCount) userCount += guild.memberCount;
});
return userCount;
};

} catch (e) {
logger(e, client, interaction);
};
};

async function getUsers(client) {
// Fast but inaccurate method
let userCount = 0;
await client.guilds.cache.forEach(guild => {
if (guild.memberCount) userCount += guild.memberCount;
});
return userCount;
};

export const config = {
name: "botinfo",
description: `Displays info about this bot.`,
Expand Down
4 changes: 2 additions & 2 deletions commands/info/roleinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default async (client, interaction, ephemeral) => {
.setColor(embedColor)
.setTitle(role.name)
.setThumbnail(icon)
.setFooter({ text: role.id })
.addFields([{ name: "Role:", value: role.toString(), inline: true }]);
if (role.hexColor !== defaultColor) roleEmbed.addFields([{ name: "Color:", value: role.hexColor, inline: true }]);
roleEmbed
Expand All @@ -39,8 +40,7 @@ export default async (client, interaction, ephemeral) => {
{ name: "Position:", value: role.rawPosition.toString(), inline: true },
{ name: "Properties:", value: roleProperties, inline: false },
{ name: "Permissions:", value: permissionString, inline: false }
])
.setFooter({ text: role.id });
]);
return sendMessage({ client: client, interaction: interaction, embeds: roleEmbed, ephemeral: ephemeral });

} catch (e) {
Expand Down
9 changes: 4 additions & 5 deletions commands/virtual_simulation/trophy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import getTrophyEmbedSlice from "../../util/trophies/getTrophyEmbedSlice.js";
export default async (client, interaction, ephemeral) => {
try {
let messageFile = null;
let embed, trophy_name, res;
let trophy_name, res;
let embed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor)
let returnString = '';
let canvas, ctx, img, shinx;
let ephemeralArg = interaction.options.getBoolean("ephemeral");
Expand All @@ -22,8 +24,6 @@ export default async (client, interaction, ephemeral) => {
let trophies;
switch (interaction.options.getSubcommand()) {
case "stock":
embed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor)
trophies = await getFullBuyableShopTrophies(master.id);
if (!emotesAllowed) trophies = replaceDiscordEmotes(trophies);
trophies.forEach(trophy => {
Expand Down Expand Up @@ -113,8 +113,7 @@ export default async (client, interaction, ephemeral) => {
});
} else {
if (!emotesAllowed) res = replaceDiscordEmotes(res, is_array = false);
embed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor)
embed
.setTitle(`${res.trophy_id}`)
.addFields([
{ name: "Icon:", value: `${res.icon}`, inline: true },
Expand Down
Loading

0 comments on commit 671ac8b

Please sign in to comment.