From 964f4f8d06bfb58fb2b17f263d3e72e5b9e49fc9 Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Thu, 23 Jul 2020 14:05:45 -0500 Subject: [PATCH] Add a command for bots to send HTML pages (#6934) --- server/chat-commands/admin.ts | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/server/chat-commands/admin.ts b/server/chat-commands/admin.ts index 0baad3adfe11..04515e8c2465 100644 --- a/server/chat-commands/admin.ts +++ b/server/chat-commands/admin.ts @@ -217,6 +217,25 @@ export const commands: ChatCommands = { `/pmuhtmlchange [user], [name], [html] - Changes html that was previously PMed to [user] to [html]. Requires * # &`, ], + sendhtmlpage(target, room, user, connection) { + if (!this.can('addhtml', null, room)) return false; + let [targetID, pageid, content] = Utils.splitFirst(target, ',', 2); + if (!target || !pageid || !content) return this.parse(`/help sendhtmlpage`); + const targetUser = Users.get(targetID); + if (!targetUser) return this.errorReply(`User not found.`); + content = this.canHTML(content)!; + if (!content) return; + const context = new Chat.PageContext({ + user: targetUser, + connection: targetUser.connections[0], + pageid: `view-bot-${user.id}-${toID(pageid)}`, + }); + context.title = `[${user.name}] ${pageid}`; + return context.send(content); + }, + sendhtmlpagehelp: [ + `/sendhtmlpage: [target], [page id], [html] - sends the [target] a HTML room with the HTML [content] and the [pageid]. Requires: s* # &`, + ], nick() { this.sendReply(`||New to the Pokémon Showdown protocol? Your client needs to get a signed assertion from the login server and send /trn`); this.sendReply(`||https://github.com/smogon/pokemon-showdown/blob/master/PROTOCOL.md#global-messages`); @@ -1090,3 +1109,28 @@ export const commands: ChatCommands = { `[player] must be a username or number, [pokemon] must be species name or party slot number (not nickname), [move] must be move name.`, ], }; + +export const pages: PageTable = { + bot(args, user) { + const [botid, pageid] = args; + const bot = Users.get(botid); + if (!bot) { + return `

The bot "${bot}" is not available.

`; + } + let canSend = Users.globalAuth.get(bot) === '*'; + let room; + for (const curRoom of Rooms.global.chatRooms) { + if (curRoom.auth.get(bot) === '*') { + canSend = true; + room = curRoom; + } + } + if (!canSend) { + return `

"${bot}" is not a bot.

`; + } + bot.sendTo( + room ? room.roomid : 'lobby', + `|pm|${user.name}|${bot.name}||requestpage|${user.name}|${pageid}` + ); + }, +};