{ "version": 3, "sources": ["../../../../server/chat-plugins/quotes.ts"], "sourcesContent": ["import {FS, Utils} from '../../lib';\r\n\r\nconst STORAGE_PATH = 'config/chat-plugins/quotes.json';\r\nconst MAX_QUOTES = 300;\r\n\r\ninterface Quote {\r\n\tuserid: string;\r\n\tquote: string;\r\n\tdate: number;\r\n}\r\n\r\nconst quotes: {[room: string]: Quote[]} = JSON.parse(FS(STORAGE_PATH).readIfExistsSync() || \"{}\");\r\n\r\n// migrate quotes out of roomsettings\r\nfunction convertOldQuotes() {\r\n\tfor (const room of Rooms.rooms.values()) {\r\n\t\t// @ts-ignore\r\n\t\tif (room.settings.quotes) {\r\n\t\t\t// @ts-ignore\r\n\t\t\tquotes[room.roomid] = room.settings.quotes;\r\n\t\t\t// @ts-ignore\r\n\t\t\tdelete room.settings.quotes;\r\n\t\t\troom.saveSettings();\r\n\t\t\tsaveQuotes();\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction saveQuotes() {\r\n\tFS(STORAGE_PATH).writeUpdate(() => JSON.stringify(quotes));\r\n}\r\n\r\nconvertOldQuotes();\r\n\r\nexport const commands: Chat.ChatCommands = {\r\n\trandquote(target, room, user) {\r\n\t\troom = this.requireRoom();\r\n\t\tconst roomQuotes = quotes[room.roomid];\r\n\t\tif (!roomQuotes?.length) return this.errorReply(`This room has no quotes.`);\r\n\t\tthis.runBroadcast(true);\r\n\t\tconst {quote, date, userid} = roomQuotes[Math.floor(Math.random() * roomQuotes.length)];\r\n\t\tconst time = Chat.toTimestamp(new Date(date), {human: true});\r\n\t\tconst attribution = toID(target) === 'showauthor' ? `