From 2168ead6e1595745148122d65fa5ccca0d78d5b2 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sat, 12 Oct 2024 09:39:57 -0400 Subject: [PATCH] Talkomatic stuff --- build/index.js | 245 ++++++++++++++++++-- bun.lockb | Bin 78352 -> 78729 bytes config/talkomatic_bots.yml | 2 +- package.json | 1 + scripts/talko.ts | 17 ++ src/api/api/trpc.ts | 14 +- src/api/commands/groups/fishing/location.ts | 38 +-- src/api/commands/groups/fishing/pick.ts | 52 ++++- src/api/commands/groups/general/myid.ts | 2 +- src/api/commands/groups/index.ts | 3 +- src/api/commands/groups/inventory/eat.ts | 3 +- src/api/commands/groups/inventory/sack.ts | 49 ++-- src/api/commands/prefixes.ts | 2 +- src/talkomatic/bot/TalkomaticBot.ts | 194 ++++++++++++---- src/talkomatic/bot/index.ts | 2 +- 15 files changed, 524 insertions(+), 100 deletions(-) create mode 100644 scripts/talko.ts diff --git a/build/index.js b/build/index.js index 542085e..5740544 100644 --- a/build/index.js +++ b/build/index.js @@ -12284,6 +12284,113 @@ var require_main = __commonJS({ } }); +// node_modules/markdown-to-unicode/src/partials/bold.js +var require_bold = __commonJS({ + "node_modules/markdown-to-unicode/src/partials/bold.js"(exports2, module2) { + "use strict"; + function convertBoldToUnicode(markdownLine) { + let unicodeLine = markdownLine; + let boldRegex = /(\*\*|__)(.*?)\1/g; + unicodeLine = unicodeLine.replace(boldRegex, (match, p1, p2) => { + let unicodeCharacters = p2.split("").map((character) => { + return convertCharToBoldUnicode(character); + }); + return unicodeCharacters.join(""); + }); + return unicodeLine; + } + function convertCharToBoldUnicode(char) { + const codePoint = char.codePointAt(0); + if (codePoint >= 65 && codePoint <= 90) { + return String.fromCodePoint(codePoint - 65 + 119808); + } else if (codePoint >= 97 && codePoint <= 122) { + return String.fromCodePoint(codePoint - 97 + 119834); + } else if (codePoint >= 48 && codePoint <= 57) { + return String.fromCodePoint(codePoint - 48 + 120782); + } else { + return char; + } + } + module2.exports = convertBoldToUnicode; + } +}); + +// node_modules/markdown-to-unicode/src/partials/italic.js +var require_italic = __commonJS({ + "node_modules/markdown-to-unicode/src/partials/italic.js"(exports2, module2) { + "use strict"; + function convertItalicToUnicode(markdownLine) { + let unicodeLine = markdownLine; + let italicRegex = /(\*|_)(.*?)\1/g; + unicodeLine = unicodeLine.replace(italicRegex, (match, p1, p2) => { + let unicodeCharacters = p2.split("").map((character) => { + return convertCharToItalicUnicode(character); + }); + return unicodeCharacters.join(""); + }); + return unicodeLine; + } + function convertCharToItalicUnicode(char) { + const codePoint = char.codePointAt(0); + if (codePoint >= 65 && codePoint <= 90) { + return String.fromCodePoint(codePoint - 65 + 119860); + } else if (codePoint >= 97 && codePoint <= 122) { + return String.fromCodePoint(codePoint - 97 + 119886); + } else { + return char; + } + } + module2.exports = convertItalicToUnicode; + } +}); + +// node_modules/markdown-to-unicode/src/partials/strikethrough.js +var require_strikethrough = __commonJS({ + "node_modules/markdown-to-unicode/src/partials/strikethrough.js"(exports2, module2) { + "use strict"; + function convertStrikethroughToUnicode(markdownLine) { + let unicodeLine = markdownLine; + let strikethroughRegex = /~~(.*?)~~/g; + unicodeLine = unicodeLine.replace(strikethroughRegex, (match, p1) => { + let unicodeCharacters = p1.split("").map((character) => { + return convertCharToStrikethroughUnicode(character); + }); + return unicodeCharacters.join(""); + }); + return unicodeLine; + } + function convertCharToStrikethroughUnicode(char) { + const strikeThroughChar = "\u0336"; + return char + strikeThroughChar; + } + module2.exports = convertStrikethroughToUnicode; + } +}); + +// node_modules/markdown-to-unicode/src/index.js +var require_src2 = __commonJS({ + "node_modules/markdown-to-unicode/src/index.js"(exports2, module2) { + "use strict"; + var convertBoldToUnicode = require_bold(); + var convertItalicToUnicode = require_italic(); + var convertStrikethroughToUnicode = require_strikethrough(); + function convertMarkdownToUnicode2(markdownText) { + let getLineByLine = markdownText.split("\n"); + let unicodeLineByLine = getLineByLine.map((line) => convertMarkdownLineToUnicode(line)); + let unicodeText = unicodeLineByLine.join("\n"); + return unicodeText; + } + function convertMarkdownLineToUnicode(markdownLine) { + let unicodeLine = markdownLine; + unicodeLine = convertBoldToUnicode(unicodeLine); + unicodeLine = convertItalicToUnicode(unicodeLine); + unicodeLine = convertStrikethroughToUnicode(unicodeLine); + return unicodeLine; + } + module2.exports = convertMarkdownToUnicode2; + } +}); + // src/util/autorestart.ts function startAutorestart() { setTimeout(() => { @@ -17318,12 +17425,13 @@ var trpc_default = gettRPC; // src/talkomatic/bot/TalkomaticBot.ts require_main().config(); +var convertMarkdownToUnicode = require_src2(); var ppl = {}; var TalkomaticBot = class extends import_node_events.EventEmitter { constructor(config) { super(); this.config = config; - this.logger = new Logger("Talkomatic - " + config.channel.id); + this.logger = new Logger("Talkomatic - " + config.channel.name); this.client = lookup("https://talkomatic.co/", { extraHeaders: { Cookie: "connect.sid=" + process.env.TALKOMATIC_SID @@ -17336,13 +17444,23 @@ var TalkomaticBot = class extends import_node_events.EventEmitter { logger; trpc = trpc_default(process.env.TALKOMATIC_FISHING_TOKEN); started = false; - textColor = "#abe3d6"; - start() { - this.logger.debug("Starting"); + defaultColor = "#abe3d6"; + channelId = ""; + async start() { + this.logger.info("Starting"); this.client.connect(); this.bindEventListeners(); - this.setChannel(this.config.channel.id); - this.started = true; + let data = await this.findChannel(this.config.channel.name) || await this.createChannel(this.config.channel.name); + this.logger.debug(data); + if (typeof data !== "undefined") { + try { + this.channelId = data.room.room_id; + this.setChannel(this.channelId); + this.started = true; + } catch (err) { + this.logger.error(err); + } + } } stop() { this.client.disconnect(); @@ -17429,16 +17547,20 @@ var TalkomaticBot = class extends import_node_events.EventEmitter { let part = ppl[msg.userId] || { name: "", id: msg.userId, - color: msg.color, + color: this.defaultColor, typingFlag: false }; this.logger.info(`${part.name}: ${msg.text}`); const command = await this.trpc.command.query({ - channel: this.config.channel.id, + channel: this.channelId, args: args.slice(1, args.length), command: args[0].substring(usedPrefix.length), prefix: usedPrefix, - user: part + user: { + id: part.id, + name: part.name, + color: part.color + } }); if (!command) return; if (command.response) @@ -17449,9 +17571,9 @@ var TalkomaticBot = class extends import_node_events.EventEmitter { "userJoined", (msg) => { const p = ppl[msg.id] || { - name: "", + name: msg.username, id: msg.id, - color: "#ffffff", + color: "#abe3d6", typingFlag: false }; ppl[msg.id] = p; @@ -17478,24 +17600,107 @@ var TalkomaticBot = class extends import_node_events.EventEmitter { } catch (err) { } }); - this.b.on("sendchat", (msg) => { - if (typeof msg.channel === "string") { - if (msg.channel !== this.config.channel) return; + this.b.on( + "sendchat", + (msg) => { + if (typeof msg.channel === "string") { + if (msg.channel !== this.channelId) return; + } + this.sendChat(msg.message); } - this.sendChat(msg.message); - }); + ); } + oldText = ""; sendChat(text, reply, id) { + if (this.oldText.split("\n").reverse()[0].toLowerCase().includes("autofish")) + text = [this.oldText, text].join("\n").split("\n").slice(-5).join("\n"); const msg = { - roomId: this.config.channel.id, - text, - color: id ? ppl[id].color : "#ffffff" + roomId: this.channelId, + // text: text.split("sack").join("ʂасκ"), + text: text.split("sack").join("caught"), + color: id ? ppl[id].color : this.defaultColor }; + for (const uuid of Object.keys(ppl)) { + const p = ppl[uuid]; + msg.text = msg.text.split(`@${uuid}`).join(p.name); + if (!p) continue; + if (uuid !== id) continue; + msg.color = p.color; + } + try { + msg.text = convertMarkdownToUnicode(msg.text); + } catch (err) { + this.logger.warn("Unable to parse markdown:", err); + } this.client.emit("typing", msg); + this.oldText = text; } setChannel(roomId) { this.client.emit("joinRoom", { roomId }); } + async createChannel(roomName, roomType = "public") { + const response = await fetch( + "https://talkomatic.co/create-and-join-room", + { + method: "POST", + headers: { + "Content-Type": "application/json", + Cookie: "connect.sid=" + process.env.TALKOMATIC_SID + }, + credentials: "include", + body: JSON.stringify({ + roomName, + roomType + }) + } + ); + if (!response.ok) + return void this.logger.warn( + "Unable to create channel:", + new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ) + ); + try { + const data = new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ); + return JSON.parse(data.toString()); + } catch (err) { + this.logger.warn( + "Unable to decode channel creation response data:", + err + ); + } + } + async findChannel(name) { + const response = await fetch("https://talkomatic.co/rooms", { + method: "GET" + }); + if (!response.ok) + return void this.logger.warn( + "Unable to create channel:", + new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ) + ); + try { + const data = new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ); + const rooms = JSON.parse(data.toString()); + for (const room of rooms.rooms) { + if (room.room_name == name) { + return { room }; + } + } + } catch (err) { + this.logger.warn( + "Unable to decode channel creation response data:", + err + ); + } + } }; // src/talkomatic/bot/index.ts @@ -17503,7 +17708,7 @@ var bots = []; var defaults = loadConfig("config/talkomatic_bots.yml", [ { channel: { - id: "116955" + name: "test/fishing" } } ]); diff --git a/bun.lockb b/bun.lockb index cdf1a21f830cea8b7b75ac37181f09e262098bbf..7a2b872c282a70512bc5cccb28a6d1725914285b 100755 GIT binary patch delta 13146 zcmeHNdt6mj_CNc|RgMaRAaJ-Uz7-6Rmsdi$zSEAHT6)C?h&<#f4+TZg6iideaeOQ* zt;koFXqrazQ*+EvdpKoU&6wsR%qRGMWa*gm`>yj4YHFsL`Th0#%>M8_Yk&7%`?1zu z=j?k9d&yb1k_&E2!h$FFd-7)e32Q4J2@WdTx7+cYB32$-yL0W>+tXgzcxm@Uzq^q_ z;&f=KGsxm|aA`q{qSrvZB&oPBWJAd11`o36<+sqHDaupR#!VfMx~x20kQy2F&(x8m z#;BiWl;?tTf0J@ud0EMll%AKCpO!r(Z>t;Hp!^l9B>6)+A$=vOsJJsS9w_Lg7ZlG! z=bqqZhup6Zcxuj+wCsFIa)H+ezw9naO(0i8dP9C?@codizs->2pp1cvXM^(uGILUs z^D-nUSK~!e@szyKELTBV?v%Vt*En>(1Ql#SiqT*W+!6$y4aozV1C0geiB8Q6ogk?2xrR3(+LoF9%rB2Pw#9%+t8cR^oAgHlD_b?_q z{1PM&yBy2McF!|pNPynjm7S56>za~R2|eyDCDRp}F(oUrFgc4ml^O)<<~)>9d7Vc#vXZl1)6-sTrcZcM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@RHsWR7gyrKqk}5`FxW9A{iRri3f4o|?O4c3rt~F}dpO zg17yH`uti~Qcl(za&zM%vu|V9gImPHy>;aqW2wiDnC90Lw4bn^xiWU&>?W7PwZE@o z9Qa(d()=4St^fF~>vuz2()l;&+>IXo_(s5;>-4-yxkZiAM;8Ys7nG9o=TN-Il7DtL m%kQdf!Wo_8_KKp0cX#NGi=yehpO { @@ -106,7 +111,12 @@ export const appRouter = router({ const backs = getBacks<{}>(id); flushBacks(id); - return backs; + try { + return backs; + } catch (err) { + logger.error(err); + return undefined; + } }) }); diff --git a/src/api/commands/groups/fishing/location.ts b/src/api/commands/groups/fishing/location.ts index 7bd00e6..155420d 100644 --- a/src/api/commands/groups/fishing/location.ts +++ b/src/api/commands/groups/fishing/location.ts @@ -2,19 +2,6 @@ import Command from "@server/commands/Command"; import { getInventory } from "@server/data/inventory"; import { locations } from "@server/fish/locations"; -const answers = [ - "You are at {loc}.", - "You appear to be at {loc}.", - "According to your map, you are at {loc}.", - "The map says you are at {loc}.", - "Looking at your world atlas, you appear to be at {loc}.", - "The world atlas defines your location as {loc}.", - "Judging by the wind direction, hemisphere sun angle, and the size of the waves in the water, you deduce that you must be at {loc}.", - "You run your fingers down the map until you find {loc}. This is where you must be.", - "Your cell phone's maps app shows your location as {loc}.", - "You pull your cell phone out of your pocket and turn it on. Opening the maps app, you realize you are at {loc}." -]; - export const location = new Command( "location", ["location", "loc", "where", "whereami", "l"], @@ -32,3 +19,28 @@ export const location = new Command( return answer.replaceAll("{loc}", loc.name); } ); + +const answers = [ + "You are at {loc}.", + "You appear to be at {loc}.", + "According to your map, you are at {loc}.", + "The map says you are at {loc}.", + "Looking at your world atlas, you appear to be at {loc}.", + "The world atlas defines your location as {loc}.", + "Judging by the wind direction, hemisphere sun angle, and the size of the waves in the water, you deduce that you must be at {loc}.", + "You run your fingers down the map until you find {loc}. This is where you must be.", + "Your cell phone's maps app shows your location as {loc}.", + "You pull your cell phone out of your pocket and turn it on. Opening the maps app, you realize you are at {loc}.", + "You currently happen to be somewhere near {loc}.", + "You look all over the piece of paper you're holding. It's actually a map, and it says you must be near {loc}.", + "Having run your fingers all over the paper, you finally come to the conclusion you must be somewhere in the vicinity of {loc}", + "Your eyes travel your map as you realize you have to be somewhere near {loc}.", + "Having found the rock that you see on your map, you are likely to be near {loc}.", + "You are likely to be near {loc}.", + "Near {loc}, you feel the wind blow on your face.", + "The wind here is strong, so you must be near {loc}.", + "Nowadays, we consider this location to be {loc}.", + "The ancient tribe long ago has given this place the name of {loc}.", + "Over the many years, people have travelled these lands and decided to name this area {loc}", + "You pull your cell phone out of your pocket and open the Maps app. The screen loads for a while, until showing you the name {loc}" +]; diff --git a/src/api/commands/groups/fishing/pick.ts b/src/api/commands/groups/fishing/pick.ts index d925920..e76db7f 100644 --- a/src/api/commands/groups/fishing/pick.ts +++ b/src/api/commands/groups/fishing/pick.ts @@ -14,7 +14,11 @@ export const pick = new Command( if (!inventory) return; if (!(await hasFruit())) - return crazy[Math.floor(Math.random() * crazy.length)]; + return crazy[Math.floor(Math.random() * crazy.length)] + .split("$PART_NAME") + .join(part.name) + .split("$PREFIX") + .join(prefix); const fruit = await genFruitAndRemove(); addItem(inventory.items as unknown as IObject[], fruit); @@ -314,5 +318,49 @@ const crazy = [ "You thought you spied a fruit, but were unable to procure any.", "You climb all over that tree and don't find a single pickable", "You wouldn't steal a fruit from a tree with no fruit.", - "Are you sure there aren't any fruit just lying around on the ground that you can /take?" + "Are you sure there aren't any fruit just lying around on the ground that you can /take?", + "Would you please stop begging for fruit? It's time for you to learn how to wait (and then maybe you will earn a watch)", + "Are you still trying to get the fruit?", + "Last time I checked, the fruit on the tree were not there.", + "When the fruit are gone, you can't have fun. Wait, that doesn't rhyme.", + "I'm Thomas Jefferson. Please wait for the fruit.", + "If I told you I was famous, would you listen to me? The fruit will not grow on command.", + "You kids can't imagine the inevitable collapse of capitalism? Incredible! The fruit are almost ready.", + "You picked up a ruler! Now you can figure out the length of things! You went to measure the fruit on the tree. Oh, wait, there's no fruit. Well, the ruler is useless, so you threw it away.", + "Fishing is a better idea right now, please keep your focus off of the fruit-less tree.", + "You want fruit from the bare tree? After all, it could only cost your life, and you got that for free!", + "This is the Earth's belly button! I don't see any fruit!", + "Go play EarhtBound, and then maybe when you have finished the game, there will be fruit.", + "Haven't you tried doing anything else? Are you still looking for the stupid fruit?", + "What is your favorite food? Go eat that, instead of the nonexistent kekklefruit.", + "Every day, the tree gets older, which means it's closer to the end of its life. Lately, there hasn't been much fruit, because people like you come and rub your sticky hands all over it.", + "Go wash your hands, you're filthy. The fruit hates dirt, and refuses to grow around people like you.", + "Patience is the key.", + "Impatience is the key.", + "For every time you decide to play the waiting game, your chances of getting fruit grows higher. So stop constantly begging for fruit, and maybe it will grow in great amounts.", + "Have you tried spending time outside? I heard there's this great place at the North Pole where they make other things to eat.", + "I have sort of neglected doing my housework... I know it's a bit of a pig sty, but anyway... I'm not growing any fruit for you.", + "You've travelled very far from home... and still, you have yet to see any fruit on the tree.", + "Maybe the tree was an illusion this whole time.", + "You are no longer alone in your adventure, some baby kekklefruit sprouts have appeared on the tree.", + "Only time can tell when you'll learn from your mistakes.", + "Everyone collectively has to stop trying to pick, and then the fruit will grow.", + "This tree hasn't grown fruit in 11 years.", + "Well, the tree has no fruit. I wish you luck...", + "Sometimes, we all want to eat to fish better, but I think you'll do fine without the fruit for now.", + "I wouldn't give you fruit even if you paid with a Diamond.", + "Go buy a hamburger instead.", + "Monkey: Meow Meow fss fss fssss? (What a strange chattering for a monkey.) Coo coo pepepe. (I think he's talking about the tree.) Croak croak breeeeeep? (Do you know how to wait for the fruit to grow?)", + "Hello! This is the kekklefruit tree. Sorry I haven't called lately. I'm still working on the way to change seeds into Kekklefruit. It's taking longer than I thought... I'm going to really work at it, though... talk to me later. *click*", + "You caught a glimpse of a small, cute Kekklefruit. No, wait, it's just an acorn.", + "What a rebellious kid! Come to the Police Station later! We have some prizes for you. Wait, you only want fruit? Well, nevermind, then. We don't have any of those fruit.", + "Tough out of luck! The kekklefruit tree is completely bare.", + "Your Luck ncreased by 5! You were filled with the Power of the Kekklefruit Tree! Your IQ decreased by 10! There's no fruit, dummy!", + "Hmm... maybe someone else has it.", + "wE fEEl GROOvE! Hi HO. mE mR. kEKkleFruIT tREe. tHis PlacE, all aRE nO FruiT.", + "Stinky! PEEEE-yEUUU! Get those disgusting hands off of the tree! There's no fruit for you!", + "You have caught all of the fish, and now you want all of the fruit? You are a menace to fish-ciety!", + "The boats came early this morning and took all of your fruit. I guess you'll never get any...", + "Our friend $PART_NAME picked 1 stag beetle from the kekklefruit tree and instantly $PREFIXyeeted it in fear.", + 'If only you knew what the word "wait" meant.' ]; diff --git a/src/api/commands/groups/general/myid.ts b/src/api/commands/groups/general/myid.ts index a813068..b6d8ced 100644 --- a/src/api/commands/groups/general/myid.ts +++ b/src/api/commands/groups/general/myid.ts @@ -2,7 +2,7 @@ import Command from "@server/commands/Command"; export const myid = new Command( "myid", - ["myid"], + ["myid", "myuuid"], "Get your own user ID", "myid", "command.general.myid", diff --git a/src/api/commands/groups/index.ts b/src/api/commands/groups/index.ts index 00524c9..d5ff18a 100644 --- a/src/api/commands/groups/index.ts +++ b/src/api/commands/groups/index.ts @@ -27,6 +27,7 @@ import { info } from "./general/info"; import { burger } from "./util/burger"; import { daily } from "./pokemon/daily"; import { give } from "./inventory/give"; +import { group } from "./util/permission"; // import { give } from "./inventory/give"; interface ICommandGroup { @@ -72,7 +73,7 @@ commandGroups.push(pokemonGroup); const utilGroup: ICommandGroup = { id: "util", displayName: "Utility", - commands: [data, setcolor, memory, autofish, fid, chance] + commands: [data, setcolor, memory, autofish, fid, chance, group] }; commandGroups.push(utilGroup); diff --git a/src/api/commands/groups/inventory/eat.ts b/src/api/commands/groups/inventory/eat.ts index d282e84..7ac4cb4 100644 --- a/src/api/commands/groups/inventory/eat.ts +++ b/src/api/commands/groups/inventory/eat.ts @@ -12,7 +12,8 @@ export const eat = new Command( "command.inventory.eat", async props => { const { args, prefix, part, user } = props; - const eating = args[0]; + // const eating = args[0]; + const eating = args.join(" "); if (!eating) return `What do you want to ${prefix}eat?`; const inventory = await getInventory(user.inventoryId); diff --git a/src/api/commands/groups/inventory/sack.ts b/src/api/commands/groups/inventory/sack.ts index 3dfd082..4a4c94e 100644 --- a/src/api/commands/groups/inventory/sack.ts +++ b/src/api/commands/groups/inventory/sack.ts @@ -5,7 +5,18 @@ import type { User } from "@prisma/client"; export const sack = new Command( "sack", - ["sack", "caught", "catched", "sock", "fish-sack", "fishies", "myfish", "mysack", "sacks"], + [ + "sack", + "caught", + "catched", + "sock", + "fish-sack", + "fishies", + "myfish", + "mysack", + "sacks", + "ʂасκ" + ], "List your caught fish", "sack [user ID]", "command.inventory.sack", @@ -37,27 +48,31 @@ export const sack = new Command( const fishSack = inv.fishSack as TFishSack; - return `Contents of ${foundUser.name}'s fish sack: ${fishSack - .map( - (fish: IFish) => - `${fish.emoji || "🐟"}${fish.name}${fish.count ? ` (x${fish.count})` : "" - }` - ) - .join(", ") || "(none)" - }`; + return `Contents of ${foundUser.name}'s fish sack: ${ + fishSack + .map( + (fish: IFish) => + `${fish.emoji || "🐟"}${fish.name}${ + fish.count ? ` (x${fish.count})` : "" + }` + ) + .join(", ") || "(none)" + }`; } else { const inv = await getInventory(user.inventoryId); if (!inv) return; const fishSack = inv.fishSack as TFishSack; - return `Contents of ${part.name}'s fish sack: ${fishSack - .map( - (fish: IFish) => - `${fish.emoji || "🐟"}${fish.name}${fish.count ? ` (x${fish.count})` : "" - }` - ) - .join(", ") || "(none)" - }`; + return `Contents of ${part.name}'s fish sack: ${ + fishSack + .map( + (fish: IFish) => + `${fish.emoji || "🐟"}${fish.name}${ + fish.count ? ` (x${fish.count})` : "" + }` + ) + .join(", ") || "(none)" + }`; } } ); diff --git a/src/api/commands/prefixes.ts b/src/api/commands/prefixes.ts index 04698cd..55c5b9c 100644 --- a/src/api/commands/prefixes.ts +++ b/src/api/commands/prefixes.ts @@ -1 +1 @@ -export const prefixes = ["/"]; +export const prefixes = ["/", "fishing"]; diff --git a/src/talkomatic/bot/TalkomaticBot.ts b/src/talkomatic/bot/TalkomaticBot.ts index 0fa62bf..f359911 100644 --- a/src/talkomatic/bot/TalkomaticBot.ts +++ b/src/talkomatic/bot/TalkomaticBot.ts @@ -4,10 +4,11 @@ import { EventEmitter } from "node:events"; import gettRPC from "@util/api/trpc"; require("dotenv").config(); +const convertMarkdownToUnicode = require("markdown-to-unicode"); export interface TalkomaticBotConfig { channel: { - id: string; + name: string; }; } @@ -27,11 +28,12 @@ export class TalkomaticBot extends EventEmitter { public logger: Logger; public trpc = gettRPC(process.env.TALKOMATIC_FISHING_TOKEN as string); public started = false; - public textColor = "#abe3d6"; + public defaultColor = "#abe3d6"; + public channelId: string = ""; constructor(public config: TalkomaticBotConfig) { super(); - this.logger = new Logger("Talkomatic - " + config.channel.id); + this.logger = new Logger("Talkomatic - " + config.channel.name); // this.client = new Client(config.uri, token); // this.client = io( // "wss://talkomatic.co/socket.io/?EIO=4&transport=websocket&sid=f_X4Z5LB8lKBlybNAdj8" @@ -47,13 +49,26 @@ export class TalkomaticBot extends EventEmitter { }); } - public start() { - this.logger.debug("Starting"); + public async start() { + this.logger.info("Starting"); this.client.connect(); // this.client.io.engine.on("packetCreate", this.logger.debug); this.bindEventListeners(); - this.setChannel(this.config.channel.id); - this.started = true; + + let data = + (await this.findChannel(this.config.channel.name)) || + (await this.createChannel(this.config.channel.name)); + this.logger.debug(data); + + if (typeof data !== "undefined") { + try { + this.channelId = (data as Record).room.room_id; + this.setChannel(this.channelId); + this.started = true; + } catch (err) { + this.logger.error(err); + } + } } public stop() { @@ -80,6 +95,7 @@ export class TalkomaticBot extends EventEmitter { typingFlag: false }; + // this.logger.debug(msg); // p.color = msg.color; if (p.typingTimeout) clearTimeout(p.typingTimeout); @@ -174,18 +190,22 @@ export class TalkomaticBot extends EventEmitter { let part: TalkomaticParticipant = ppl[msg.userId] || { name: "", id: msg.userId, - color: msg.color, + color: this.defaultColor, typingFlag: false }; this.logger.info(`${part.name}: ${msg.text}`); const command = await this.trpc.command.query({ - channel: this.config.channel.id, + channel: this.channelId, args: args.slice(1, args.length), command: args[0].substring(usedPrefix.length), prefix: usedPrefix, - user: part + user: { + id: part.id, + name: part.name, + color: part.color + } }); if (!command) return; @@ -203,9 +223,9 @@ export class TalkomaticBot extends EventEmitter { avatar: string; }) => { const p = ppl[msg.id] || { - name: "", + name: msg.username, id: msg.id, - color: "#ffffff", + color: "#abe3d6", typingFlag: false }; @@ -237,47 +257,141 @@ export class TalkomaticBot extends EventEmitter { } catch (err) {} }); - this.b.on("sendchat", msg => { - // this.logger.debug("sendchat message:", msg); + this.b.on( + "sendchat", + (msg: { m: "sendchat"; channel: string; message: string }) => { + // this.logger.debug("sendchat message:", msg); - if (typeof msg.channel === "string") { - if (msg.channel !== this.config.channel) return; + if (typeof msg.channel === "string") { + if (msg.channel !== this.channelId) return; + } + + this.sendChat(msg.message); } - - this.sendChat(msg.message); - }); + ); } + private oldText: string = ""; + public sendChat(text: string, reply?: string, id?: string) { - // let lines = text.split("\n"); - - // for (const line of lines) { - // const splits = line.match(/.{510}|.{1,509}/gi); - // if (!splits) continue; - - // for (const split of splits) { - // if (split.length <= 510) { - // const text = `\u034f${split - // .split("\t") - // .join("") - // .split("\r") - // .join("")}`; + if ( + this.oldText + .split("\n") + .reverse()[0] + .toLowerCase() + .includes("autofish") + ) + text = [this.oldText, text] + .join("\n") + .split("\n") + .slice(-5) + .join("\n"); const msg = { - roomId: this.config.channel.id, - text, - color: id ? ppl[id].color : "#ffffff" + roomId: this.channelId, + // text: text.split("sack").join("ʂасκ"), + text: text.split("sack").join("caught"), + color: id ? ppl[id].color : this.defaultColor }; + for (const uuid of Object.keys(ppl)) { + const p = ppl[uuid]; + + msg.text = msg.text.split(`@${uuid}`).join(p.name); + + if (!p) continue; + if (uuid !== id) continue; + + msg.color = p.color; + } + + try { + msg.text = convertMarkdownToUnicode(msg.text); + } catch (err) { + this.logger.warn("Unable to parse markdown:", err); + } + this.client.emit("typing", msg); - // } else { - // this.sendChat(split); - // } - // } - // } + + this.oldText = text; } public setChannel(roomId: string) { this.client.emit("joinRoom", { roomId }); } + + public async createChannel( + roomName: string, + roomType: "public" | "private" = "public" + ) { + const response = await fetch( + "https://talkomatic.co/create-and-join-room", + { + method: "POST", + headers: { + "Content-Type": "application/json", + Cookie: "connect.sid=" + process.env.TALKOMATIC_SID + }, + credentials: "include", + body: JSON.stringify({ + roomName, + roomType + }) + } + ); + + if (!response.ok) + return void this.logger.warn( + "Unable to create channel:", + new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ) + ); + + try { + const data = new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ); + + return JSON.parse(data.toString()); + } catch (err) { + this.logger.warn( + "Unable to decode channel creation response data:", + err + ); + } + } + + public async findChannel(name: string) { + const response = await fetch("https://talkomatic.co/rooms", { + method: "GET" + }); + + if (!response.ok) + return void this.logger.warn( + "Unable to create channel:", + new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ) + ); + + try { + const data = new TextDecoder().decode( + (await response.body?.getReader().read())?.value + ); + + const rooms = JSON.parse(data.toString()); + + for (const room of rooms.rooms) { + if (room.room_name == name) { + return { room }; + } + } + } catch (err) { + this.logger.warn( + "Unable to decode channel creation response data:", + err + ); + } + } } diff --git a/src/talkomatic/bot/index.ts b/src/talkomatic/bot/index.ts index 8d53829..782d2f1 100644 --- a/src/talkomatic/bot/index.ts +++ b/src/talkomatic/bot/index.ts @@ -6,7 +6,7 @@ const bots: TalkomaticBot[] = []; const defaults = loadConfig("config/talkomatic_bots.yml", [ { channel: { - id: "116955" + name: "test/fishing" } } ] as TalkomaticBotConfig[]);