Skip to content

Commit

Permalink
Use new requireRoom API in trivia and scavs (#7553)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscke committed Oct 21, 2020
1 parent c6aa139 commit bbb550b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 48 deletions.
18 changes: 6 additions & 12 deletions server/chat-plugins/scavengers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1865,8 +1865,7 @@ const ScavengerCommands: ChatCommands = {
* Leaderboard Commands
*/
addpoints(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('mute', null, room);

const parts = target.split(',');
Expand All @@ -1883,8 +1882,7 @@ const ScavengerCommands: ChatCommands = {
},

removepoints(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('mute', null, room);

const parts = target.split(',');
Expand All @@ -1901,8 +1899,7 @@ const ScavengerCommands: ChatCommands = {
},

resetladder(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('declare', null, room);

Leaderboard.reset().write();
Expand Down Expand Up @@ -2161,8 +2158,7 @@ const ScavengerCommands: ChatCommands = {
*/
huntcount: 'huntlogs',
async huntlogs(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('mute', null, room);

if (target === 'RESET') {
Expand Down Expand Up @@ -2207,8 +2203,7 @@ const ScavengerCommands: ChatCommands = {
},

async playlogs(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('mute', null, room);

if (target === 'RESET') {
Expand Down Expand Up @@ -2263,8 +2258,7 @@ const ScavengerCommands: ChatCommands = {

uninfract: "infract",
infract(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'scavengers') return this.errorReply("This command can only be used in the scavengers room.");
room = this.requireRoom('scavengers' as RoomID);
this.checkCan('mute', null, room);

const targetId = toID(target);
Expand Down
47 changes: 11 additions & 36 deletions server/chat-plugins/trivia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1692,10 +1692,7 @@ const triviaCommands: ChatCommands = {

submit: 'add',
add(target, room, user, connection, cmd) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);
if (cmd === 'add') this.checkCan('mute', null, room);
if (cmd === 'submit') this.checkCan('show', null, room);
if (!target) return false;
Expand Down Expand Up @@ -1777,10 +1774,7 @@ const triviaCommands: ChatCommands = {
addhelp: [`/trivia add [category] | [question] | [answer1], [answer2], ... [answern] - Adds question(s) to the question database. Requires: % @ # &`],

review(target, room) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('ban', null, room);

const submissions = triviaData.submissions;
Expand All @@ -1805,10 +1799,7 @@ const triviaCommands: ChatCommands = {

reject: 'accept',
accept(target, room, user, connection, cmd) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('ban', null, room);
this.checkChat();

Expand Down Expand Up @@ -1897,10 +1888,7 @@ const triviaCommands: ChatCommands = {
rejecthelp: [`/trivia reject [index1], [index2], ... [indexn] OR all - Remove questions from the submission database using their index numbers or ranges of them. Requires: @ # &`],

delete(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('mute', null, room);
this.checkChat();

Expand Down Expand Up @@ -1928,10 +1916,7 @@ const triviaCommands: ChatCommands = {
deletehelp: [`/trivia delete [question] - Delete a question from the trivia database. Requires: % @ # &`],

move(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('mute', null, room);
this.checkChat();

Expand Down Expand Up @@ -1984,10 +1969,7 @@ const triviaCommands: ChatCommands = {
],

qs(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr('This command can only be used in Question Workshop.'));
}
room = this.requireRoom('questionworkshop' as RoomID);

let buffer = "|raw|<div class=\"ladder\" style=\"overflow-y: scroll; max-height: 300px;\"><table>";
if (!target) {
Expand Down Expand Up @@ -2052,8 +2034,7 @@ const triviaCommands: ChatCommands = {
cssearch: 'search',
casesensitivesearch: 'search',
search(target, room, user, connection, cmd) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') return this.errorReply("This command can only be used in Question Workshop.");
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('show', null, room);
if (!target.includes(',')) return this.errorReply(this.tr("No valid search arguments entered."));

Expand Down Expand Up @@ -2159,10 +2140,7 @@ const triviaCommands: ChatCommands = {

clearquestions: 'clearqs',
clearqs(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'questionworkshop') {
return this.errorReply(this.tr("This command can only be used in Question Workshop"));
}
room = this.requireRoom('questionworkshop' as RoomID);
this.checkCan('declare', null, room);
target = toID(target);
const category = CATEGORY_ALIASES[target] || target;
Expand All @@ -2182,8 +2160,7 @@ const triviaCommands: ChatCommands = {

pastgames: 'history',
history(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'trivia') return this.errorReply(this.tr("This command can only be used in Trivia."));
room = this.requireRoom('trivia' as RoomID);
if (!this.runBroadcast()) return false;
if (!triviaData.history?.length) return this.sendReplyBox(this.tr("There is no game history."));

Expand All @@ -2202,8 +2179,7 @@ const triviaCommands: ChatCommands = {

removepoints: 'addpoints',
addpoints(target, room, user, connection, cmd) {
room = this.requireRoom();
if (room.roomid !== 'trivia') return this.errorReply(this.tr("This command can only be used in Trivia."));
room = this.requireRoom('trivia' as RoomID);
this.checkCan('editroom', null, room);

const [userid, pointString] = this.splitOne(target).map(toID);
Expand Down Expand Up @@ -2236,8 +2212,7 @@ const triviaCommands: ChatCommands = {
],

removeleaderboardentry(target, room, user) {
room = this.requireRoom();
if (room.roomid !== 'trivia') return this.errorReply(this.tr("This command can only be used in Trivia."));
room = this.requireRoom('trivia' as RoomID);
this.checkCan('editroom', null, room);

const userid = toID(target);
Expand Down

0 comments on commit bbb550b

Please sign in to comment.