UNPKG

koishi-plugin-adapter-iirose

Version:

IIROSE-[蔷薇花园](https://iirose.com/)适配器

1,569 lines (1,530 loc) 78.6 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { IIROSE_Bot: () => IIROSE_Bot, IIROSE_WSsend: () => IIROSE_WSsend, WsClient: () => WsClient, default: () => src_default }); module.exports = __toCommonJS(src_exports); // src/bot.ts var import_koishi6 = require("koishi"); // src/ws.ts var import_koishi3 = require("koishi"); var import_pako = __toESM(require("pako")); // src/decoder/Damaku.ts var damaku = /* @__PURE__ */ __name((message) => { if (message.substr(0, 1) === "=") { const list = message.substr(1).split(">"); for (const item of list) { if (item.length === 6) { const msg = { username: item[0], avatar: item[5], message: item[1], color: item[2] }; return msg; } } return null; } }, "damaku"); // src/decoder/JoinRoom.ts var import_html_entities = require("html-entities"); var joinRoom = /* @__PURE__ */ __name((message) => { const tmp = message.split(">"); if (tmp.length === 12) { if (/\d+/.test(tmp[0])) { if (tmp[3] === "'1") { const msg = { timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities.decode)(tmp[2]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10] }; return msg; } } } }, "joinRoom"); // src/decoder/LeaveRoom.ts var import_html_entities2 = require("html-entities"); var leaveRoom = /* @__PURE__ */ __name((message) => { const tmp = message.split(">"); if (tmp.length === 12) { if (/\d+/.test(tmp[0])) { if (tmp[3] === "'3") { const msg = { timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities2.decode)(tmp[2]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10] }; return msg; } } } }, "leaveRoom"); // src/decoder/SwitchRoom.ts var switchRoom = /* @__PURE__ */ __name((message) => { const tmp = message.split(">"); if (tmp.length === 12) { if (/\d+/.test(tmp[0])) { if (tmp[3].substr(0, 2) === "'2") { const msg = { timestamp: Number(tmp[0]), avatar: tmp[1], username: tmp[2], color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10], targetRoom: tmp[3].substr(2) }; return msg; } } } }, "switchRoom"); // src/decoder/Music.ts var music = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === "&1") { const tmp = message.substr(2).split(">"); if (tmp.length >= 9 && tmp[8] === "") { const msg = { url: `http${tmp[0].split(" ")[0]}`, link: `http${tmp[0].split(" ")[1]}`, duration: Number(tmp[1]), title: tmp[2], singer: tmp[3].substr(2), owner: tmp[4], pic: `http${tmp[6]}` }; return msg; } } }, "music"); // src/decoder/PaymentCallback.ts var paymentCallback = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === "|$") { return { money: Number(message.substr(2)) }; } }, "paymentCallback"); // src/decoder/PrivateMessage.ts var import_html_entities3 = require("html-entities"); var _PrivateMessage = class _PrivateMessage { constructor(data) { this.timestamp = data.timestamp; this.uid = data.uid; this.username = data.username; this.avatar = data.avatar; this.message = data.message; this.color = data.color; this.messageId = data.messageId; } }; __name(_PrivateMessage, "PrivateMessage"); var PrivateMessage = _PrivateMessage; var privateMessage = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === '""') { const item = message.substr(2).split("<"); for (const msg of item) { const tmp = msg.split(">"); if (tmp.length === 11) { if (/^\d+$/.test(tmp[0])) { const msg2 = new PrivateMessage({ timestamp: Number(tmp[0]), uid: tmp[1], username: (0, import_html_entities3.decode)(tmp[2]), avatar: tmp[3], message: (0, import_html_entities3.decode)(tmp[4]), color: tmp[5], messageId: Number(tmp[10]) }); return msg2; } } } return null; } }, "privateMessage"); // src/decoder/PublicMessage.ts var import_html_entities4 = require("html-entities"); var _PublicMessage = class _PublicMessage { constructor(data) { this.timestamp = data.timestamp; this.avatar = data.avatar; this.username = data.username; this.message = data.message; this.color = data.color; this.uid = data.uid; this.title = data.title; this.messageId = data.messageId; this.replyMessage = data.replyMessage; } }; __name(_PublicMessage, "PublicMessage"); var PublicMessage = _PublicMessage; var replyMsg = /* @__PURE__ */ __name((msg) => { if (msg.includes(" (_hr) ")) { const replies = []; msg.split(" (hr_) ").forEach((e) => { if (e.includes(" (_hr) ")) { const tmp = e.split(" (_hr) "); const user = tmp[1].split("_"); replies.unshift({ message: (0, import_html_entities4.decode)(tmp[0]), username: (0, import_html_entities4.decode)(user[0]), time: Number(user[1]) }); replies.sort((a, b) => { return a.time - b.time; }); } else { replies.unshift(e); } }); return replies; } return null; }, "replyMsg"); var publicMessage = /* @__PURE__ */ __name((input) => { if (input.substring(0, 1) !== '"') return null; const message = input.substring(1); if (message.indexOf("<") === -1) { const tmp = message.split(">"); if (tmp.length === 11) { if (/^\d+$/.test(tmp[0])) { const reply = replyMsg(tmp[3]); const message2 = reply ? String(reply.shift()) : tmp[3]; if (message2.startsWith("m__4@")) { return null; } const msg = { timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities4.decode)(tmp[2]), message: (0, import_html_entities4.decode)(message2), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], messageId: Number(tmp[10]), replyMessage: reply }; return new PublicMessage(msg); } } } }, "publicMessage"); // src/decoder/MusicMessage.ts var import_html_entities5 = require("html-entities"); var replyMsg2 = /* @__PURE__ */ __name((msg) => { if (msg.includes(" (_hr) ")) { const replies = []; msg.split(" (hr_) ").forEach((e) => { if (e.includes(" (_hr) ")) { const tmp = e.split(" (_hr) "); const user = tmp[1].split("_"); replies.unshift({ message: (0, import_html_entities5.decode)(tmp[0]), username: (0, import_html_entities5.decode)(user[0]), time: Number(user[1]) }); replies.sort((a, b) => { return a.time - b.time; }); } else { replies.unshift(e); } }); return replies; } return null; }, "replyMsg"); var musicMessageAnalyze = /* @__PURE__ */ __name((input) => { const { timestamp, avatar, username, message, color, uid, title, messageId } = input; const musicData = message.replace(/ /g, "").split(">"); return { timestamp, avatar, username, color, uid, title, messageId, musicName: musicData[1], musicSinger: musicData[2], musicPic: musicData[3], musicColor: musicData[4] }; }, "musicMessageAnalyze"); var musicMessage = /* @__PURE__ */ __name((input) => { if (input.substring(0, 1) !== '"') return null; const message = input.substring(1); if (message.indexOf("<") === -1) { const tmp = message.split(">"); if (tmp.length === 11) { if (/^\d+$/.test(tmp[0])) { const reply = replyMsg2(tmp[3]); const message2 = reply ? String(reply.shift()) : tmp[3]; const msg = { timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities5.decode)(tmp[2]), message: (0, import_html_entities5.decode)(message2), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], messageId: Number(tmp[10]), replyMessage: reply }; if (message2.startsWith("m__4@")) { return musicMessageAnalyze(msg); } } } } }, "musicMessage"); // src/decoder/ManyMessage.ts var import_html_entities6 = require("html-entities"); var _ManyMessage = class _ManyMessage { constructor(data) { this.timestamp = data.timestamp; this.avatar = data.avatar; this.username = data.username; this.message = data.message; this.color = data.color; this.uid = data.uid; this.title = data.title; this.messageId = data.messageId; this.replyMessage = data.replyMessage; this.type = data.type; } }; __name(_ManyMessage, "ManyMessage"); var ManyMessage = _ManyMessage; var replyMsg3 = /* @__PURE__ */ __name((msg) => { if (msg.includes(" (_hr) ")) { const replies = []; msg.split(" (hr_) ").forEach((e) => { if (e.includes(" (_hr) ")) { const tmp = e.split(" (_hr) "); const user = tmp[1].split("_"); replies.unshift({ message: (0, import_html_entities6.decode)(tmp[0]), username: (0, import_html_entities6.decode)(user[0]), time: Number(user[1]) }); replies.sort((a, b) => { return a.time - b.time; }); } else { replies.unshift(e); } }); return replies; } return null; }, "replyMsg"); var manyMessage = /* @__PURE__ */ __name((input, bot) => { if (input.substring(0, 1) !== '"') return null; const message = input.substring(1); if (message.indexOf("<") !== -1) { const tmp1 = message.split("<"); const output = []; tmp1.forEach((e) => { const tmp = e.split(">"); tmp[0] = tmp[0].replace('"', ""); if (/^\d+$/.test(tmp[0])) { if (tmp.length === 11) { if (!isNaN(Number(tmp[8])) && Number(tmp[8]) > -1 && Number(tmp[8]) < 5) { if (bot.config.uid == tmp[1]) { return; } output.push(new ManyMessage({ type: "privateMessage", timestamp: Number(tmp[0]), avatar: tmp[3], username: (0, import_html_entities6.decode)(tmp[2]), message: (0, import_html_entities6.decode)(tmp[4]), color: tmp[5], uid: tmp[1], messageId: Number(tmp[10]) })); } else { if (bot.config.uid == tmp[8]) { return; } const reply = replyMsg3(tmp[3]); output.push(new ManyMessage({ type: "publicMessage", timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities6.decode)(tmp[2]), message: (0, import_html_entities6.decode)(reply ? String(reply.shift()) : tmp[3]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], messageId: Number(tmp[10]), replyMessage: reply })); } } else if (tmp.length === 12) { if (bot.config.uid == tmp[8]) { return; } if (tmp[3] === "'1") { const msg = { type: "joinRoom", timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities6.decode)(tmp[2]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10] }; output.push(new ManyMessage(msg)); } else if (tmp[3].substr(0, 2) === "'2") { const msg = { type: "switchRoom", timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities6.decode)(tmp[2]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10], targetRoom: tmp[3].substr(2) }; output.push(new ManyMessage(msg)); } else if (tmp[3] === "'3") { const msg = { type: "leaveRoom", timestamp: Number(tmp[0]), avatar: tmp[1], username: (0, import_html_entities6.decode)(tmp[2]), color: tmp[5], uid: tmp[8], title: tmp[9] === "'108" ? "花瓣" : tmp[9], room: tmp[10] }; output.push(new ManyMessage(msg)); } } } }); return output; } }, "manyMessage"); // src/decoder/Userlist.ts var userList = /* @__PURE__ */ __name((message) => { if (message.substr(0, 3) === '%*"') { const list = []; message.substr(3).split("<").forEach((e, i) => { const tmp = e.split(">"); if (tmp.length >= 8) { list.push({ avatar: tmp[0], username: tmp[2], color: tmp[3], room: tmp[4], uid: tmp[8] }); } }); return list; } }, "userList"); // src/decoder/GetUserListCallback.ts var getUserListCallback = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === "u2") { const list = []; message.substr(2).split("<").forEach((e) => { const tmp = e.split(">"); if (tmp.length >= 8) { list.push({ avatar: tmp[0], username: tmp[2], color: tmp[3], room: tmp[4], uid: tmp[8] }); } }); return list; } }, "getUserListCallback"); // src/decoder/UserProfileCallback.ts var userProfileCallback = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === "+1") { const tmp = message.substr(2).split(">"); const msg = { email: tmp[0], location: tmp[4], website: tmp[5], hobby: tmp[6], intro: tmp[8], background: tmp[9], music: tmp[11], lastLoginTime: new Date(Number(tmp[12]) * 1e3), visits: tmp[13], title: tmp[14], rooms: tmp[21].split('"'), tags: tmp[22], regTime: new Date(Number(tmp[24]) * 1e3), online: tmp[25], credit: tmp[32], life: tmp[31].split("<").map((e) => { const data = { image: `http${e.split(" ")[0]}`, time: new Date(Number(e.split(" ")[1]) * 1e3), desc: e.split(" ").splice(2).join(" ") }; return data; }), mate: { username: tmp[23] ? tmp[23].split("<")[0] : null, avatar: tmp[23] ? tmp[23].split("<")[1] : null, color: tmp[23] ? tmp[23].split("<")[2] : null }, money: { hold: tmp[17], bank: tmp[33] }, like: { times: Number(tmp[16].split('"')[0]), users: tmp[16].split('"')[1].split("'") } }; return msg; } }, "userProfileCallback"); // src/decoder/BankCallback.ts var bankCallback = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === ">$") { const tmp = message.substr(2).split('"'); const data = { total: Number(tmp[0]), income: Number(tmp[1]), deposit: Number(tmp[3].split(" ")[0]), interestRate: [Number(tmp[5].split(" ")[0]), Number(tmp[5].split(" ")[1])], balance: Number(tmp[4]) }; return data; } }, "bankCallback"); // src/decoder/MediaListCallback.ts var import_html_entities7 = require("html-entities"); var mediaListCallback = /* @__PURE__ */ __name((message) => { if (message.substr(0, 1) === "~") { const result = message.substr(1).split("<").map((e, i) => { const tmp = e.split(">"); return { id: `${i}_${tmp[0]}`, length: Number(tmp[0]), title: (0, import_html_entities7.decode)(tmp[1]), color: tmp[2].substr(0, 6), name: tmp[2].substr(6), type: Number(tmp[3]), avatar: tmp[4], cover: `http${tmp[5]}` }; }); return result; } }, "mediaListCallback"); // src/decoder/SelfMove.ts var selfMove = /* @__PURE__ */ __name((message) => { if (message.substr(0, 2) === "-*") { const msg = { id: message.substr(2) }; return msg; } }, "selfMove"); // src/decoder/MailboxMessage.ts var import_html_entities8 = require("html-entities"); var mailboxMessage = /* @__PURE__ */ __name((message) => { if (/^@/.test(message)) { let parser = false; message.slice(2).split("<").forEach((e) => { const tmp = e.split(">"); if (tmp.length === 3) { parser = true; return { notice: (0, import_html_entities8.decode)(tmp[0]), background: tmp[1], timestamp: Number(tmp[2]) }; } if (tmp.length === 7) { if (/^'\^/.test(tmp[3])) { parser = true; const data = { username: (0, import_html_entities8.decode)(tmp[0]), avatar: tmp[1], gender: tmp[2], background: tmp[4], timestamp: Number(tmp[5]), color: tmp[6] }; return data; } else if (/^'\*/.test(tmp[3])) { parser = true; const data = { username: (0, import_html_entities8.decode)(tmp[0]), avatar: tmp[1], gender: tmp[2], background: tmp[4], timestamp: Number(tmp[5]), color: tmp[6], message: (0, import_html_entities8.decode)(tmp[3].substr(3)) }; return data; } else if (/^'\$/.test(tmp[3])) { parser = true; const data = { username: (0, import_html_entities8.decode)(tmp[0]), avatar: tmp[1], gender: tmp[2], money: parseInt(tmp[3].split(" ")[0].substr(2)), message: (0, import_html_entities8.decode)(tmp[3].split(" ")[1] || ""), background: tmp[4], timestamp: Number(tmp[5]), color: tmp[6] }; return data; } } }); return parser; } }, "mailboxMessage"); // src/decoder/Stock.ts var stock = /* @__PURE__ */ __name((message, bot) => { if (message.substr(0, 1) === ">") { const list = message.substr(1).split(">")[0].split('"'); if (list.length === 5) { let uid = bot.ctx.config.uid; if (bot.config.smStart && bot.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; } const data = { userId: uid, totalStock: Number(list[0]), totalMoney: Number(Number(list[1]).toFixed(4)), unitPrice: Number(Number(list[2]).toFixed(4)), personalStock: Number(list[3]), personalMoney: Number(list[4]) }; bot.ctx.emit("iirose/stockBackCall", data); return data; } return null; } }, "stock"); // src/decoder/BeforeMoveRoomStart.ts var beforeMoveRoomStart = /* @__PURE__ */ __name((message) => { if (message.substr(0, 1) === "m") { const msg = { can: true }; return msg; } }, "beforeMoveRoomStart"); // src/decoder/index.ts var decoder = /* @__PURE__ */ __name((bot, msg) => { const len = {}; len.manyMessage = manyMessage(msg, bot); len.userlist = userList(msg); len.publicMessage = publicMessage(msg); len.leaveRoom = leaveRoom(msg); len.joinRoom = joinRoom(msg); len.privateMessage = privateMessage(msg); len.damaku = damaku(msg); len.switchRoom = switchRoom(msg); len.music = music(msg); len.paymentCallback = paymentCallback(msg); len.getUserListCallback = getUserListCallback(msg); len.userProfileCallback = userProfileCallback(msg); len.bankCallback = bankCallback(msg); len.mediaListCallback = mediaListCallback(msg); len.selfMove = selfMove(msg); len.mailboxMessage = mailboxMessage(msg); len.musicMessage = musicMessage(msg); len.stock = stock(msg, bot); len.beforeMoveRoomStart = beforeMoveRoomStart(msg); const newObj = {}; for (const key in len) { if ((len[key] === 0 || len[key] === false || len[key]) && len[key].toString().replace(/(^\s*)|(\s*$)/g, "") !== "") { if (key === "manyMessage") { newObj[key] = len[key]; } if (len[key].uid) { let uid = bot.ctx.config.uid; if (bot.config.smStart && bot.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; } if (len[key].uid !== uid) { newObj[key] = len[key]; } } else { newObj[key] = len[key]; } } } return newObj; }, "decoder"); // src/messageTemp.ts var messageObjList = {}; // src/decoderMessage.ts var import_koishi = require("koishi"); var decoderMessage = /* @__PURE__ */ __name((obj, bot) => { for (const key in obj) { switch (key) { case "userlist": { if (!obj.userlist) return; const data = obj.userlist; let uid = bot.ctx.config.uid; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; } const event = { selfId: uid, type: "userlist", platform: "iirose", timestamp: Date.now() }; const session = bot.session(event); bot.ctx.emit("iirose/before-getUserList", session, data); break; } case "publicMessage": { if (!obj.publicMessage) return; messageObjList[String(obj.publicMessage.messageId)] = { messageId: String(obj.publicMessage.messageId), isDirect: true, content: obj.publicMessage.message, timestamp: Number(obj.publicMessage.timestamp), author: { userId: obj.publicMessage.uid, avatar: obj.publicMessage.avatar, username: obj.publicMessage.username, nickname: obj.publicMessage.username } }; obj.publicMessage.message = clearMsg(obj.publicMessage.message); const data = obj.publicMessage; const session = bot.session({ type: "message", user: { id: data.uid, name: data.username, avatar: data.avatar.startsWith("http") ? data.avatar : `https://static.codemao.cn/rose/v0/images/icon/${data.avatar}` }, message: { messageId: String(data.messageId), content: data.message, elements: import_koishi.h.parse(data.message) }, timestamp: Number(data.timestamp) }); let uid = bot.ctx.config.uid; let guildId = bot.ctx.config.roomId; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; guildId = bot.ctx.config.smRoom; } session.platform = "iirose"; session.subtype = "group"; session.subsubtype = "group"; session.guildId = guildId; session.content = data.message; session.channelId = `public:${guildId}`; session.selfId = uid; session.isDirect = false; bot.dispatch(session); break; } case "leaveRoom": { const data = obj.leaveRoom; if (!data) return; let uid = bot.ctx.config.uid; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; } const event = { selfId: uid, type: "room-leave", platform: "iirose", timestamp: Date.now(), userId: data.uid, username: data.username, user: { id: data.uid, name: data.username }, message: { messageId: data.uid + "leaveRoom", content: "leaveRoom", elements: import_koishi.h.parse("leaveRoom") }, guildId: data.room }; const session = bot.session(event); session.guildId = bot.ctx.config.roomIdfa; bot.ctx.emit("iirose/leaveRoom", session, data); break; } case "joinRoom": { const data = obj.joinRoom; if (!data) return; let uid = bot.ctx.config.uid; let guildId = bot.ctx.config.roomId; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; guildId = bot.ctx.config.sm; } const event = { type: "room-join", userId: data.uid, username: data.username, timestamp: Number(data.timestamp), author: { userId: data.uid, avatar: data.avatar.startsWith("http") ? data.avatar : `https://static.codemao.cn/rose/v0/images/icon/${data.avatar}`, username: data.username }, platform: "iirose", guildId, selfId: uid, bot, data, user: { id: data.uid, name: data.username }, message: { messageId: data.uid + "joinRoom", content: "joinRoom", elements: import_koishi.h.parse("joinRoom") } }; const session = bot.session(event); session.guildId = guildId; bot.ctx.emit("iirose/joinRoom", session, data); break; } case "privateMessage": { if (!obj.privateMessage) return; messageObjList[String(obj.privateMessage.messageId)] = { messageId: String(obj.privateMessage.messageId), isDirect: true, content: obj.privateMessage.message, timestamp: Number(obj.privateMessage.timestamp), author: { userId: obj.privateMessage.uid, avatar: obj.privateMessage.avatar, username: obj.privateMessage.username, nickname: obj.privateMessage.username } }; obj.privateMessage.message = clearMsg(obj.privateMessage.message); const data = obj.privateMessage; const session = bot.session({ type: "message", user: { id: data.uid, name: data.username, avatar: data.avatar.startsWith("http") ? data.avatar : `https://static.codemao.cn/rose/v0/images/icon/${data.avatar}` }, message: { messageId: String(data.messageId), content: data.message, elements: import_koishi.h.parse(data.message) }, timestamp: Number(data.timestamp) }); session.platform = "iirose"; session.subtype = "private"; session.subsubtype = "private"; session.guildId = data.uid; session.content = data.message; session.channelId = `private:${data.uid}`; let uid = bot.ctx.config.uid; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; } session.selfId = uid; session.isDirect = true; bot.dispatch(session); break; } case "damaku": { const data = obj.damaku; if (!data) return; let uid = bot.ctx.config.uid; let guildId = bot.ctx.config.roomId; if (bot.ctx.config.smStart && bot.ctx.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { uid = bot.ctx.config.smUid; guildId = bot.ctx.config.smRoom; } const event = { type: "damaku", userId: data.username, username: data.username, timestamp: Date.now(), author: { userId: data.username, avatar: data.avatar.startsWith("http") ? data.avatar : `https://static.codemao.cn/rose/v0/images/icon/${data.avatar}`, username: data.username }, platform: "iirose", guildId, selfId: uid, user: { id: data.username, name: data.username }, message: { id: `${data.username}damaku`, content: data.message } }; const session = bot.session(event); bot.ctx.emit("iirose/newDamaku", session, data); break; } case "switchRoom": { const event = { type: "switchRoom", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/switchRoom", session, obj.switchRoom); break; } case "music": { const data = obj.music; const event = { type: "music", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/newMusic", session, data); break; } case "paymentCallback": { const data = obj.paymentCallback; const event = { type: "paymentCallback", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/before-payment", session, data); break; } case "getUserListCallback": { const data = obj.getUserListCallback; const event = { type: "getUserListCallback", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/before-getUserList", session, data); break; } case "userProfileCallback": { const data = obj.userProfileCallback; const event = { type: "userProfileCallback", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/before-userProfile", session, data); break; } case "bankCallback": { const data = obj.bankCallback; const event = { type: "bankCallback", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/before-bank", session, data); break; } case "mediaListCallback": { const data = obj.mediaListCallback; const event = { type: "mediaListCallback", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/before-mediaList", session, data); break; } case "selfMove": { const data = obj.selfMove; const event = { type: "selfMove", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/selfMove", session, data); break; } case "beforeMoveRoomStart": { const data = obj.beforeMoveRoomStart; bot.internal.moveRoomStart(); const event = { type: "moveRoomStart", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/BeforeMoveRoomStart", session, data); break; } case "mailboxMessage": { const data = obj.mailboxMessage; const event = { type: "mailboxMessage", platform: "iirose", guildId: bot.config.roomId }; const session = bot.session(event); bot.ctx.emit("iirose/mailboxMessage", session, data); break; } default: { break; } } } }, "decoderMessage"); function clearMsg(msg) { const result = [ [/\s*\[\*([\s\S]+)\*\]\s*/g, '<at name="', '"></at>', /\s\[\*/g, /\*\]\s/g], [/\s*\[@([\s\S]+)@\]\s*/g, '<at id="', '"></at>', /\s\[\@/g, /\@\]\s/g], [/https*:\/\/[\s\S]+?\.(png|jpg|jpeg|gif)(#e)*/g, '<img src="', '"></img>', /\[/g, /]/g] ]; let msg1 = msg; for (const reg of result) { const Reg = reg[0]; const matchArr = msg1.match(Reg); if (matchArr) { let findIndex = -1; const stringTemp = []; matchArr.forEach((v) => { if (reg.length > 3) { for (let i = 3; i < reg.length; i++) { msg1 = msg1.replace(reg[i], ""); v = v.replace(reg[i], ""); } } findIndex++; msg1 = msg1.replace(v, `^$${findIndex}$^`); stringTemp.push(v.trim()); }); stringTemp.forEach((v, index) => { msg1 = msg1.replace(`^$${index}$^`, reg[1] + v + reg[2]); }); } } return msg1; } __name(clearMsg, "clearMsg"); // src/encoder/admin/kick.ts var kick_default = /* @__PURE__ */ __name((username) => { return `!#["${username}"]`; }, "default"); // src/encoder/admin/media_cut.ts var media_cut_default = /* @__PURE__ */ __name((id) => { if (!id) return "!11"; return `!12["${id}"]`; }, "default"); // src/encoder/admin/media_clear.ts var media_clear_default = /* @__PURE__ */ __name(() => { return "!13"; }, "default"); // src/encoder/admin/setMaxUser.ts var setMaxUser_default = /* @__PURE__ */ __name((num) => { if (num) return `!h6["1${num}"]`; return '!h6["1"]'; }, "default"); // src/encoder/admin/whiteList.ts var whiteList_default = /* @__PURE__ */ __name((username, time, intro) => { return `!hw["4","${username}","${time}","${intro || "undefined"}"]`; }, "default"); // src/encoder/messages/damaku.ts var damaku_default = /* @__PURE__ */ __name((message, color) => { const data = { t: message, c: color }; return `~${JSON.stringify(data)}`; }, "default"); // src/encoder/messages/PublicMessage.ts var PublicMessage_default = /* @__PURE__ */ __name((message, color) => { if (message === "cut") { return `{0${JSON.stringify({ m: message, mc: color, i: Math.random().toString().substr(2, 12) })}`; } return JSON.stringify({ m: message, mc: color, i: Math.random().toString().substr(2, 12) }); }, "default"); // src/encoder/messages/media_card.ts var import_html_entities9 = require("html-entities"); var media_card_default = /* @__PURE__ */ __name((type, title, singer, cover, color, duration, BitRate = 320, origin) => { function parseBitrate(bitrate) { switch (bitrate) { case 1e4: return "1e4"; case 2e4: return "2e4"; case 3e4: return "3e4"; default: return bitrate; } } __name(parseBitrate, "parseBitrate"); function durationToText(duration2) { const secondsInMinute = 60; const secondsInHour = secondsInMinute * 60; const secondsInDay = secondsInHour * 24; const secondsInYear = secondsInDay * 365; const secondsInMillennium = secondsInYear * 1e3; const secondsInTenThousandYears = secondsInMillennium * 10; const secondsInHundredThousandYears = secondsInTenThousandYears * 10; const secondsInMillionYears = secondsInHundredThousandYears * 10; const secondsInTenMillionYears = secondsInMillionYears * 10; const secondsInHundredMillionYears = secondsInTenMillionYears * 10; const secondsInBillionYears = secondsInHundredMillionYears * 10; const billionYears = Math.floor(duration2 / secondsInBillionYears); duration2 %= secondsInBillionYears; const hundredMillionYears = Math.floor(duration2 / secondsInHundredMillionYears); duration2 %= secondsInHundredMillionYears; const tenMillionYears = Math.floor(duration2 / secondsInTenMillionYears); duration2 %= secondsInTenMillionYears; const millionYears = Math.floor(duration2 / secondsInMillionYears); duration2 %= secondsInMillionYears; const hundredThousandYears = Math.floor(duration2 / secondsInHundredThousandYears); duration2 %= secondsInHundredThousandYears; const tenThousandYears = Math.floor(duration2 / secondsInTenThousandYears); duration2 %= secondsInTenThousandYears; const millennia = Math.floor(duration2 / secondsInMillennium); duration2 %= secondsInMillennium; const years = Math.floor(duration2 / secondsInYear); duration2 %= secondsInYear; const days = Math.floor(duration2 / secondsInDay); duration2 %= secondsInDay; const hours = Math.floor(duration2 / secondsInHour); duration2 %= secondsInHour; const minutes = Math.floor(duration2 / secondsInMinute); const seconds = duration2 % secondsInMinute; let text = ""; if (billionYears > 0) { text += `${billionYears}亿年 `; } if (hundredMillionYears > 0) { text += `${hundredMillionYears}亿年 `; } if (tenMillionYears > 0) { text += `${tenMillionYears}千万年 `; } if (millionYears > 0) { text += `${millionYears}百万年 `; } if (hundredThousandYears > 0) { text += `${hundredThousandYears}十万年 `; } if (tenThousandYears > 0) { text += `${tenThousandYears}万年 `; } if (millennia > 0) { text += `${millennia}千年 `; } if (years > 0) { text += `${years}年 `; } if (days > 0) { text += `${days}天 `; } if (hours > 0) { text += `${hours}小时 `; } if (minutes > 0) { text += `${minutes}分钟 `; } if (seconds > 0) { text += `${seconds}秒`; } return text.trim(); } __name(durationToText, "durationToText"); const typeMap = { music: "=0", video: "=1", netease: "@0", xiamimusic: "@1", qqmusic: "@2", qianqianmusic: "@3", kugoumusic: "@4", ximalayafm: "@5", lizhifm: "@6", echohuisheng: "@7", fivesing: "@8", iqiyi: "*0", tencentvideo: "*1", youtube: "*2", bilibili: "*3", mangotv: "*4", tiktok: "*5", kuaishou: "*6", onesixthreemv: "*7", bilibililive: "*8" }; let data; let t; if (origin && origin !== "null" && origin !== "undefined") { t = origin; } else { t = type; } title = (0, import_html_entities9.encode)(title); singer = (0, import_html_entities9.encode)(singer); color = (0, import_html_entities9.encode)(color); if (type === "music") { if (!BitRate) { data = `m__4${typeMap[t]}>${title}>${singer}>${cover}>${color}>>11451${durationToText(duration)}`; } else { data = `m__4${typeMap[t]}>${title}>${singer}>${cover}>${color}>${parseBitrate(BitRate)}`; } } else { if (!BitRate) { data = `m__4${typeMap[t]}>${title}>${singer}>${cover}>${color}>>11451${durationToText(duration)}`; } else { data = `m__4${typeMap[t]}>${title}>${singer}>${cover}>${color}>>${parseBitrate(BitRate)}>>${durationToText(duration)}`; } } return PublicMessage_default(data, color); }, "default"); // src/encoder/messages/media_data.ts var media_data_default = /* @__PURE__ */ __name((type, title, signer, cover, link, url, duration, lyrics = null, origin) => { const typeMap = { music: "=0", video: "=1", netease: "@0", xiamimusic: "@1", qqmusic: "@2", qianqianmusic: "@3", kugoumusic: "@4", ximalayafm: "@5", lizhifm: "@6", echohuisheng: "@7", fivesing: "@8", iqiyi: "!0", tencentvideo: "!1", youtube: "!2", bilibili: "!3", mangotv: "!4", tiktok: "!5", kuaishou: "!6", onesixthreemv: "!7", bilibililive: "!8" }; let t; if (origin && origin !== "null" && origin !== "undefined") { t = origin; } else { t = type; } const data = JSON.stringify({ s: url.substr(4), d: duration, c: cover.substr(4), n: title, r: signer, b: `${typeMap[t]}`, o: link.substr(4), l: lyrics }); return `&1${data}`; }, "default"); // src/encoder/user/StockBuy.ts var StockBuy_default = /* @__PURE__ */ __name((quantity) => { return `>$${quantity}`; }, "default"); // src/encoder/user/StockSell.ts var StockSell_default = /* @__PURE__ */ __name((quantity) => { return `>@${quantity}`; }, "default"); // src/encoder/user/StockGet.ts var StockGet_default = /* @__PURE__ */ __name(() => { return `>#`; }, "default"); // src/utils.ts var import_koishi2 = require("koishi"); var logger = new import_koishi2.Logger("IIROSE-BOT"); var startEventsServer = /* @__PURE__ */ __name((bot) => { let event = []; event.push(bot.ctx.on("iirose/moveRoom", async (moveData) => { const roomId = moveData.roomId; if (!roomId) { if (bot.config.roomId === roomId) { return logger.debug(" [IIROSE-BOT] 移动房间失败,当前所在房间已为目标房间 "); } bot.config.roomId = bot.config.roomId; return logger.debug(` [IIROSE-BOT] 移动房间失败,目标房间为: ${roomId},已经自动移动到默认房间`); } if (bot.config.roomId === roomId) { return logger.debug(" [IIROSE-BOT] 移动房间失败,当前所在房间已为目标房间 "); } bot.config.oldRoomId = bot.config.roomId; bot.config.roomId = roomId; bot.config.roomPassword = moveData.roomPassword; await bot.adapter.disconnect(bot); await bot.adapter.connect(bot); })); event.push(bot.ctx.on("iirose/kick", (kickData) => { IIROSE_WSsend(bot, kick_default(kickData.username)); })); event.push(bot.ctx.on("iirose/cut-one", (cutOne) => { cutOne.hasOwnProperty("id") ? IIROSE_WSsend(bot, media_cut_default(cutOne.id)) : IIROSE_WSsend(bot, media_cut_default()); })); event.push(bot.ctx.on("iirose/cut-all", () => { IIROSE_WSsend(bot, media_clear_default()); })); event.push(bot.ctx.on("iirose/setMaxUser", (setMaxUser) => { setMaxUser.hasOwnProperty("number") ? IIROSE_WSsend(bot, setMaxUser_default(setMaxUser.maxMember)) : IIROSE_WSsend(bot, setMaxUser_default()); })); event.push(bot.ctx.on("iirose/whiteList", (whiteList) => { whiteList.hasOwnProperty("intro") ? IIROSE_WSsend(bot, whiteList_default(whiteList.username, whiteList.time, whiteList.intro)) : IIROSE_WSsend(bot, whiteList_default(whiteList.username, whiteList.time)); })); event.push(bot.ctx.on("iirose/damaku", (damaku2) => { IIROSE_WSsend(bot, damaku_default(damaku2.message, damaku2.color)); })); event.push(bot.ctx.on("iirose/makeMusic", (musicOrigin) => { const { type, name, signer, cover, link, url, duration, bitRate, color, lyrics, origin } = musicOrigin; IIROSE_WSsend(bot, media_card_default(type, name, signer, cover, color, duration, bitRate, origin)); IIROSE_WSsend(bot, media_data_default(type, name, signer, cover, link, url, duration, lyrics, origin)); })); event.push(bot.ctx.on("iirose/stockBuy", (numberData) => { IIROSE_WSsend(bot, StockBuy_default(numberData)); })); event.push(bot.ctx.on("iirose/stockSell", (numberData) => { IIROSE_WSsend(bot, StockSell_default(numberData)); })); event.push(bot.ctx.on("iirose/stockGet", (callBack) => { IIROSE_WSsend(bot, StockGet_default()); bot.ctx.once("iirose/stockBackCall", (stockData) => { const outData = stockData; outData.bot = bot; outData.send = (data) => { if (data.hasOwnProperty("public")) { bot.sendMessage("public:", data.public.message); } if (data.hasOwnProperty("private")) { bot.sendMessage(`private:${data.private.userId}`, data.private.message); } }; return callBack(outData); }); })); return event; }, "startEventsServer"); var stopEventsServer = /* @__PURE__ */ __name((event) => { event.forEach((element) => { element(); }); }, "stopEventsServer"); // src/ws.ts var import_md5 = __toESM(require("md5")); process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; var logger2 = new import_koishi3.Logger("IIROSE-BOT"); var _WsClient = class _WsClient extends import_koishi3.Adapter.WsClient { constructor(ctx, bot) { super(ctx, bot); // WSurl: string = 'wss://m2.iirose.com:8778'; this.event = []; // public inject = ['database']; this.live = null; this.setTimeoutId = null; this.firstLogin = false; } /** * 准备ws通信 * @returns */ async prepare() { logger2.info("websocket client preparing"); const iiroseList = ["m1", "m2", "m8", "m9", "m"]; let faseter = ""; let maximumSpeed = 1e5; let allErrors; let dispose = false; this.ctx.on("dispose", () => { dispose = true; }); do { allErrors = true; for (let webIndex of iiroseList) { const speed = await this.getLatency(`wss://${webIndex}.iirose.com:8778`); if (speed != "error") { allErrors = false; if (maximumSpeed > speed) { faseter = webIndex; maximumSpeed = speed; } } } if (allErrors) { logger2.warn("所有服务器都无法连接,将在5秒后重试..."); await new Promise((r) => setTimeout(r, 5e3)); } if (dispose) { return; } } while (allErrors); const socket = await this.bot.ctx.http.ws(`wss://${faseter}.iirose.com:8778`); logger2.success(`websocket client prepared, connecting to wss://${faseter}.iirose.com:8778`); this.bot.socket = socket; const roomIdReg = /\s*\[_([\s\S]+)_\]\s*/; const userNameReg = /\s*\[\*([\s\S]+)\*\]\s*/; const roomIdConfig = this.bot.config.roomId; const userNameConfig = this.bot.config.usename; let username = userNameReg.test(userNameConfig) ? userNameConfig.match(userNameReg)?.[1] : userNameConfig; let room = roomIdReg.test(roomIdConfig) ? roomIdConfig.match(roomIdReg)?.[1] : roomIdConfig; if (this.bot.config.smStart && this.bot.config.smPassword === "ec3a4ac482b483ac02d26e440aa0a948d309c822") { this.loginObj = { r: this.bot.config.smRoom, n: this.bot.config.smUsername, i: this.bot.config.smImage, nc: this.bot.config.smColor, s: this.bot.config.smGender, st: this.bot.config.smst, mo: this.bot.config.smmo, uid: this.bot.config.smUid, li: this.bot.config.smli, mb: this.bot.config.smmb, mu: this.bot.config.smmu, la: this.bot.config.smLocation, vc: this.bot.config.smvc, fp: `@${(0, import_md5.default)(this.bot.config.smUsername)}` }; logger2.info("已启用蔷薇游客模式"); } else { this.loginObj = { r: room || this.bot.config.roomId, n: username || this.bot.config.usename, p: this.bot.config.password, st: "n", mo: this.bot.config.Signature, mb: "", mu: "01", lr: this.bot.config.oldRoomId, rp: this.bot.config.roomPassword, fp: `@${(0, import_md5.default)(username || this.bot.config.usename)}` }; } this.loginObj.lr ? "" : delete this.loginObj.lr; socket.addEventListener("open", () => { logger2.success("websocket client opening"); const loginPack = "*" + JSON.stringify(this.loginObj); IIROSE_WSsend(this.bot, loginPack); this.event = startEventsServer(this.bot); this.bot.online(); this.live = setInterval(() => { if (this.bot.status == import_koishi3.Universal.Status.ONLINE) { IIROSE_WSsend(this.bot, ""); } }, 30 * 1e3); }); return socket; } /** * 接受ws通信 */ accept() { this.firstLogin = false; if (!this.bot.socket) { this.ctx.logger("iirose").error("WebSocket connection is not established."); return; } this.bot.socket.addEventListener("message", async (event) => { if (this.setTimeoutId) { clearTimeout(this.setTimeoutId); this.setTimeoutId = null; } const array = new Uint8Array(event.data); let message; if (array[0] === 1) { message = import_pako.default.inflate(array.slice(1), { to: "string" }); } else { message = Buffer.from(array).toString("utf8"); } if (!this.firstLogin) { this.firstLogin = true; if (message.startsWith(`%*"0`)) { logger2.error(`名字被占用,用户名:${this.loginObj.n}`); } else if (message.startsWith(`%*"1`)) { logger2.error("用户名不存在"); } else if (message.startsWith(`%*"2`)) { logger2.error(`密码错误,用户名:${this.loginObj.n}`); }