diff --git a/.env.template b/.env.template old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.prettierrc b/.prettierrc old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/bun.lockb b/bun.lockb index 43aecb8..ef277f7 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml old mode 100644 new mode 100755 diff --git a/config/ascii.txt b/config/ascii.txt old mode 100644 new mode 100755 diff --git a/config/ascii.yml b/config/ascii.yml old mode 100644 new mode 100755 diff --git a/config/balance.yml b/config/balance.yml old mode 100644 new mode 100755 diff --git a/config/mpp_net_channels.yml b/config/mpp_net_channels.yml old mode 100644 new mode 100755 index 6f82adc..9a72b3d --- a/config/mpp_net_channels.yml +++ b/config/mpp_net_channels.yml @@ -1,6 +1,11 @@ desiredUser: - name: "πŸŸ‡ π™Žπ™ͺπ™₯π™šπ™§ Cosmic" + #name: "πŸŸ‡ π™Žπ™ͺπ™₯π™šπ™§ Cosmic" + name: "πŸŸ‡ Cosmic ⚝ *help" color: "#1d0054" agents: + #wss://smnmpp.hri7566.info:8443: + # - id: "lobby" wss://mppclone.com: - - id: "βœ§π““π“”π“₯ π“‘π“Έπ“Έπ“Άβœ§" + #- id: "βœ§π““π“”π“₯ π“‘π“Έπ“Έπ“Άβœ§" + #- id: "Hree7566" + - id: "{midi-test}" diff --git a/config/prefixes.yml b/config/prefixes.yml old mode 100644 new mode 100755 index 533a675..f5a4b56 --- a/config/prefixes.yml +++ b/config/prefixes.yml @@ -1,7 +1,7 @@ prefixes: - - id: "**" + - id: "*" spaced: false - - id: cdebug + - id: cosmic spaced: true - - id: d + - id: c spaced: false diff --git a/config/roles.yml b/config/roles.yml index 69e5de1..cf69309 100644 --- a/config/roles.yml +++ b/config/roles.yml @@ -4,6 +4,7 @@ NONE: - cosmic.commandGroup.general - cosmic.command.inventory - cosmic.command.balance + - cosmic.command.bake - cosmic.command.magic8ball - cosmic.command.color - cosmic.command.id diff --git a/config/services.yml b/config/services.yml old mode 100644 new mode 100755 diff --git a/config/switchchat.yml b/config/switchchat.yml old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/pm2.config.cjs b/pm2.config.cjs old mode 100644 new mode 100755 diff --git a/prisma/schema.prisma b/prisma/schema.prisma old mode 100644 new mode 100755 diff --git a/src/commands/Command.ts b/src/commands/Command.ts old mode 100644 new mode 100755 diff --git a/src/commands/CommandGroup.ts b/src/commands/CommandGroup.ts old mode 100644 new mode 100755 diff --git a/src/commands/CommandHandler.ts b/src/commands/CommandHandler.ts old mode 100644 new mode 100755 diff --git a/src/commands/Prefix.ts b/src/commands/Prefix.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/economy/bake.ts b/src/commands/commands/economy/bake.ts new file mode 100755 index 0000000..e1612bd --- /dev/null +++ b/src/commands/commands/economy/bake.ts @@ -0,0 +1,15 @@ +import { formatBalance } from "../../../economy/Balance"; +import { startBaking } from "../../../economy/baking"; +import { Command } from "../../Command"; + +export const bake = new Command( + "bake", + ["bake", "b", "startbaking", "bakecake", "oven"], + "bozo's oven", + "bake", + (msg, agent) => { + const agentId = globalThis.serviceLoader.getAgentId(agent); + const message = startBaking(msg.user.id, agentId); + return message; + } +); diff --git a/src/commands/commands/economy/balance.ts b/src/commands/commands/economy/balance.ts old mode 100644 new mode 100755 index 85c3d92..546e8b1 --- a/src/commands/commands/economy/balance.ts +++ b/src/commands/commands/economy/balance.ts @@ -8,6 +8,6 @@ export const balance = new Command( "balance", msg => { const bal = msg.inventory.balance; - return `Balance: ${formatBalance(bal)}`; + return `Your balance: ${formatBalance(bal)}`; } ); diff --git a/src/commands/commands/economy/grow.ts b/src/commands/commands/economy/grow.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/economy/inventory.ts b/src/commands/commands/economy/inventory.ts old mode 100644 new mode 100755 index a566aa1..f423fec --- a/src/commands/commands/economy/inventory.ts +++ b/src/commands/commands/economy/inventory.ts @@ -1,4 +1,5 @@ -import { Item, StackableItem } from "../../../economy/Item"; +import { readItems } from "../../../data/inventory"; +import { CakeItem, Item, StackableItem } from "../../../economy/Item"; import { Command } from "../../Command"; export const inventory = new Command( @@ -6,16 +7,18 @@ export const inventory = new Command( ["inventory", "inv"], "get bozo's inventory", "inventory", - msg => { - const items = msg.inventory.items as string; - console.log(items); - const list = JSON.parse(items) + async msg => { + const items = await readItems(msg.p._id); + if (!items) return `Items: (none)`; + + console.log(typeof items, items); + + const list = items .map( i => - `${i.name}${ - (i as StackableItem).count - ? " " + (i as StackableItem).count - : "" + `${(i as CakeItem).emoji ? (i as CakeItem).emoji : ""}${i.name}${(i as StackableItem).count + ? " " + `(x${(i as StackableItem).count})` + : "" }` ) .join(" | "); diff --git a/src/commands/commands/economy/pick.ts b/src/commands/commands/economy/pick.ts old mode 100644 new mode 100755 index 3391a07..0920328 --- a/src/commands/commands/economy/pick.ts +++ b/src/commands/commands/economy/pick.ts @@ -16,5 +16,6 @@ export const pick = new Command( addItem(msg.p._id, fruit); return `(insert random boring message about ${fruit.name} here)`; - } + }, + false ); diff --git a/src/commands/commands/economy/tree.ts b/src/commands/commands/economy/tree.ts old mode 100644 new mode 100755 index 2f18341..1aa4901 --- a/src/commands/commands/economy/tree.ts +++ b/src/commands/commands/economy/tree.ts @@ -8,5 +8,6 @@ export const tree = new Command( "tree", async msg => { return `There are ${KekklefruitTree.getFruitCount()} kekklefruit on the tree.`; - } + }, + false ); diff --git a/src/commands/commands/fun/eat.ts b/src/commands/commands/fun/eat.ts new file mode 100755 index 0000000..47fc040 --- /dev/null +++ b/src/commands/commands/fun/eat.ts @@ -0,0 +1,50 @@ +import { readItems, subtractItem } from "../../../data/inventory"; +import { FoodItem } from "../../../economy/Item"; +import { TEatBhv, eatBhv } from "../../../economy/eatBhv"; +import { Logger } from "../../../util/Logger"; +import { Command } from "../../Command"; + +const logger = new Logger("eat"); + +export const eat = new Command( + "eat", + ["eat"], + "bozo hungy", + "eat", + async (msg, agent) => { + if (!msg.argv[1]) return "What do you want to eat?"; + const itemFuzzy = msg.argv[1].toLowerCase(); + const items = await readItems(msg.user.id); + if (!items) return "You have nothing to eat."; + + let what = items.find(item => { + if (item.name.toLowerCase().includes(itemFuzzy)) return true; + }) as FoodItem | undefined; + + if (!what) return `You don't have any "${itemFuzzy}" to eat.`; + if (!what.consumable) return `You can't eat the ${what.name}.`; + if (!what.edible) return `The ${what.name} is not edible.`; + + // TODO cause eat behavior + let bhv: TEatBhv | undefined; + + if (what.id.includes("cake")) { + // Find regular cake behavior + bhv = eatBhv.get("cake"); + } else { + // Find eat bhv for item ID + bhv = eatBhv.get(what.id); + } + + if (!bhv) return `You don't know how to eat ${what.name}.`; + const reply = await bhv(msg, agent, what); + + if (reply.consumed) { + const worked = await subtractItem(msg.user.id, what); + if (!worked) logger.warn(`Failed to subtract item ${what.name} from user ${msg.user.id}`); + } + + return reply.output; + //return `You ate the ${what.name}. (not really)`; + } +); diff --git a/src/commands/commands/fun/magic8ball.ts b/src/commands/commands/fun/magic8ball.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/general/about.ts b/src/commands/commands/general/about.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/general/help.ts b/src/commands/commands/general/help.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/branch.ts b/src/commands/commands/utility/branch.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/color.ts b/src/commands/commands/utility/color.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/crown.ts b/src/commands/commands/utility/crown.ts new file mode 100644 index 0000000..49314a1 --- /dev/null +++ b/src/commands/commands/utility/crown.ts @@ -0,0 +1,16 @@ +import Client from "mpp-client-net"; +import { Command } from "../../Command"; + +export const crown = new Command( + "crown", + ["crown"], + "get bozo hat", + "crown", + (msg, agent) => { + if (agent.platform !== "mpp") return; + (agent.client as Client).sendArray([{ + m: "chown", + id: msg.p.platformId + }]); + } +); diff --git a/src/commands/commands/utility/cursor.ts b/src/commands/commands/utility/cursor.ts old mode 100644 new mode 100755 index 6cf3b0d..913ec1e --- a/src/commands/commands/utility/cursor.ts +++ b/src/commands/commands/utility/cursor.ts @@ -1,4 +1,4 @@ -import type { MPPAgent } from "../../../services/mpp"; +import type { MPPNetAgent } from "../../../services/mppnet"; import { Command } from "../../Command"; export const cursor = new Command( @@ -10,7 +10,7 @@ export const cursor = new Command( if (agent.platform !== "mpp") return; if (!msg.argv[1]) return "Specify a mode."; - const cursor = (agent as MPPAgent).cursor; + const cursor = (agent as MPPNetAgent).cursor; cursor.props.currentAnimation = msg.argv[1]; } ); diff --git a/src/commands/commands/utility/delinv.ts b/src/commands/commands/utility/delinv.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/ic.ts b/src/commands/commands/utility/ic.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/id.ts b/src/commands/commands/utility/id.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/math.ts b/src/commands/commands/utility/math.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/memory.ts b/src/commands/commands/utility/memory.ts old mode 100644 new mode 100755 index 661e2fe..1b37e7e --- a/src/commands/commands/utility/memory.ts +++ b/src/commands/commands/utility/memory.ts @@ -6,10 +6,12 @@ export const memory = new Command( "get the memory bozo", "memory", () => { - return `${(process.memoryUsage().heapUsed / 1000 / 1000).toFixed( - 2 - )} MB used / ${(process.memoryUsage().heapTotal / 1000 / 1000).toFixed( - 2 - )} MB total`; + const mem = process.memoryUsage(); + + return `${(mem.heapUsed / 1000 / 1000).toFixed(2)} MB / ${( + mem.heapTotal / + 1000 / + 1000 + ).toFixed(2)} MB / ${(mem.rss / 1000 / 1000).toFixed(2)} MB`; } ); diff --git a/src/commands/commands/utility/msg.ts b/src/commands/commands/utility/msg.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/permissions.ts b/src/commands/commands/utility/permissions.ts old mode 100644 new mode 100755 index 803ea73..04f2536 --- a/src/commands/commands/utility/permissions.ts +++ b/src/commands/commands/utility/permissions.ts @@ -18,9 +18,7 @@ export const permissions = new Command( if (msg.argv[1]) role = fuzzyFindRoleByDisplayName(msg.argv[1]); if (role) { - return `Permissions for role "${ - role.displayName - }": ${role.permissions.join(" | ")}`; + return `Permissions for role \`${role.displayName}\`: \`${role.permissions.join("\` | \`")}\``; } else { return `No role found.`; } diff --git a/src/commands/commands/utility/role.ts b/src/commands/commands/utility/role.ts old mode 100644 new mode 100755 diff --git a/src/commands/commands/utility/uptime.ts b/src/commands/commands/utility/uptime.ts old mode 100644 new mode 100755 diff --git a/src/commands/index.ts b/src/commands/index.ts old mode 100644 new mode 100755 index 2f33597..f506a40 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -19,6 +19,9 @@ import { tree } from "./commands/economy/tree"; import { pick } from "./commands/economy/pick"; import { grow } from "./commands/economy/grow"; import { delinv } from "./commands/utility/delinv"; +import { eat } from "./commands/fun/eat"; +import { bake } from "./commands/economy/bake"; +import { crown } from "./commands/utility/crown"; export function loadCommands() { // cringe @@ -27,11 +30,11 @@ export function loadCommands() { globalThis.commandHandler.addCommandGroup(general); const economy = new CommandGroup("economy", "πŸ’Έ Economy"); - economy.addCommands([inventory, balance, tree, pick, grow]); + economy.addCommands([inventory, balance, tree, pick, grow, bake]); globalThis.commandHandler.addCommandGroup(economy); const fun = new CommandGroup("fun", "✨ Fun"); - fun.addCommands([magic8ball]); + fun.addCommands([magic8ball, eat]); globalThis.commandHandler.addCommandGroup(fun); const utility = new CommandGroup("utility", "πŸ”¨ Utility"); @@ -47,7 +50,8 @@ export function loadCommands() { uptime, permissions, branch, - delinv + delinv, + crown ]); globalThis.commandHandler.addCommandGroup(utility); } diff --git a/src/data/inventory.ts b/src/data/inventory.ts old mode 100644 new mode 100755 index 7baac39..2b7795a --- a/src/data/inventory.ts +++ b/src/data/inventory.ts @@ -16,14 +16,51 @@ export async function readInventory(userId: Inventory["userId"]) { return await prisma.inventory.findUnique({ where: { userId: userId } }); } +export async function readItems(userId: Inventory["userId"]) { + const inv = await readInventory(userId); + if (!inv) return null; + + console.log("bruh", inv.items, "end bruh"); + + // prisma why? pick one!!! + if (typeof inv.items !== "string") return inv.items as unknown as Item[]; + return JSON.parse(inv.items) as Item[]; +} + export function collapseInventory(inventoryData: Item[]) { + let newItems: Item[] = []; + + oldLoop: + for (let i of inventoryData) { + let found = false; + + newLoop: + for (let j of newItems) { + if (i.id === j.id) { + // Merge + if ( + typeof (i as StackableItem).count === "number" && + typeof (j as StackableItem).count === "number" + ) { + (i as StackableItem).count += (j as StackableItem).count; + } + + found = true; + break newLoop; + } + } + + // Add + if (!found) newItems.push(i); + } + for (let i = 0; i < inventoryData.length; i++) { if (i <= 0) continue; if (inventoryData[i].id === inventoryData[i - 1].id) { if ( typeof (inventoryData[i - 1] as StackableItem).count === - "number" && + "number" && typeof (inventoryData[i] as StackableItem).count === "number" ) { (inventoryData[i - 1] as StackableItem).count += ( @@ -42,7 +79,7 @@ export async function updateInventory(data: Omit) { where: { userId: data.userId }, data: { balance: data.balance, - items: JSON.stringify(data.items) + items: data.items as JsonArray } }); } @@ -51,16 +88,46 @@ export async function deleteInventory(userId: Inventory["userId"]) { return await prisma.inventory.delete({ where: { userId } }); } -export async function addItem(userId: Inventory["userId"], item: T) { +export async function addItem( + userId: Inventory["userId"], + item: T +) { let inventory = await readInventory(userId); if (!inventory) return false; - console.log(inventory.items); - - inventory.items = JSON.stringify(JSON.parse(inventory.items as string).push(item)); + (inventory.items as unknown as Item[]).push(item); collapseInventory(inventory.items as unknown as Item[]); await updateInventory(inventory); return true; } + +export async function subtractItem( + userId: Inventory["userId"], + item: T +) { + let inventory = await readInventory(userId); + if (!inventory) return false; + + if ((item as unknown as StackableItem).count) { + const it = (inventory.items as unknown as Item[]).find( + it => it.id == item.id + ); + if (!it) return false; + (it as StackableItem).count--; + } else { + const it = (inventory.items as unknown as Item[]).find( + it => it.id == item.id + ); + if (!it) return false; + (inventory.items as unknown as Item[]).splice( + (inventory.items as unknown as Item[]).indexOf(it), + 1 + ); + } + + await updateInventory(inventory); + + return true; +} diff --git a/src/data/prisma.ts b/src/data/prisma.ts old mode 100644 new mode 100755 diff --git a/src/data/user.ts b/src/data/user.ts old mode 100644 new mode 100755 diff --git a/src/economy/Balance.ts b/src/economy/Balance.ts old mode 100644 new mode 100755 index 17cb6cb..1fababd --- a/src/economy/Balance.ts +++ b/src/economy/Balance.ts @@ -1,3 +1,4 @@ +import { readInventory, updateInventory } from "../data/inventory"; import { loadConfig } from "../util/config"; export const balanceConfig = loadConfig("config/balance.yml", { @@ -16,3 +17,17 @@ export function formatBalance( if (after) return `${balance.toFixed(cutoff)}${symbol}`; else return `${symbol}${balance.toFixed(cutoff)}`; } + +export async function getBalance(id: string) { + const inventory = await readInventory(id); + if (!inventory) return balanceConfig.defaultBalance; + return inventory.balance; +} + +export async function setBalance(id: string, balance: number) { + const inventory = await readInventory(id); + if (!inventory) return false; + inventory.balance = balance; + await updateInventory(inventory); + return true; +} diff --git a/src/economy/Item.ts b/src/economy/Item.ts old mode 100644 new mode 100755 diff --git a/src/economy/baking/cakes.ts b/src/economy/baking/cakes.ts new file mode 100755 index 0000000..af39854 --- /dev/null +++ b/src/economy/baking/cakes.ts @@ -0,0 +1,32 @@ +import { type CakeItem } from "../Item"; + +export const cakes: CakeItem[] = [ + { + id: "cake", + name: "Chocolate Cake", + emoji: "πŸŽ‚", + icing: "chocolate", + filling: "chocolate", + edible: true, + consumable: true, + }, + { + id: "cake", + name: "Vanilla Cake", + emoji: "πŸŽ‚", + icing: "vanilla", + filling: "vanilla", + edible: true, + consumable: true, + }, + { + id: "cake", + name: "Strawberry Cake", + emoji: "πŸ“", + icing: "strawberry", + filling: "strawberry", + edible: true, + consumable: true, + } +]; + diff --git a/src/economy/baking/index.ts b/src/economy/baking/index.ts new file mode 100755 index 0000000..f3ef6e1 --- /dev/null +++ b/src/economy/baking/index.ts @@ -0,0 +1,93 @@ +import { User } from "@prisma/client"; +import { cakes } from "./cakes"; +import { ServiceAgent } from "../../services/ServiceAgent"; +import { StackableItem } from "../Item"; +import { Logger } from "../../util/Logger"; +import { addItem } from "../../data/inventory"; +import { readUser } from "../../data/user"; + +export interface BakingUser { + id: User["id"]; + client_id: string; +} + +export const bakingUsers = new Array(); + +export function getRandomCake() { + return cakes[Math.floor(Math.random() * cakes.length)]; +} + +export function isBaking(userId: User["id"]) { + return bakingUsers.find(u => u.id === userId) !== undefined; +} + +const alreadyBakingAnswers = [ + "You are already baking, dummy.", + "Though it seems you don't care, you are already baking a cake, and you can't start baking another one.", + "Baking is an art that requires patience, which you do not have. In other words, you are already baking, dummy.", + "You shouldn't be baking any more cakes than one at a time.", + "You happen to be baking already, and you would need another oven to bake another cake, and there is only one oven in your house.", + "Since you don't seem to get it, baking can not be started again while you are already baking.", + "You are already baking.", + "Baking is something you are already doing.", + "Baking should be something you do once in a while, not constantly.", + "You are currently baking a cake, which means the oven is already in use, so you can't start baking another one." +]; + +export function startBaking(userId: User["id"], clientId: string) { + // Already baking? + if (isBaking(userId)) return alreadyBakingAnswers[Math.floor(Math.random() * alreadyBakingAnswers.length)]; + + // Add to baking list + bakingUsers.push({ + id: userId, + client_id: clientId + }); + + return "You started baking a cake."; +} + +export function stopBaking(userId: User["id"]) { + if (!isBaking(userId)) return "You are not baking."; + bakingUsers.splice(bakingUsers.findIndex(u => u.id === userId), 1); + return "You stopped baking a cake."; +} + +export function getRandomBaker() { + return bakingUsers[Math.floor(Math.random() * bakingUsers.length)]; +} + +export function getClient(clientId: string) { + const agent = globalThis.serviceLoader.getAgent(0) as ServiceAgent; + return agent; +} + +const logger = new Logger("baking"); + +setInterval(async () => { + const r = Math.random(); + + //logger.debug(`Baking check: ${r}`); + + if (r < 0.03) { + // Get a random baker and send them a cake and a message stating they finished baking + const baker = getRandomBaker(); + if (!baker) return; + const client = getClient(baker.client_id); + bakingUsers.splice(bakingUsers.findIndex(u => u.id === baker.id), 1); + + if (client) { + const cake = getRandomCake(); + const user = await readUser(baker.id); + + if (!user) return void client.emit("send chat", "Something terrible happened when I tried to give someone a cake"); + + client.emit("send chat", `@${user.platformId} finished baking and got ${cake.name}${(cake as unknown as StackableItem).count + ? " " + `(x${(cake as unknown as StackableItem).count})` : ""}.`); + + + // Add cake to inventory + await addItem(baker.id, cake); + } + } +}, 1000); diff --git a/src/economy/eatBhv.ts b/src/economy/eatBhv.ts new file mode 100755 index 0000000..e5840fe --- /dev/null +++ b/src/economy/eatBhv.ts @@ -0,0 +1,35 @@ +import type { CommandMessage } from "../commands/CommandHandler"; +import type { ServiceAgent } from "../services/ServiceAgent"; +import { formatBalance, getBalance, setBalance } from "./Balance"; +import type { CakeItem, Item } from "./Item"; + +export interface IEatReply { + output?: string; + consumed: boolean; +} + +export type TEatBhv = (msg: CommandMessage, agent: ServiceAgent, item: Item) => Promise; + +export const eatBhv = new Map(); + +eatBhv.set("kekklefruit", async (msg, agent) => { + return { + output: "kek eat bhv test", + consumed: true + }; +}); + +eatBhv.set("cake", async (msg, agent, item) => { + const cake = item as CakeItem; + const balance = await getBalance(msg.user.id); + + if (typeof balance !== "number") return { output: "Somehow, you don't have a wallet to put stuff in, so you can't eat cake.", consumed: false }; + + const money = Math.floor(Math.random() * 500); + await setBalance(msg.user.id, balance + money); + + return { + output: `You ate ${item.name} and your stomach turned it into ${formatBalance(money)}.`, + consumed: true + }; +}); diff --git a/src/economy/items.ts b/src/economy/items.ts old mode 100644 new mode 100755 diff --git a/src/economy/kekkle.ts b/src/economy/kekkle.ts old mode 100644 new mode 100755 index 478e35f..dd3198b --- a/src/economy/kekkle.ts +++ b/src/economy/kekkle.ts @@ -1,6 +1,6 @@ import { get, set } from "../data/prisma"; import { Logger } from "../util/Logger"; -import { FoodItem } from "./Item"; +import type { FoodItem, StackableItem } from "./Item"; export class KekklefruitTree { protected static fruit: number = 0; @@ -47,8 +47,9 @@ export class KekklefruitTree { id: "kekklefruit", name: "Kekklefruit", consumable: true, - edible: true - } as FoodItem; + edible: true, + count: 1 + } as FoodItem & StackableItem; } } diff --git a/src/index.ts b/src/index.ts old mode 100644 new mode 100755 diff --git a/src/permissions/default.ts b/src/permissions/default.ts old mode 100644 new mode 100755 index a2c748d..9505c9a --- a/src/permissions/default.ts +++ b/src/permissions/default.ts @@ -9,6 +9,8 @@ export const defaultConfig = { "cosmic.command.inventory", "cosmic.command.balance", + "cosmic.command.bake", + "cosmic.command.eat", "cosmic.command.magic8ball", diff --git a/src/permissions/index.ts b/src/permissions/index.ts old mode 100644 new mode 100755 diff --git a/src/services/ServiceAgent.ts b/src/services/ServiceAgent.ts old mode 100644 new mode 100755 diff --git a/src/services/console/MicroHandler.ts b/src/services/console/MicroHandler.ts old mode 100644 new mode 100755 index 3b59e97..4743b96 --- a/src/services/console/MicroHandler.ts +++ b/src/services/console/MicroHandler.ts @@ -6,7 +6,8 @@ import { BaseCommandMessage } from "../../commands/CommandHandler"; import { readUser, updateUser } from "../../data/user"; import { CosmicColor } from "../../util/CosmicColor"; import { ServiceAgent } from "../ServiceAgent"; -import { MPPAgent } from "../mpp"; +import { MPPNetAgent } from "../mppnet"; +import { readFileSync } from "fs"; export interface ChatMessage { m: "a"; @@ -55,7 +56,7 @@ export class MicroHandler { case "commands": case "cmds": default: - return "Microcommands: /help | /js | /exit | /list | /view | /unview | /admin+ | /admin- | /owner+ "; + return "Microcommands: /help | /js | /exit | /list | /view | /unview | /admin+ | /admin- | /owner+ | /owner- "; break; case "js": case "eval": @@ -80,8 +81,7 @@ export class MicroHandler { if (agent2.platform === "mpp") { agent.emit( "log", - `${i} - ${agent2.platform} - ${ - (agent2 as MPPAgent).desiredChannel + `${i} - ${agent2.platform} - ${(agent2 as MPPNetAgent).desiredChannel }` ); } else { @@ -150,11 +150,10 @@ export class MicroHandler { if (conAg.viewAgent.platform !== "mpp") return "The view agent is not on MPP."; - const ppl = (conAg.viewAgent as MPPAgent).client.ppl; + const ppl = (conAg.viewAgent as MPPNetAgent).client.ppl; return `MPP Users: ${Object.values(ppl).map( p => - `\n - ${p._id} (user) / ${p.id} (part): ${p.name} (${ - p.color + `\n - ${p._id} (user) / ${p.id} (part): ${p.name} (${p.color }, ${new CosmicColor(p.color).getName()})` )}`; break; @@ -206,6 +205,22 @@ export class MicroHandler { 6 )}...] an owner`; break; + case "owner-": + const userId4 = command.argv + .slice(1, command.argv.length) + .join(" "); + + let user4 = await readUser(userId4); + if (!user4) return "No such user."; + + user4.role = Role.NONE; + await updateUser(user4); + + return `Made user "${user4.name}" [${user4.platformId.substring( + 0, + 6 + )}] a normal user.`; + break; } } } diff --git a/src/services/console/index.ts b/src/services/console/index.ts old mode 100644 new mode 100755 index ebd2b59..dd22555 --- a/src/services/console/index.ts +++ b/src/services/console/index.ts @@ -32,12 +32,14 @@ export class ConsoleAgent extends ServiceAgent { this.started = true; this.client.setPrompt("> "); this.client.prompt(true); + (globalThis as any).readline = this.client; } public stop() { if (!this.started) return; this.started = false; this.client.close(); + delete (globalThis as any).readline; } protected bindEventListeners(): void { diff --git a/src/services/discord/index.ts b/src/services/discord/index.ts old mode 100644 new mode 100755 diff --git a/src/services/index.ts b/src/services/index.ts old mode 100644 new mode 100755 index d9b0791..1a37abb --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,4 +1,4 @@ -import { MPPAgent } from "./mpp"; +import { MPPNetAgent } from "./mppnet"; import env from "../util/env"; import { ServiceAgent } from "./ServiceAgent"; import { loadConfig } from "../util/config"; @@ -58,14 +58,14 @@ export class ServiceLoader { if (config.enableMPP) { for (const uri of Object.keys(mppConfig.agents)) { for (const channel of mppConfig.agents[uri]) { - const mppAgent = new MPPAgent( + const mppAgent = new MPPNetAgent( uri, channel.id, channel.overrideName ? { - name: channel.overrideName, - color: mppConfig.desiredUser.color - } + name: channel.overrideName, + color: mppConfig.desiredUser.color + } : mppConfig.desiredUser, env.MPPNET_TOKEN, config.debug @@ -107,4 +107,8 @@ export class ServiceLoader { this.agents.splice(this.agents.indexOf(agent), 1); } } + + public static getAgentId(agent: ServiceAgent) { + return this.agents.indexOf(agent); + } } diff --git a/src/services/mpp/Cursor.ts b/src/services/mppnet/Cursor.ts old mode 100644 new mode 100755 similarity index 88% rename from src/services/mpp/Cursor.ts rename to src/services/mppnet/Cursor.ts index 5492cec..e2cf252 --- a/src/services/mpp/Cursor.ts +++ b/src/services/mppnet/Cursor.ts @@ -1,4 +1,4 @@ -import { MPPAgent } from "."; +import { MPPNetAgent } from "."; interface Vector2 { x: number; @@ -20,12 +20,22 @@ interface CursorProps { } export class Cursor { + public static animations = new Map void>(); + public visible: boolean = true; public displayInterval: NodeJS.Timeout; public updateInterval: NodeJS.Timeout; + public animationLoop = [ + "bounce", + "bounce2", + "constrained", + "lemniscate", + "test", + ]; + public props: CursorProps = { - currentAnimation: "lemniscate", + currentAnimation: this.animationLoop[0], position: { x: 50, y: 50 @@ -50,7 +60,7 @@ export class Cursor { following: "" }; - constructor(public agent: MPPAgent) { + constructor(public agent: MPPNetAgent) { this.displayInterval = setInterval(() => { if ( this.props.oldPosition.x !== this.props.position.x || @@ -66,6 +76,13 @@ export class Cursor { } }, 1000 / 20); + let animationIndex = 0; + const animationInterval = setInterval(() => { + animationIndex++; + if (animationIndex >= this.animationLoop.length) animationIndex = 0; + this.props.currentAnimation = this.animationLoop[animationIndex]; + }, 10000); + this.updateInterval = setInterval(() => { switch (this.props.currentAnimation) { case "bounce": @@ -88,6 +105,11 @@ export class Cursor { this.props.velocity.y += this.props.acceleration.y * this.props.dt; + if (this.props.velocity.x > 50) this.props.velocity.x = 50; + if (this.props.velocity.x < -50) this.props.velocity.x = -50; + if (this.props.velocity.y > 50) this.props.velocity.y = 50; + if (this.props.velocity.y < -50) this.props.velocity.y = -50; + this.props.position.x += this.props.velocity.x * this.props.dt; this.props.position.y += @@ -135,7 +157,7 @@ export class Cursor { if (this.props.position.y < 75) { this.props.acceleration.y = - Math.random() * 100 - 50 - this.props.gravity; + ((Math.random() * 50) - 25) - this.props.gravity; } else { this.props.acceleration.y = -(Math.random() * 50); } @@ -239,7 +261,7 @@ export class Cursor { 50; this.props.position.y = Math.sin(this.props.angles[0] * (Math.PI / 180) * 3) * - 10 + + 10 + 50; break; @@ -254,7 +276,7 @@ export class Cursor { 50; this.props.position.y = Math.sin(this.props.angles[0] * (Math.PI / 180) * 2) * - 10 + + 10 + 50; break; @@ -296,7 +318,7 @@ export class Cursor { break; } - }, 1000 / 60); + }, 1500 / 60); } public show() { diff --git a/src/services/mpp/index.ts b/src/services/mppnet/index.ts old mode 100644 new mode 100755 similarity index 96% rename from src/services/mpp/index.ts rename to src/services/mppnet/index.ts index 1d202f1..6b9a11a --- a/src/services/mpp/index.ts +++ b/src/services/mppnet/index.ts @@ -5,7 +5,7 @@ import { Cursor } from "./Cursor"; import { ChatMessage } from "../console/MicroHandler"; import { help as helpCommand } from "../../commands/commands/general/help"; -export class MPPAgent extends ServiceAgent { +export class MPPNetAgent extends ServiceAgent { public cursor: Cursor; constructor( @@ -18,6 +18,7 @@ export class MPPAgent extends ServiceAgent { const cl = new Client(uri, token); super("mpp", cl); this.cursor = new Cursor(this); + this.cursor.show(); } public start() { @@ -33,11 +34,14 @@ export class MPPAgent extends ServiceAgent { this.client.on("hi", msg => { this.client.setChannel(this.desiredChannel); + }); + + this.client.on("ch", msg => { this.fixUser(); }); this.client.on("t", msg => { - this.fixUser(); + // this.fixUser(); }); this.client.on("a", async msg => { diff --git a/src/services/switchchat/index.ts b/src/services/switchchat/index.ts old mode 100644 new mode 100755 diff --git a/src/util/CosmicColor.ts b/src/util/CosmicColor.ts old mode 100644 new mode 100755 diff --git a/src/util/Logger.ts b/src/util/Logger.ts old mode 100644 new mode 100755 index cb8f698..1cf6774 --- a/src/util/Logger.ts +++ b/src/util/Logger.ts @@ -17,6 +17,8 @@ export function padNum( export class Logger { private static log(method: string, ...args: any[]) { + process.stdout.write(`\x1b[2K\r`); + (console as unknown as Record any>)[ method ]( @@ -24,6 +26,10 @@ export class Logger { unimportant(this.getHHMMSSMS()), ...args ); + + if ((globalThis as any).readline) { + (globalThis as any).readline.prompt(); + } } public static getHHMMSSMS() { diff --git a/src/util/ascii.ts b/src/util/ascii.ts old mode 100644 new mode 100755 diff --git a/src/util/config.ts b/src/util/config.ts old mode 100644 new mode 100755 diff --git a/src/util/env.ts b/src/util/env.ts old mode 100644 new mode 100755 diff --git a/src/util/git.ts b/src/util/git.ts old mode 100644 new mode 100755 diff --git a/test/data/inventory.test.ts b/test/data/inventory.test.ts old mode 100644 new mode 100755 diff --git a/tsconfig.json b/tsconfig.json old mode 100644 new mode 100755