@@ -2990,6 +2990,52 @@ export const commands: Chat.ChatCommands = {
2990
2990
altsloghelp : [
2991
2991
`/altslog [userid] - View the alternate account history for the given [userid]. Requires: % @ &` ,
2992
2992
] ,
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
+ } ,
2993
3039
} ;
2994
3040
2995
3041
export const handlers : Chat . Handlers = {
@@ -3065,6 +3111,22 @@ export const pages: Chat.PageTable = {
3065
3111
}
3066
3112
return buf ;
3067
3113
} ,
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
+ } ,
3068
3130
battlerules ( query , user ) {
3069
3131
const rules = Object . values ( Dex . data . Rulesets ) . filter ( rule => rule . effectType !== "Format" ) ;
3070
3132
const tourHelp = `https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-forum-rules-resources-read-here-first.3570628/#post-6777489` ;
0 commit comments