Skip to content

Commit ded3afc

Browse files
authored
updated qotd remove command (#255)
1 parent d1e3dfd commit ded3afc

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/commands/admin/qotd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = new Command({
4242
.setColor(0xA47DAB)
4343
.setDescription(
4444
queue.map((q, i) =>
45-
`#${i + 1} (ID ${q.id}) - ${q.question}`)
45+
`#${i + 1} - ${q.question}`)
4646
.join('\n') || 'Queue is empty.');
4747
message.channel.send({ embeds: [queueEmbed] });
4848
break;

src/database/qotd.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ module.exports = {
5454
getPast: () => all(
5555
'SELECT * FROM past_questions ORDER BY posted_at DESC LIMIT 10'),
5656

57-
removeQuestion: (id) => run('DELETE FROM queue WHERE id = ?', [id]),
57+
removeQuestion: async (position) => {
58+
const index = parseInt(position) - 1;
59+
if (isNaN(index) || index < 0) throw new Error('Invalid position');
60+
61+
const target = await get(
62+
'SELECT id FROM queue ORDER BY priority DESC, id ASC LIMIT 1 OFFSET ?',
63+
[index]
64+
);
65+
66+
if (target) {
67+
return run('DELETE FROM queue WHERE id = ?', [target.id]);
68+
}
69+
return null;
70+
},
5871

5972
popNext: async () => {
6073
const next = await get(

0 commit comments

Comments
 (0)