Talkomatic stuff

This commit is contained in:
Hri7566 2024-10-12 09:39:57 -04:00
parent 2d0fb07da2
commit 2168ead6e1
15 changed files with 524 additions and 100 deletions

View File

@ -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);
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: "<unknown user>",
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: "<unknown user>",
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) => {
this.b.on(
"sendchat",
(msg) => {
if (typeof msg.channel === "string") {
if (msg.channel !== this.config.channel) return;
if (msg.channel !== this.channelId) return;
}
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"
}
}
]);

BIN
bun.lockb

Binary file not shown.

View File

@ -1,2 +1,2 @@
- channel:
id: "369310"
name: test/fishing

View File

@ -23,6 +23,7 @@
"cli-markdown": "^3.4.0",
"discord.js": "^14.16.2",
"dotenv": "^16.4.5",
"markdown-to-unicode": "^1.0.2",
"mpp-client-net": "^1.2.3",
"prisma": "^5.19.1",
"socket.io-client": "^4.8.0",

17
scripts/talko.ts Normal file
View File

@ -0,0 +1,17 @@
const roomName = "test/fishing";
const roomType = "private";
const response = await fetch("https://talkomatic.co/create-and-join-room", {
method: "POST",
headers: {
"Content-Type": "application/json",
Cookie: "updatePopupClosed1=true; userColor=darkTurquoise; connect.sid=s%3ATTw_3S9yiLjLTGqgn-8q_NvMVyZeKbzL.8s6fsBX70UGA2joKD60nW3pm9XmCELWT4io%2FIfv1yd4"
},
credentials: "include",
body: JSON.stringify({ roomName, roomType })
});
console.log(response);
console.log(
new TextDecoder().decode((await response.body?.getReader().read())?.value)
);

View File

@ -97,7 +97,12 @@ export const appRouter = router({
isDM
);
try {
return out;
} catch (err) {
logger.error(err);
return undefined;
}
}),
backs: privateProcedure.query(async opts => {
@ -106,7 +111,12 @@ export const appRouter = router({
const backs = getBacks<{}>(id);
flushBacks(id);
try {
return backs;
} catch (err) {
logger.error(err);
return undefined;
}
})
});

View File

@ -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}"
];

View File

@ -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.'
];

View File

@ -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",

View File

@ -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);

View File

@ -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);

View File

@ -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,10 +48,12 @@ export const sack = new Command(
const fishSack = inv.fishSack as TFishSack;
return `Contents of ${foundUser.name}'s fish sack: ${fishSack
return `Contents of ${foundUser.name}'s fish sack: ${
fishSack
.map(
(fish: IFish) =>
`${fish.emoji || "🐟"}${fish.name}${fish.count ? ` (x${fish.count})` : ""
`${fish.emoji || "🐟"}${fish.name}${
fish.count ? ` (x${fish.count})` : ""
}`
)
.join(", ") || "(none)"
@ -50,10 +63,12 @@ export const sack = new Command(
if (!inv) return;
const fishSack = inv.fishSack as TFishSack;
return `Contents of ${part.name}'s fish sack: ${fishSack
return `Contents of ${part.name}'s fish sack: ${
fishSack
.map(
(fish: IFish) =>
`${fish.emoji || "🐟"}${fish.name}${fish.count ? ` (x${fish.count})` : ""
`${fish.emoji || "🐟"}${fish.name}${
fish.count ? ` (x${fish.count})` : ""
}`
)
.join(", ") || "(none)"

View File

@ -1 +1 @@
export const prefixes = ["/"];
export const prefixes = ["/", "fishing"];

View File

@ -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);
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<string, any>).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: "<unknown user>",
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: "<unknown user>",
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.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 (msg.channel !== this.channelId) return;
}
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
);
}
}
}

View File

@ -6,7 +6,7 @@ const bots: TalkomaticBot[] = [];
const defaults = loadConfig("config/talkomatic_bots.yml", [
{
channel: {
id: "116955"
name: "test/fishing"
}
}
] as TalkomaticBotConfig[]);