separate sync and load

This commit is contained in:
2023-06-16 22:42:07 +02:00
parent 4360b33f79
commit 3c9b17febd
2 changed files with 57 additions and 21 deletions
+1 -21
View File
@@ -10,7 +10,7 @@ import db, { checkMemberPermissions, execute, insertGoob } from '../db'
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('load') .setName('load')
.setDescription('Synchronise all past and future goobers from this channel'), .setDescription('Loads all past goobers from this channel'),
async execute (interaction: CommandInteraction) { async execute (interaction: CommandInteraction) {
if (interaction.user.id !== owner_id) { if (interaction.user.id !== owner_id) {
await interaction.reply({ await interaction.reply({
@@ -30,9 +30,6 @@ module.exports = {
return return
} }
db.run('DELETE FROM goob WHERE guild = $guild', {
$guild: interaction.guildId
})
db.run('DELETE FROM tracked WHERE guild = $guild', { db.run('DELETE FROM tracked WHERE guild = $guild', {
$guild: interaction.guildId $guild: interaction.guildId
}) })
@@ -82,23 +79,6 @@ module.exports = {
await interaction.editReply( await interaction.editReply(
`Loading complete ! loaded ${loaded} messages with ${loadedImages} images` `Loading complete ! loaded ${loaded} messages with ${loadedImages} images`
) )
const reply = await interaction.fetchReply()
if (reply === undefined) {
await interaction.reply({
content: 'Impossible to fetch reply. Did something go wrong ?',
ephemeral: true
})
return
}
db.run(
'INSERT INTO tracked (guild, last_message, channel) VALUES ($guild, $last_message, $channel)',
{
$guild: interaction.guildId,
$channel: interaction.channelId,
$last_message: reply.id
}
)
const length = await execute('SELECT count(*) as count from goob') const length = await execute('SELECT count(*) as count from goob')
interaction.client.user?.setActivity(`${length[0].count as string} goobers`, { interaction.client.user?.setActivity(`${length[0].count as string} goobers`, {
type: ActivityType.Listening type: ActivityType.Listening
+56
View File
@@ -0,0 +1,56 @@
import {
type CommandInteraction,
SlashCommandBuilder,
ActivityType
} from 'discord.js'
import { owner_id } from '../config.json'
import db, { execute } from '../db'
module.exports = {
data: new SlashCommandBuilder()
.setName('sync')
.setDescription('Synchronise all past and future goobers from this channel'),
async execute (interaction: CommandInteraction) {
if (interaction.user.id !== owner_id) {
await interaction.reply({
content: 'You do not have access to this command!',
ephemeral: true
})
return
}
if (
interaction.channel?.isDMBased() === true ||
interaction.guild === undefined
) {
await interaction.reply({
content: 'This command is disabled for DM channels',
ephemeral: true
})
return
}
await interaction.client.commands.get('load')?.execute(interaction)
const reply = await interaction.fetchReply()
if (reply === undefined) {
await interaction.reply({
content: 'Impossible to fetch reply. Did something go wrong ?',
ephemeral: true
})
return
}
db.run(
'INSERT INTO tracked (guild, last_message, channel) VALUES ($guild, $last_message, $channel)',
{
$guild: interaction.guildId,
$channel: interaction.channelId,
$last_message: reply.id
}
)
const length = await execute('SELECT count(*) as count from goob')
interaction.client.user?.setActivity(`${length[0].count as string} goobers`, {
type: ActivityType.Listening
})
}
}