Skip to content

Commit

Permalink
it typechecks!
Browse files Browse the repository at this point in the history
tsconfig is quite lax, notably strict null checking is off, but one step at a time heh
  • Loading branch information
meadowsys committed Mar 2, 2024
1 parent 92d6d8d commit ca1fd1c
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 28 deletions.
8 changes: 7 additions & 1 deletion modules/bizaam.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ module.exports = class Bizaam extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
bizaam(msg) {
if (Application.modules.Discord.controlTalkedRecently(msg, this.config.bizaamType)) {
const random = Tools.getRandomIntFromInterval(0, this.config.bizaamAnswer.length - 1);
msg.channel.send(Tools.parseReply(this.config.bizaamAnswer[random], [this.bizaamEmoji])).then(sentEmbed => {
msg.channel.send(Tools.parseReply(
this.config.bizaamAnswer[random],
this.bizaamEmoji.toString()
)).then(sentEmbed => {
sentEmbed.react(this.bizaamEmoji);
});

Expand Down
18 changes: 14 additions & 4 deletions modules/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ module.exports = class Discord extends Module {
return new Promise(resolve => {
this.log.debug("Initializing...");

/**
* @type { Array<{
* cmd: string;
* cb: (msg: import("discord.js").Message) => void;
* }> }
*/
this.commands = [];
this.reactions = [];
// this.reactions = [];
/** @type { Set<string> } */
this.channelMessaged = new Set();
/** @type { Set<string> } */
Expand Down Expand Up @@ -96,13 +102,17 @@ module.exports = class Discord extends Module {
}
}

/**
* @param { string } cmd
* @param { (msg: import("discord.js").Message) => void } cb
*/
addCommand(cmd, cb) {
this.commands.push({ cmd, cb });
}

addReaction(text, type, cb) {
this.reactions.push({ text, type, cb });
}
// addReaction(text, type, cb) {
// this.reactions.push({ text, type, cb });
// }

/**
* @param { string } type
Expand Down
9 changes: 4 additions & 5 deletions modules/gamer-canni.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ module.exports = class GamerCanni extends Module {
await sentEmbed.react(emojis[i]);
}

const filter = (reaction, user) => {
return emojis.includes(reaction.emoji.name) && user.id === msg.author.id;
};

sentEmbed.awaitReactions(filter, { max: 1, time: 30000, errors: ["time"] }).then(collected => {
sentEmbed.awaitReactions(
(react, user) => emojis.includes(react.emoji.name) && user.id === msg.author.id,
{ max: 1, time: 30000, errors: ["time"] }
).then(collected => {
const reaction = collected.first();

const userChoice = this.getEmojiName(reaction.emoji.name);
Expand Down
5 changes: 5 additions & 0 deletions modules/greetings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ module.exports = class Greetings extends Module {
}
}

/**
* @param { import("discord.js").Message } msg
* @param { string } type
* @param { Array<string> } answerType
*/
sendMessage(msg, type, answerType) {
if (Application.modules.Discord.controlTalkedRecently(msg, type, false, "channel", undefined, undefined, 90000)) {
const random = Tools.getRandomIntFromInterval(0, answerType.length - 1);
Expand Down
2 changes: 1 addition & 1 deletion modules/holiday.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const christmas_date = [12, 25];
const new_year_date = [1, 1];
// let wachmann_id;

/** @extends { Module<import("./holiday-config.json*/
/** @extends { Module<import("./holiday-config.json")> } */
module.exports = class Holiday extends Module {
/** @override */
start() {
Expand Down
11 changes: 10 additions & 1 deletion modules/hype.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ module.exports = class Hype extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
hype(msg) {
if (Application.modules.Discord.controlTalkedRecently(msg, this.config.hypeType, false, undefined, undefined, undefined, 120000)) {
msg.channel.send(Tools.parseReply(this.config.ans_hype, [this.bizaamEmoji]), { files:[path] });
msg.channel.send(
Tools.parseReply(
this.config.ans_hype,
this.bizaamEmoji.toString()
),
{ files: [path] }
);

Application.modules.Discord.setMessageSent();
}
Expand Down
21 changes: 15 additions & 6 deletions modules/inter-bot-com.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,27 @@ module.exports = class InterBotCom extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
check_wachmann_interaction(msg) {
if (msg.mentions.has(Application.getClient().user)) {
if (Tools.msg_contains(msg, "hey, don't boop me.")) {
setTimeout(function() {
msg.channel.send(Tools.parseReply(this.config.ans_boop_guard_response, [msg.author]));
}.bind(this), 2000);
setTimeout(() => {
msg.channel.send(Tools.parseReply(
this.config.ans_boop_guard_response,
msg.author.toString()
));
}, 2000);
}

if (Tools.msg_contains(msg, "what the hay!?")) {
setTimeout(function() {
msg.channel.send(Tools.parseReply(this.config.bapGuardResponse, [Application.modules.Discord.getEmoji("gc_cannishy")]));
}.bind(this), 2000);
setTimeout(() => {
msg.channel.send(Tools.parseReply(
this.config.bapGuardResponse,
Application.modules.Discord.getEmoji("gc_cannishy").toString()
));
}, 2000);
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions modules/no-message-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const Application = require("../lib/Application");
const Module = require("../lib/Module");
const Tools = require("../lib/Tools");
const remote_on = false;
/**
* I guess this is null because the associated functionality is disabled?
* @type { null }
*/
const remote_target = null;

/** @extends { Module<import("./no-message-processor-config.json")> } */
Expand All @@ -24,16 +28,22 @@ module.exports = class NoMessageProcessor extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
handle(msg) {
// When no message was sent, Canni either says she doesn't understand, or boops someone at random if she's not mentioned.
if (msg.mentions.has(Application.getClient().user)) {
if (!remote_on || remote_target !== msg.channel) {
msg.channel.send(Tools.parseReply(this.config.stillLearningAnswer, [Application.modules.Discord.getEmoji("gc_cannishy")]));
msg.channel.send(Tools.parseReply(
this.config.stillLearningAnswer,
Application.modules.Discord.getEmoji("gc_cannishy").toString()
));
}
} else {
const random = Tools.getRandomIntFromInterval(0, 500);
if (random === 10) {
msg.channel.send(Tools.parseReply(this.config.randomBoopAnswer, [msg.author]));
msg.channel.send(Tools.parseReply(this.config.randomBoopAnswer, msg.author.toString()));
}

if (random === 42) {
Expand Down
13 changes: 12 additions & 1 deletion modules/potato.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = class Potato extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
handle(msg) {
if (Tools.msg_contains_list(msg, this.config.phrase_potato)) {
return this.potato(msg, this.config.potatoType, this.config.ans_potato);
Expand All @@ -34,16 +37,24 @@ module.exports = class Potato extends Module {
}
}

/**
* @param { import("discord.js").Message } msg
* @param { string } type
* @param { Array<string> } answerType
*/
potato(msg, type, answerType) {
if (Application.modules.Discord.controlTalkedRecently(msg, type)) {
const random = Tools.getRandomIntFromInterval(0, answerType.length - 1);
msg.channel.send(Tools.parseReply(answerType[random], [msg.author])).then(sentEmbed => {
msg.channel.send(Tools.parseReply(answerType[random], msg.author.toString())).then(sentEmbed => {
this.potatofy(sentEmbed);
});
Application.modules.Discord.setMessageSent();
}
}

/**
* @param { import("discord.js").Message } msg
*/
potatofy(msg) {
if (Application.modules.Discord.checkUserAccess(msg.author)) {
msg.react(this.smartato_emo);
Expand Down
23 changes: 17 additions & 6 deletions modules/solver.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ module.exports = class Solver extends Module {
* @param { import("discord.js").Message } msg
*/
info(msg) {
msg.channel.send(Tools.parseReply(this.config.solver_info, [msg.author, this.smileEmoji]));
msg.channel.send(Tools.parseReply(
this.config.solver_info,
msg.author.toString(),
this.smileEmoji.toString()
));
Application.modules.Discord.setMessageSent();
}

Expand All @@ -57,15 +61,18 @@ module.exports = class Solver extends Module {
const alg = msg.content.split("solve");
if (alg.length > 1 && alg[1] !== "") {
this.single(alg[1]).then(function(res) {
msg.channel.send(Tools.parseReply(config.simple_solve, [msg.author, res])).catch(function(error) {
msg.channel.send(Tools.parseReply(config.simple_solve, msg.author.toString(), res)).catch(function(error) {
if (error.toString().toLowerCase().includes("must be 2000 or fewer in length")) {
msg.channel.send("I'm sorry. The result of your calculation is too long to be printed in Discord.");
}
Application.log.error(error);
});
});
} else {
msg.channel.send(Tools.parseReply(this.config.solver_nothing, [msg.author]));
msg.channel.send(Tools.parseReply(
this.config.solver_nothing,
msg.author.toString()
));
}
Application.modules.Discord.setMessageSent();
}
Expand All @@ -79,9 +86,13 @@ module.exports = class Solver extends Module {
if (alg.length > 1 && alg[1] !== "") {
this.multi(this.prepareMulti(alg[1].split(","))).then(function(res) {
if (res === "") {
msg.channel.send(Tools.parseReply(config.solver_no_output, [msg.author]));
msg.channel.send(Tools.parseReply(config.solver_no_output, msg.author.toString()));
} else {
msg.channel.send(Tools.parseReply(config.simple_multi_solve, [msg.author, res])).catch(function(error) {
msg.channel.send(Tools.parseReply(
config.simple_multi_solve,
msg.author.toString(),
res
)).catch(function(error) {
if (
Tools.msg_contains(error, "must be 2000 or fewer in length")
|| Tools.msg_contains(error, "must be 4000 or fewer in length")
Expand All @@ -94,7 +105,7 @@ module.exports = class Solver extends Module {
}
});
} else {
msg.channel.send(Tools.parseReply(this.config.solver_nothing, [msg.author]));
msg.channel.send(Tools.parseReply(this.config.solver_nothing, msg.author.toString()));
}
Application.modules.Discord.setMessageSent();
}
Expand Down
19 changes: 18 additions & 1 deletion modules/time-to-galacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = class TimeToGalacon extends Module {
});
}

/**
* @param { import("discord.js").Message } msg
*/
handleWhen(msg) {
if (Application.modules.Discord.checkUserAccess(msg.author)) {
if (active) {
Expand All @@ -46,6 +49,9 @@ module.exports = class TimeToGalacon extends Module {
}
}

/**
* @param { import("discord.js").Message } msg
*/
handleMessage(msg) {
if (Application.modules.Discord.checkUserAccess(msg.author) && msg.mentions.has(Application.modules.Discord.client.user)) {
if (Tools.msg_contains(msg, "when is galacon")) {
Expand Down Expand Up @@ -123,7 +129,12 @@ module.exports = class TimeToGalacon extends Module {
const duration = this.getTimeRemaining();
const random = Tools.getRandomIntFromInterval(0, this.config.galaconAnswer.length - 1);

msg.channel.send(Tools.parseReply(this.config.timeAnswer, [duration.days, duration.hrs, duration.minutes]) + "\n" + this.config.galaconAnswer[random]);
msg.channel.send(Tools.parseReply(
this.config.timeAnswer,
duration.days.toString(),
duration.hrs,
duration.minutes
) + "\n" + this.config.galaconAnswer[random]);

Application.modules.Discord.setMessageSent();
}
Expand All @@ -140,13 +151,19 @@ module.exports = class TimeToGalacon extends Module {
}

getTimeRemaining() {
// i dunno what's going on here
// but it works so i'm not touching it :p ~vt

const duration = this.galaconDate.diff(moment());
// @ts-expect-error
let seconds = parseInt(duration) / 1000;
const days = Math.floor(seconds / (3600 * 24));
seconds -= days * 3600 * 24;
const hrs = Tools.padTime(Math.floor(seconds / 3600));
// @ts-expect-error
seconds -= hrs * 3600;
const minutes = Tools.padTime(Math.floor(seconds / 60));
// @ts-expect-error
seconds -= minutes * 60;

return {
Expand Down

0 comments on commit ca1fd1c

Please sign in to comment.