WIP: Format code with Google Typescript formatting guidelines

This commit is contained in:
2025-07-04 10:39:32 -04:00
parent e53d38e0ad
commit c834acdfec
12 changed files with 596 additions and 235 deletions

View File

@@ -5,10 +5,10 @@ import {
TextChannel,
type ChatInputCommandInteraction,
type Client,
} from "discord.js";
import { type Sequelize, Model, INTEGER, TEXT, DATE, BOOLEAN } from "sequelize";
import * as sequelize from "sequelize";
import * as chrono from "chrono-node";
} from 'discord.js';
import {type Sequelize, Model, INTEGER, TEXT, DATE, BOOLEAN} from 'sequelize';
import * as sequelize from 'sequelize';
import * as chrono from 'chrono-node';
// const REMINDERS_CHANNEL = "1062196593379520593"; // #bot-test-channel
// const REMINDERS_CHANNEL = ""; // #general
@@ -22,18 +22,18 @@ interface Settings {
}
const data = new SlashCommandBuilder()
.setName("remind")
.setDescription("Remind me to do something")
.addStringOption((option) =>
.setName('remind')
.setDescription('Remind me to do something')
.addStringOption(option =>
option
.setName("when")
.setDescription("Short description of when you want the reminder")
.setName('when')
.setDescription('Short description of when you want the reminder')
.setRequired(true),
)
.addStringOption((option) =>
.addStringOption(option =>
option
.setName("what")
.setDescription("Short description of what you want to be reminded of")
.setName('what')
.setDescription('Short description of what you want to be reminded of')
.setRequired(true),
);
@@ -62,17 +62,17 @@ class Plugin {
// if (this.settings.responseMode === "private") {
// channel = getSendableTextChannel(client, reminder.requestChannel);
// }
if (this.settings.responseMode === "public" || !channel) {
if (this.settings.responseMode === 'public' || !channel) {
channel = getSendableTextChannel(client, publicChannel);
}
if (!channel) {
throw Error("Cannot find valid channel to send reminder on");
throw Error('Cannot find valid channel to send reminder on');
}
return channel;
}
async loop() {
console.debug("remind.js main loop");
console.debug('remind.js main loop');
const results = await Reminder.findAll({
// NOTE: 'trigger' is the time when the reminder should go off. If trigger -
// now is positive, trigger is in the future. If trigger - now <=
@@ -87,7 +87,7 @@ class Plugin {
const now = new Date(Date.now());
const delay = reminder.trigger.getTime() - now.getTime();
console.log(
`Callback for Reminder ${reminder.get("id")} triggering in ${delay}ms`,
`Callback for Reminder ${reminder.get('id')} triggering in ${delay}ms`,
);
const channel = this.getChannel(reminder);
setTimeout(async () => await triggerReminder(channel, reminder), delay);
@@ -113,7 +113,7 @@ class Plugin {
}
async function initialize(settings: Settings) {
console.log("Initializing remind.js");
console.log('Initializing remind.js');
// Populate Reminder table inside SQLite DB
Reminder.init(
@@ -136,7 +136,7 @@ async function initialize(settings: Settings) {
requestChannel: TEXT,
requestMessage: TEXT,
},
{ sequelize: settings.db },
{sequelize: settings.db},
);
await Reminder.sync();
@@ -144,13 +144,13 @@ async function initialize(settings: Settings) {
console.debug(`Accessing channel ${settings.publicChannel}`);
if (!getSendableTextChannel(settings.client, settings.publicChannel)) {
throw Error(
"Invalid value for publicChannel; specify a channel the bot can access.",
'Invalid value for publicChannel; specify a channel the bot can access.',
);
}
// Initialize the 'plugin' object which will store all state required to control the mainloop.
if (settings.loopIntervalSec == null || settings.loopIntervalSec <= 0) {
console.log("Setting plugin loop interval to default of 60 seconds");
console.log('Setting plugin loop interval to default of 60 seconds');
settings.loopIntervalSec = 60;
}
const plugin = new Plugin(settings);
@@ -164,13 +164,13 @@ function getSendableTextChannel(client: Client, chanId: string) {
throw Error("Can't check non-existent client");
}
if (!channel) {
throw Error("No such channel is visible to Blitz");
throw Error('No such channel is visible to Blitz');
}
if (!channel?.isSendable()) {
throw Error("Channel is not a text channel, or otherwise not Sendable");
throw Error('Channel is not a text channel, or otherwise not Sendable');
}
if (!(channel instanceof TextChannel)) {
throw Error("Channel is not a guild channel");
throw Error('Channel is not a guild channel');
}
const permissions = channel?.permissionsFor(client.user);
const requiredPerms = new PermissionsBitField([
@@ -178,7 +178,7 @@ function getSendableTextChannel(client: Client, chanId: string) {
PermissionsBitField.Flags.ViewChannel,
]);
if (!permissions?.has(requiredPerms)) {
throw Error("Missing required permissions: SendMessages, ViewChannel");
throw Error('Missing required permissions: SendMessages, ViewChannel');
}
return channel;
}
@@ -197,7 +197,7 @@ async function triggerReminder(channel: TextChannel, reminder: Reminder) {
}
async function execute(interaction: ChatInputCommandInteraction) {
const whenString = interaction.options.getString("when") ?? "now";
const whenString = interaction.options.getString('when') ?? 'now';
const when = chrono.parseDate(whenString);
if (!when) {
await interaction.reply(`Sorry, I don't understand '${when}' as a date`);
@@ -205,7 +205,7 @@ async function execute(interaction: ChatInputCommandInteraction) {
}
const reminder = await Reminder.create({
userId: interaction.user.id,
text: interaction.options.getString("what"),
text: interaction.options.getString('what'),
trigger: when, // TODO
requestMessage: interaction.id,
requestChannel: interaction.channelId,