Add support to /removequote last (#10472)

* Allow removing last quote

Standarize with a1ced8d4b3

* Update server/chat-plugins/quotes.ts

* oops

---------

Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>
This commit is contained in:
Sergio Garcia 2024-08-06 07:42:50 +02:00 committed by GitHub
parent 90d35efe0d
commit 9c2da0a7fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -83,17 +83,17 @@ export const commands: Chat.ChatCommands = {
room = this.requireRoom();
this.checkCan('mute', null, room);
if (!quotes[room.roomid]?.length) return this.errorReply(`This room has no quotes.`);
const index = parseInt(target.trim());
const roomQuotes = quotes[room.roomid];
const index = toID(target) === 'last' ? roomQuotes.length - 1 : parseInt(toID(target)) - 1;
if (isNaN(index)) {
return this.errorReply(`Invalid index.`);
}
const roomQuotes = quotes[room.roomid];
if (!roomQuotes[index - 1]) {
if (!roomQuotes[index]) {
return this.errorReply(`Quote not found.`);
}
const [removed] = roomQuotes.splice(index - 1, 1);
const [removed] = roomQuotes.splice(index, 1);
const collapsedQuote = removed.quote.replace(/\n/g, ' ');
this.privateModAction(`${user.name} removed quote indexed at ${index}: "${collapsedQuote}" (originally added by ${removed.userid}).`);
this.privateModAction(`${user.name} removed quote indexed at ${index + 1}: "${collapsedQuote}" (originally added by ${removed.userid}).`);
this.modlog(`REMOVEQUOTE`, null, collapsedQuote);
saveQuotes();
this.refreshPage(`quotes-${room.roomid}`);