Skip to content

Commit

Permalink
Fix a few bugs, clean up a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
earthernsence committed Oct 2, 2021
1 parent 25c767d commit 8375c24
Show file tree
Hide file tree
Showing 14 changed files with 631 additions and 699 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ config.json
/node_modules
package.json
package-lock.json
.vscode
.vscode
testfileforrandomsnippets.js
Binary file modified adab data.xlsx
Binary file not shown.
11 changes: 6 additions & 5 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const commands = require("./utils/commands");
const { Internal } = require("./classes/FunctionClasses/Internal");
const { Help } = require("./classes/FunctionClasses/Help");
const { Time } = require("./classes/FunctionClasses/Time");
const { Meta } = require("./classes/ApplicationCommand/MetaApplicationCommand");
const { Meta } = require("./classes/Meta");

// eslint-disable-next-line max-len
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.DIRECT_MESSAGES, Discord.Intents.FLAGS.GUILD_INTEGRATIONS, Discord.Intents.FLAGS.GUILD_MEMBERS], partials: ["MESSAGE", "CHANNEL", "USER", "REACTION", "GUILD_MEMBER"] });
Expand Down Expand Up @@ -204,7 +204,7 @@ client.on("interactionCreate", async interaction => {
return;
}

if (!client.commands.has(interaction.commandName) && interaction.commandName !== "help") return;
if (!client.commands.has(interaction.commandName) && interaction.commandName !== "help" && interaction.commandName !== "meta") return;

incrementTag("totalRequests", Tags, "Tags");

Expand Down Expand Up @@ -240,7 +240,7 @@ client.on("interactionCreate", async interaction => {
TimeTags
});
m.send();
} else client.commands.get(interaction.commandName).execute(interaction, interaction.channelId, Tags);
} else client.commands.get(interaction.commandName).execute(interaction, interaction.channelId);
incrementTag("totalSuccesses", Tags, "Tags");
incrementTag(interaction.commandName, Tags, "Tags");
incrementTag(Time.newDate().getHours(), TimeTags, "TimeTags");
Expand Down Expand Up @@ -302,8 +302,9 @@ client.on("messageCreate", async message => {
// Sends a message with the amount of helpers, and then DMs you the list.
if (message.content.toLowerCase() === "++helpers" && ((message.author.id === config.ids.earth && message.guildId === adIDs.serverID) || isMod)) {
const roleInfo = message.guild.roles.resolve(config.ids.helperRole);
const namesAndIDs = roleInfo.members.map(member => `${member.user.username}#${member.user.discriminator} (${member.user.id})`);
console.log(namesAndIDs);
const namesAndIDs = roleInfo.members.map(member => `${member.user.username}#${member.user.discriminator} (${member.user.id}) [${member.roles.highest.name}]`);

console.log(namesAndIDs.join("\n"));
message.reply(`Currently, ${roleInfo.members.size} person(s) have the Helper role.`);
message.author.send(namesAndIDs.join("\n"));
}
Expand Down
29 changes: 18 additions & 11 deletions classes/ApplicationCommand/TimeStudyApplicationCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class TimeStudyApplicationCommand extends ApplicationCommand {
this.name === "eternitychallengeorder";
}

isTSorECorECO() {
return this.name === "ec" ||
this.name === "ts" ||
this.name === "eco";
}

/**
* @inheritdoc
* @return {Array}
Expand Down Expand Up @@ -128,32 +134,33 @@ class TimeStudyApplicationCommand extends ApplicationCommand {
let argMessage;
let argMessageWithDM;
let args;
if (this.hasHelperRole(interaction)) this.ephemeral = false;
else if (!this.hasHelperRole(interaction)) this.ephemeral = true;
if (this.isECOorEC()) args = [`${this.getArgs(interaction)[0]}x${this.getArgs(interaction)[1]}`];
const allArgs = this.getArgs(interaction);
const isHelper = this.hasHelperRole(interaction);

if (this.isECOorEC()) args = [`${allArgs[0]}x${allArgs[1]}`];
else if (this.isTS()) {
args = this.getArgs(interaction);
args = allArgs;
if (!args[1]) args[1] = "active";
} else if (this.isPeople() || this.isHTP()) {
args = this.getArgs(interaction);
args = allArgs;
}

if (this.type !== "shorthand" || this.name === "ts" || this.name === "ec" || this.name === "eco") {
if (this.type !== "shorthand" || this.isTSorECorECO()) {
argMessage = this.getArgMessage(args);
argMessageWithDM = this.getArgMessage(args, true);
} else if (this.type === "shorthand") {
argMessage = this.sent[0];
argMessageWithDM = this.sent[0];
}

if (this.isEC() && this.hasHelperRole(interaction)) {
interaction.reply({ content: argMessage, ephemeral: this.getArgs(interaction)[2] });
interaction.followUp({ content: argMessageWithDM, ephemeral: this.getArgs(interaction)[2] });
if (this.isEC() && isHelper) {
interaction.reply({ content: argMessage, ephemeral: allArgs[2] });
interaction.followUp({ content: argMessageWithDM, ephemeral: allArgs[2] });
return;
}

interaction.reply({ content: argMessage, ephemeral: !this.hasHelperRole(interaction) });
if (this.isEC()) interaction.followUp({ content: argMessageWithDM, ephemeral: !this.hasHelperRole(interaction) });
interaction.reply({ content: argMessage, ephemeral: !isHelper });
if (this.isEC()) interaction.followUp({ content: argMessageWithDM, ephemeral: !isHelper });
}
}

Expand Down
29 changes: 17 additions & 12 deletions classes/FunctionClasses/Checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Checks {
"ecsPlusCheck": this.ecsPlusCheck,
"weirdICsCheck": this.weirdICsCheck,
"lateBreakCheck": this.lateBreakCheck,
"challengeCheck": this.challengeCheck,
true: true
};
}
Expand All @@ -32,23 +33,23 @@ class Checks {
}

static earlyGameCheck(id, message) {
return config.ids.earlyGame.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.earlyGame.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static breakCheck(id, message) {
return config.ids.break.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.break.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static earlyEternityCheck(id, message) {
return config.ids.earlyEternity.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.earlyEternity.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static ecsCheck(id, message) {
return config.ids.ecs.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.ecs.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static endgameCheck(id, message) {
return config.ids.endgame.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.endgame.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static botCommandsCheck(id, message) {
Expand All @@ -62,15 +63,15 @@ class Checks {
}

static bankedInfsCheck(id, message) {
return config.ids.common.includes(id) || config.ids.ecs[1] === id || config.ids.endgame.includes(id) || Checks.botCommandsCheck(id, message);
return Checks.commonCheck(id) || config.ids.ecs[1] === id || config.ids.endgame.includes(id) || Checks.botCommandsCheck(id, message);
}

static dilationGrindCheck(id, message) {
return config.ids.endgame.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message) || config.ids.ecs[1] === id;
return config.ids.endgame.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message) || config.ids.ecs[1] === id;
}

static earlyInfinityCheck(id, message) {
return config.ids.earlyGame[1] === id || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.earlyGame[1] === id || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static eternityGrindingCheck(id, message) {
Expand All @@ -86,19 +87,23 @@ class Checks {
}

static e4000Check(id, message) {
return config.ids.endgame[1] === id || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.endgame[1] === id || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static ecsPlusCheck(id, message) {
return config.ids.ecs.includes(id) || config.ids.endgame.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.ecs.includes(id) || config.ids.endgame.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static weirdICsCheck(id, message) {
return config.ids.earlyEternity.includes(id) || config.ids.break.includes(id) || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.earlyEternity.includes(id) || config.ids.break.includes(id) || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static lateBreakCheck(id, message) {
return config.ids.break[1] === id || config.ids.common.includes(id) || Checks.botCommandsCheck(id, message);
return config.ids.break[1] === id || Checks.commonCheck(id) || Checks.botCommandsCheck(id, message);
}

static challengeCheck(id, message) {
return Checks.earlyInfinityCheck(id, message) || Checks.breakCheck(id, message) || Checks.earlyEternityCheck(id, message) || Checks.ecsCheck(id, message);
}
}

Expand Down
3 changes: 2 additions & 1 deletion classes/FunctionClasses/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Message {
"endgameCheck": this.noWorkyMessage("endgame"),
"e4000Check": this.noWorkyMessage("e4000 EP"),
"weirdICsCheck": this.noWorkyMessage("Break Infinity", "early Eternity"),
"lateBreakCheck": this.noWorkyMessage("last Break Infinity")
"lateBreakCheck": this.noWorkyMessage("last Break Infinity"),
"challengeCheck": `This command only works in Early Infinity channels, Break Infinity channels, Eternity channels, and EC channels.`
}
};
}
Expand Down
118 changes: 6 additions & 112 deletions ...licationCommand/MetaApplicationCommand.js → classes/Meta.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* eslint-disable no-console */
"use strict";

const { ApplicationCommand } = require("./ApplicationCommand");
const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js");
const config = require("../../utils/config.json");
const commands = require("../../utils/commands");
const { footerMessages } = require("../../utils/messages");
const wait = require("util").promisify(setTimeout);
const { Time } = require("../FunctionClasses/Time");
const { MessageActionRow, MessageButton } = require("discord.js");
const config = require("../utils/config.json");
const commands = require("../utils/commands");
const { footerMessages } = require("../utils/messages");
const { Time } = require("./FunctionClasses/Time");

const NOW = new Date();
const metaMessageObject = {
Expand Down Expand Up @@ -226,108 +224,4 @@ class Meta {
}
}

/**
* @class MetaApplicationCommand
* @extends {ApplicationCommand}
* @classdesc Class for executing meta.js.
*/
class MetaApplicationCommand extends ApplicationCommand {
async manageBottomAndTopCommands(Tags, secondAttribute) {
const tagsMatchedWithTimesUsed = {};
const tagList = await Tags.findAll({ attributes: ["timesUsed", secondAttribute] });
tagList.map(t => Object.assign(tagsMatchedWithTimesUsed, { [t[secondAttribute]]: t.timesUsed }));
const sorted = Object.values(tagsMatchedWithTimesUsed).sort((a, b) => b - a);
const requests = sorted[0];
const successes = sorted[1];
sorted.shift();
sorted.shift();
let top5commands = [];
let bottom5commands = [];
for (let i = 0; i < 5; i++) {
const b = Object.entries(tagsMatchedWithTimesUsed).find(a => a[1] === sorted[0]);
top5commands.push(b);
delete tagsMatchedWithTimesUsed[b[0]];
sorted.shift();
}
for (let i = 0; i < 5; i++) {
const b = Object.entries(tagsMatchedWithTimesUsed).find(a => a[1] === sorted[sorted.length - 1]);
bottom5commands.push(b);
delete tagsMatchedWithTimesUsed[b[0]];
sorted.pop();
}
bottom5commands = bottom5commands.map(a => `${a[0]}: ${a[1]}`).reverse().join("\n");
top5commands = top5commands.map(a => `${a[0]}: ${a[1]}`).join("\n");
return {
requests,
successes,
bottom5commands,
top5commands,
};
}

getStatus(ping) {
if (ping >= 200) return `Very high ping! ${ping}ms`;
if (ping >= 175) return `High ping! ${ping}ms`;
if (ping >= 150) return `Relatively high ping! ${ping}ms`;
if (ping >= 125) return `Slightly above average ping! ${ping}ms`;
if (ping >= 100) return `Average ping! ${ping}ms`;
if (ping >= 75) return `Below average ping! ${ping}ms`;
if (ping >= 50) return `Very good ping! ${ping}ms`;
return `Incredible ping! ${ping}ms`;
}

/**
* Executes the command.
* @param {Object} interaction - The interaction object used for the command that contains all useful information
*/
async execute(interaction, Tags, TimeTags) {
if (!this.getCheck(interaction.channelId, interaction)) {
interaction.reply({ content: `hey bitchass you can't use that command here`, ephemeral: true });
return;
}
const tagStuff = await this.manageBottomAndTopCommands(Tags, "name");
const timeTagStuff = await this.manageBottomAndTopCommands(TimeTags, "hour");
const embed = new MessageEmbed()
.setColor("BLURPLE")
.setTitle("Bot Information")
.setDescription(`Internal bot information`)
.setThumbnail(`${interaction.client.user.displayAvatarURL()}`)
.addFields(
{ name: "Bot version", value: config.version, inline: true },
{ name: "Last restart", value: metaMessageObject.lastrestart, inline: true },
// eslint-disable-next-line max-len
{ name: "Uptime", value: `The bot has been up for ${Time.dhmsFromMS(interaction.client.uptime).clock}, (${Time.decimalTime(true, Time.newDate(), interaction.client.uptime)} 10h time)`, inline: true },
{ name: "Status", value: `Pong! ${this.getStatus(interaction.client.ws.ping)}`, inline: true },
{ name: "Suggest", value: metaMessageObject.suggest, inline: true },
{ name: "Invite", value: metaMessageObject.invite, inline: true },
{ name: "Contributing", value: metaMessageObject.contributing, inline: true },
{ name: "Total amount of commands", value: `${commands.all.length}`, inline: true },
{ name: "Total requests/successses", value: `Requests: ${tagStuff.requests}\nSuccesses: ${tagStuff.successes}`, inline: true },
{ name: "Top 5 used commands", value: `${tagStuff.top5commands}`, inline: true },
{ name: "Bottom 5 used commands", value: `${tagStuff.bottom5commands}`, inline: true },
{ name: "All data", value: metaMessageObject.alldata, inline: true },
{ name: "Time", value: Time.getTime(), inline: true },
{ name: "Top 5 active hours (UTC-5)", value: `${timeTagStuff.top5commands}`, inline: true },
{ name: "Bottom 5 active hours (UTC-5)", value: `${timeTagStuff.bottom5commands}`, inline: true },
)
.setTimestamp()
.setFooter(footerMessages.next(false), `${interaction.client.user.displayAvatarURL()}`);

const buttonRow = new MessageActionRow()
.addComponents(
new MessageButton()
.setStyle("LINK")
.setLabel("See all commands")
.setURL("https://earthernsence.github.io/ADAnswers-Bot/docs/"),
new MessageButton()
.setStyle("LINK")
.setLabel("GitHub repository")
.setURL("https://github.com/earthernsence/ADAnswers-Bot"),
);
await interaction.deferReply();
await wait(2000);
await interaction.editReply({ embeds: [embed], ephemeral: true, components: [buttonRow] });
}
}

module.exports = { MetaApplicationCommand, Meta };
module.exports = { Meta };
2 changes: 1 addition & 1 deletion commands/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
number: 1,
name: "challenge",
description: "Args: all challenges, including `ecs`. Returns a guide for each argument. All of these commands have shorthands as well, f.e `/challenge c9` will return the same result as `/c9`",
check: true,
check: "challengeCheck",
acceptableArgs: Object.keys(challengeMessageObject),
sent: undefined,
getArgMessage(arg) {
Expand Down
Loading

0 comments on commit 8375c24

Please sign in to comment.