Implement Nag service
This commit is contained in:
@@ -1,24 +1,48 @@
|
||||
import {ChatInputCommandInteraction, SlashCommandBuilder} from 'discord.js';
|
||||
import {
|
||||
type ChatInputCommandInteraction,
|
||||
SlashCommandBuilder,
|
||||
} from "discord.js";
|
||||
|
||||
import {Settings} from './common';
|
||||
import type { Settings } from "./service";
|
||||
|
||||
import {Nag, CheckIn} from './common';
|
||||
import { Nag, CheckIn } from "./service";
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName('checkin')
|
||||
.setDescription('Check-in for your daily nag')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('text')
|
||||
.setDescription('Optional description of what you have achieved'),
|
||||
);
|
||||
.setName("checkin")
|
||||
.setDescription("Check-in for your daily nag")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("text")
|
||||
.setDescription("Optional description of what you have achieved"),
|
||||
);
|
||||
|
||||
async function initialize(settings: Settings) {}
|
||||
|
||||
function execute(interaction: ChatInputCommandInteraction) {}
|
||||
async function execute(interaction: ChatInputCommandInteraction) {
|
||||
// TODO For now there is only one nag, but in the future this could be different. So let's construct it as a loop for now.
|
||||
const result = await Nag.findAll({
|
||||
where: {
|
||||
userId: interaction.user.id,
|
||||
},
|
||||
});
|
||||
if (!result) {
|
||||
await interaction.reply(
|
||||
"Couldn't find any nags for you, what are you checking in for?",
|
||||
);
|
||||
return;
|
||||
}
|
||||
for (const nag of result) {
|
||||
await CheckIn.create({
|
||||
nagId: nag.id,
|
||||
lastCheckIn: new Date(Date.now()),
|
||||
});
|
||||
await interaction.reply("Thanks for checking in!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export default function () {
|
||||
return {
|
||||
data,
|
||||
};
|
||||
return {
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user