Skip to content

Commit f643969

Browse files
committed
Port /randtopic to the sim
Per request from staff, since Officer Jenny has been taken down, this is one of the commands they'd like ported.
1 parent 693ee84 commit f643969

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

server/chat-commands/info.ts

+62
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,52 @@ export const commands: Chat.ChatCommands = {
29902990
altsloghelp: [
29912991
`/altslog [userid] - View the alternate account history for the given [userid]. Requires: % @ &`,
29922992
],
2993+
2994+
randtopic(target, room, user) {
2995+
room = this.requireRoom();
2996+
if (!room.settings.topics?.length) {
2997+
return this.errorReply(`This room has no random topics to select from.`);
2998+
}
2999+
this.runBroadcast();
3000+
this.sendReply(Utils.html`|html|<div class="broadcast-blue">${Utils.randomElement(room.settings.topics)}</div>`);
3001+
},
3002+
3003+
addtopic(target, room, user) {
3004+
room = this.requireRoom();
3005+
this.checkCan('mute', null, room);
3006+
target = target.trim();
3007+
if (!toID(target).length) {
3008+
return this.parse(`/help addtopic`);
3009+
}
3010+
if (!room.settings.topics) room.settings.topics = [];
3011+
room.settings.topics.push(target);
3012+
this.privateModAction(`${user.name} added the topic "${target}" to the random topic pool.`);
3013+
this.modlog('ADDTOPIC', null, target);
3014+
room.saveSettings();
3015+
},
3016+
addtopichelp: [`/addtopic [target] - Adds the [target] to the pool of random discussion topics. Requires: % @ # &`],
3017+
3018+
removetopic(target, room, user) {
3019+
room = this.requireRoom();
3020+
this.checkCan('mute', null, room);
3021+
const index = Number(toID(target)) - 1;
3022+
if (isNaN(index)) {
3023+
return this.errorReply(`Invalid topic index: ${target}. Must be a number.`);
3024+
}
3025+
if (!room.settings.topics?.[index]) {
3026+
return this.errorReply(`Topic ${index + 1} not found.`);
3027+
}
3028+
const topic = room.settings.topics.splice(index, 1)[0];
3029+
room.saveSettings();
3030+
this.privateModAction(`${user.name} removed topic ${index + 1} from the random topic pool.`);
3031+
this.modlog('REMOVETOPIC', null, topic);
3032+
},
3033+
removetopichelp: [`/removetopic [index] - Removes the topic from the room's topic pool. Requires: % @ # &`],
3034+
3035+
randomtopics(target, room, user) {
3036+
room = this.requireRoom();
3037+
return this.parse(`/join view-topics-${room}`);
3038+
},
29933039
};
29943040

29953041
export const handlers: Chat.Handlers = {
@@ -3065,6 +3111,22 @@ export const pages: Chat.PageTable = {
30653111
}
30663112
return buf;
30673113
},
3114+
topics(query, user) {
3115+
const room = this.requireRoom();
3116+
this.title = `[Topics] ${room.title}`;
3117+
const topics = room.settings.topics || [];
3118+
let buf;
3119+
if (!topics.length) {
3120+
buf = `<div class="pad"><h2>This room has no discussion topics saved.</h2></div>`;
3121+
return buf;
3122+
}
3123+
buf = `<div class="pad"><h2>Random topics for ${room.title} (${topics.length}):</h2><ul>`;
3124+
for (const [i, topic] of topics.entries()) {
3125+
buf += Utils.html`<li>${i + 1}: "${topic}"</li>`;
3126+
}
3127+
buf += `</ul></div>`;
3128+
return buf;
3129+
},
30683130
battlerules(query, user) {
30693131
const rules = Object.values(Dex.data.Rulesets).filter(rule => rule.effectType !== "Format");
30703132
const tourHelp = `https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-forum-rules-resources-read-here-first.3570628/#post-6777489`;

server/rooms.ts

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface RoomSettings {
121121
minorActivity?: PollData | AnnouncementData;
122122
minorActivityQueue?: MinorActivityData[];
123123
repeats?: RepeatedPhrase[];
124+
topics?: string[];
124125
autoModchat?: {
125126
rank: GroupSymbol,
126127
time: number,

0 commit comments

Comments
 (0)