WIP: Format code with Google Typescript formatting guidelines
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||
import {ChatInputCommandInteraction, SlashCommandBuilder} from 'discord.js';
|
||||
|
||||
import { Settings } from "./common";
|
||||
import {Settings} from './common';
|
||||
|
||||
import { Nag, CheckIn } from './common';
|
||||
import {Nag, CheckIn} from './common';
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("checkin")
|
||||
.setDescription("Check-in for your daily nag")
|
||||
.addStringOption((option) =>
|
||||
.setName('checkin')
|
||||
.setDescription('Check-in for your daily nag')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("text")
|
||||
.setDescription("Optional description of what you have achieved"),
|
||||
.setName('text')
|
||||
.setDescription('Optional description of what you have achieved'),
|
||||
);
|
||||
|
||||
async function initialize(settings: Settings) {}
|
||||
|
||||
function execute(interaction: ChatInputCommandInteraction) {
|
||||
|
||||
}
|
||||
function execute(interaction: ChatInputCommandInteraction) {}
|
||||
|
||||
export default function () {
|
||||
return {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
Client,
|
||||
SlashCommandBuilder,
|
||||
TextChannel,
|
||||
} from "discord.js";
|
||||
} from 'discord.js';
|
||||
import {
|
||||
Sequelize,
|
||||
Model,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
BOOLEAN,
|
||||
DATE,
|
||||
literal,
|
||||
} from "sequelize";
|
||||
} from 'sequelize';
|
||||
|
||||
export interface Settings {
|
||||
client: Client; // Main Discord client object
|
||||
@@ -63,7 +63,7 @@ export async function initAndSyncTables(sequelize: Sequelize) {
|
||||
type: BOOLEAN,
|
||||
},
|
||||
},
|
||||
{ sequelize },
|
||||
{sequelize},
|
||||
);
|
||||
CheckIn.init(
|
||||
{
|
||||
@@ -76,14 +76,14 @@ export async function initAndSyncTables(sequelize: Sequelize) {
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{ sequelize },
|
||||
{sequelize},
|
||||
);
|
||||
Nag.hasOne(CheckIn, { foreignKey: "nagId" });
|
||||
Nag.hasOne(CheckIn, {foreignKey: 'nagId'});
|
||||
await Nag.sync();
|
||||
await CheckIn.sync();
|
||||
}
|
||||
|
||||
import { Guild, Channel } from "discord.js";
|
||||
import {Guild, Channel} from 'discord.js';
|
||||
|
||||
export class Plugin {
|
||||
settings: Settings;
|
||||
@@ -106,7 +106,7 @@ export class Plugin {
|
||||
|
||||
async triggerNag(nag: Nag) {
|
||||
const client = this.settings.client;
|
||||
const chan = client.channels.cache.get("1234"); // TODO
|
||||
const chan = client.channels.cache.get('1234'); // TODO
|
||||
if (!(chan instanceof TextChannel)) {
|
||||
return; // TODO
|
||||
}
|
||||
@@ -114,16 +114,16 @@ export class Plugin {
|
||||
const failText =
|
||||
nag.failText ??
|
||||
`<@${nag.userId}> didn't complete "${nag.text}". Shame shame!`;
|
||||
const mentionHere = nag.mentionHere ? "<@here> " : "";
|
||||
const mentionHere = nag.mentionHere ? '<@here> ' : '';
|
||||
const msg = `${mentionHere}${failText}`;
|
||||
await chan.send(msg);
|
||||
} catch (error) {
|
||||
console.log("Error while creating Nag:", error); // TODO
|
||||
console.log('Error while creating Nag:', error); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
async loop() {
|
||||
console.debug("nag.js main loop");
|
||||
console.debug('nag.js main loop');
|
||||
// Find all nags where the last check-in was before (next check in) - (24 hours)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,30 @@ import {
|
||||
ChatInputCommandInteraction,
|
||||
Client,
|
||||
SlashCommandBuilder,
|
||||
} from "discord.js";
|
||||
import { Sequelize, literal } from "sequelize";
|
||||
} from 'discord.js';
|
||||
import {Sequelize, literal} from 'sequelize';
|
||||
|
||||
import { Nag, CheckIn, Settings } from "./common";
|
||||
import { Chrono } from "chrono-node";
|
||||
import {Nag, CheckIn, Settings} from './common';
|
||||
import {Chrono} from 'chrono-node';
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("nag")
|
||||
.setDescription("Let Blitzcrank nag you every day about something")
|
||||
.addStringOption((option) =>
|
||||
.setName('nag')
|
||||
.setDescription('Let Blitzcrank nag you every day about something')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setRequired(true)
|
||||
.setName("text")
|
||||
.setDescription("What you have to do every day"),
|
||||
.setName('text')
|
||||
.setDescription('What you have to do every day'),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("failText")
|
||||
.setDescription("Custom message to be broadcast on failure"),
|
||||
.setName('failText')
|
||||
.setDescription('Custom message to be broadcast on failure'),
|
||||
)
|
||||
.addBooleanOption((option) =>
|
||||
.addBooleanOption(option =>
|
||||
option
|
||||
.setName("mentionHere")
|
||||
.setDescription("Whether to DM you or @ a channel")
|
||||
.setName('mentionHere')
|
||||
.setDescription('Whether to DM you or @ a channel')
|
||||
.setRequired(false),
|
||||
);
|
||||
|
||||
@@ -41,7 +41,7 @@ function lateCheckedInUsers() {
|
||||
async function initialize(settings: Settings) {}
|
||||
|
||||
async function execute(interaction: ChatInputCommandInteraction) {
|
||||
const text = interaction.options.getString("text");
|
||||
const text = interaction.options.getString('text');
|
||||
if (text === null || text === undefined) {
|
||||
await interaction.reply("Nag can't have a blank `text`, try again.");
|
||||
return;
|
||||
@@ -49,15 +49,15 @@ async function execute(interaction: ChatInputCommandInteraction) {
|
||||
const nag = await Nag.create({
|
||||
userId: interaction.user.id,
|
||||
text: text,
|
||||
failText: interaction.options.getString("failText"),
|
||||
mentionHere: interaction.options.getBoolean("mentionHere") ?? false,
|
||||
failText: interaction.options.getString('failText'),
|
||||
mentionHere: interaction.options.getBoolean('mentionHere') ?? false,
|
||||
});
|
||||
await nag.save();
|
||||
const chrono = new Chrono();
|
||||
const checkIn = chrono.parseDate("today at 9AM");
|
||||
const checkIn = chrono.parseDate('today at 9AM');
|
||||
if (!checkIn) {
|
||||
await interaction.reply(
|
||||
"Internal error while saving your nag. Tell Drew the bot is broken!!!",
|
||||
'Internal error while saving your nag. Tell Drew the bot is broken!!!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@ import {
|
||||
ChatInputCommandInteraction,
|
||||
Client,
|
||||
SlashCommandBuilder,
|
||||
} from "discord.js";
|
||||
import { Sequelize } from "sequelize";
|
||||
|
||||
import { Settings } from './common'
|
||||
} from 'discord.js';
|
||||
import {Sequelize} from 'sequelize';
|
||||
|
||||
import {Settings} from './common';
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("unnag")
|
||||
.setDescription("Remove a nag");
|
||||
.setName('unnag')
|
||||
.setDescription('Remove a nag');
|
||||
|
||||
|
||||
async function initialize(settings: Settings) {
|
||||
}
|
||||
async function initialize(settings: Settings) {}
|
||||
|
||||
async function execute(interaction: ChatInputCommandInteraction) {
|
||||
return;
|
||||
@@ -24,6 +21,6 @@ export default function (settings: Settings) {
|
||||
return {
|
||||
data,
|
||||
execute,
|
||||
initialize: async() => await initialize(settings),
|
||||
initialize: async () => await initialize(settings),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { type Client, SlashCommandBuilder } from "discord.js";
|
||||
import type { Sequelize } from "sequelize";
|
||||
import {type Client, SlashCommandBuilder} from 'discord.js';
|
||||
import type {Sequelize} from 'sequelize';
|
||||
|
||||
export default function (settings: { client: Client; db: Sequelize }) {
|
||||
export default function (settings: {client: Client; db: Sequelize}) {
|
||||
return {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Send a ping to the bot"),
|
||||
.setName('ping')
|
||||
.setDescription('Send a ping to the bot'),
|
||||
|
||||
initialize: async () => {},
|
||||
|
||||
execute: async (interaction) => {
|
||||
execute: async interaction => {
|
||||
await interaction.reply(
|
||||
`Pong! This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user