From 20336fdfa0e042a2ab0ce1861653ef4e97e82f4f Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Thu, 18 Jun 2020 23:47:17 -0700 Subject: [PATCH] Refactor /requestshow --- server/chat-commands/info.ts | 26 +++++++++++++------------- server/rooms.ts | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/chat-commands/info.ts b/server/chat-commands/info.ts index af5323c5d0..818a89aa87 100644 --- a/server/chat-commands/info.ts +++ b/server/chat-commands/info.ts @@ -2443,16 +2443,16 @@ export const commands: ChatCommands = { if (this.can('showmedia', null, room)) return this.errorReply(`Use !show instead.`); if (room.pendingApprovals?.has(user.id)) return this.errorReply('You have a request pending already.'); if (!toID(target)) return this.parse(`/help requestshow`); + let [link, comment] = target.split(','); if (!/^https?:\/\//.test(link)) link = `https://${link}`; link = encodeURI(link); if (!room.pendingApprovals) room.pendingApprovals = new Map(); - const info = { + room.pendingApprovals.set(user.id, { name: user.name, link: link, comment: comment, - }; - room.pendingApprovals.set(user.id, info); + }); this.sendReply(`You have requested to show the link: ${link}${comment ? ` (with the comment ${comment})` : ''}.`); room.sendMods( Utils.html`|uhtml|request-${user.id}|
${user.name} wants to show ${link}
` + @@ -2470,8 +2470,8 @@ export const commands: ChatCommands = { } const userid = toID(target); if (!userid) return this.parse(`/help approveshow`); - const info = room.pendingApprovals?.get(userid); - if (!info) return this.errorReply(`${userid} has no pending request.`); + const request = room.pendingApprovals?.get(userid); + if (!request) return this.errorReply(`${userid} has no pending request.`); if (userid === user.id) { return this.errorReply(`You can't approve your own /show request.`); } @@ -2479,22 +2479,22 @@ export const commands: ChatCommands = { room.sendMods(`|uhtmlchange|request-${userid}|`); let buf; - if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)(\/|$)/i.test(info.link)) { + if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)(\/|$)/i.test(request.link)) { const YouTube = new YoutubeInterface(); - buf = await YouTube.generateVideoDisplay(info.link); + buf = await YouTube.generateVideoDisplay(request.link); if (!buf) return this.errorReply('Could not get YouTube video'); } else { try { - const [width, height, resized] = await Chat.fitImage(info.link); - buf = Utils.html``; - if (resized) buf += Utils.html`
full-size image`; + const [width, height, resized] = await Chat.fitImage(request.link); + buf = Utils.html``; + if (resized) buf += Utils.html`
full-size image`; } catch (err) { return this.errorReply('Invalid image'); } } - buf += Utils.html`

(Requested by ${info.name})`; - if (info.comment) { - buf += Utils.html`

${info.comment}

`; + buf += Utils.html`

(Requested by ${request.name})`; + if (request.comment) { + buf += Utils.html`

${request.comment}

`; } else { buf += `

`; } diff --git a/server/rooms.ts b/server/rooms.ts index 351fe7db3e..4fd23d53a7 100644 --- a/server/rooms.ts +++ b/server/rooms.ts @@ -1096,7 +1096,7 @@ export class BasicChatRoom extends BasicRoom { logUserStatsInterval: NodeJS.Timer | null; expireTimer: NodeJS.Timer | null; userList: string; - pendingApprovals: Map | null; + pendingApprovals: Map | null; constructor(roomid: RoomID, title?: string, options: Partial = {}) { super(roomid, title);