diff --git a/src/commands/CommandHandler.ts b/src/commands/CommandHandler.ts index ad46f19..2f063b9 100644 --- a/src/commands/CommandHandler.ts +++ b/src/commands/CommandHandler.ts @@ -7,6 +7,7 @@ import { Prefix } from "./Prefix"; import { createInventory, readInventory } from "../data/inventory"; import { hasPermission } from "../permissions"; import { Logger } from "../util/Logger"; +import { balanceConfig } from "../economy/Balance"; export interface CommandMessage { m: "command"; @@ -77,7 +78,8 @@ export class CommandHandler { if (!inventory) { await createInventory({ userId: msg.p._id, - items: [] + items: [], + balance: balanceConfig.defaultBalance || 0 }); inventory = await readInventory(msg.p._id); diff --git a/src/commands/commands/economy/balance.ts b/src/commands/commands/economy/balance.ts index e9eff2e..85c3d92 100644 --- a/src/commands/commands/economy/balance.ts +++ b/src/commands/commands/economy/balance.ts @@ -1,5 +1,4 @@ import { formatBalance } from "../../../economy/Balance"; -import { Item, StackableItem } from "../../../economy/Item"; import { Command } from "../../Command"; export const balance = new Command( @@ -7,7 +6,7 @@ export const balance = new Command( ["balance", "bal", "money"], "get bozo's balance", "balance", - (msg, agent) => { + msg => { const bal = msg.inventory.balance; return `Balance: ${formatBalance(bal)}`; } diff --git a/src/commands/commands/economy/inventory.ts b/src/commands/commands/economy/inventory.ts index 10c55ad..0b1c767 100644 --- a/src/commands/commands/economy/inventory.ts +++ b/src/commands/commands/economy/inventory.ts @@ -1,13 +1,12 @@ import { Item, StackableItem } from "../../../economy/Item"; import { Command } from "../../Command"; -import { CommandHandler } from "../../CommandHandler"; export const inventory = new Command( "inventory", ["inventory", "inv"], "get bozo's inventory", "inventory", - (msg, agent) => { + msg => { const items = msg.inventory.items as unknown as Item[]; const list = items .map( diff --git a/src/commands/commands/fun/magic8ball.ts b/src/commands/commands/fun/magic8ball.ts index b12f01d..b380693 100644 --- a/src/commands/commands/fun/magic8ball.ts +++ b/src/commands/commands/fun/magic8ball.ts @@ -3,26 +3,26 @@ import crypto from "crypto"; // Possible answers const answers = [ - "It is certain", - "It is decidedly so", - "Without a doubt", - "Yes, definitely", - "You may rely on it", - "As I see it, yes", - "Most likely", - "Outlook good", - "Yes", - "Signs point to yes", - "Reply hazy, try again", - "Ask again later", - "Better not tell you now", - "Cannot predict now", - "Concentrate and ask again", - `Don't count on it`, - "My reply is no", - "My sources say no", - "Outlook not so good", - "Very doubtful" + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes, definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Reply hazy, try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + `Don't count on it`, + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful" ]; export const magic8ball = new Command( @@ -30,37 +30,37 @@ export const magic8ball = new Command( ["magic8ball", "8ball", "8"], "magic8ball bozo", "magic8ball ", - (msg, agent) => { - /** - * Magic 8 ball command - * - * Returns a unique answer for every question asked. - */ + msg => { + /** + * Magic 8 ball command + * + * Returns a unique answer for every question asked. + */ - // Check arguments - // We're not checking for question marks since the user might think that's too much work - if (!msg.argv[1]) return `šŸŽ± Ask me a question, dummy`; + // Check arguments + // We're not checking for question marks since the user might think that's too much work + if (!msg.argv[1]) return `šŸŽ± Ask me a question, dummy`; - // Hash the question (the user will get the same response for repeated questions) - // We use a predictable but unique salt (security by obscurity?) - const hash = crypto.createHash("sha-256"); - hash.update("magic" + msg.argv[1] + "8ball"); + // Hash the question (the user will get the same response for repeated questions) + // We use a predictable but unique salt (security by obscurity?) + const hash = crypto.createHash("sha-256"); + hash.update("magic" + msg.argv[1] + "8ball"); - // Use the question hash as the index - const hex = hash.digest("hex"); - let index = parseInt(hex[0] + hex[1] + hex[2], 16); + // Use the question hash as the index + const hex = hash.digest("hex"); + let index = parseInt(hex[0] + hex[1] + hex[2], 16); - // Make sure the index is within the bounds of the answers array - while (index >= answers.length) { - index -= answers.length; - } + // Make sure the index is within the bounds of the answers array + while (index >= answers.length) { + index -= answers.length; + } - while (index <= 0) { - index += answers.length; - } + while (index <= 0) { + index += answers.length; + } - // Answer the user's question - let answer = answers[index]; - return `šŸŽ± ${answer}, ${msg.p.name}`; + // Answer the user's question + let answer = answers[index]; + return `šŸŽ± ${answer}, ${msg.p.name}`; } ); diff --git a/src/commands/commands/general/about.ts b/src/commands/commands/general/about.ts index c0a3b6b..3b8d4c3 100644 --- a/src/commands/commands/general/about.ts +++ b/src/commands/commands/general/about.ts @@ -5,7 +5,7 @@ export const about = new Command( ["about", "info"], "get about bozo", "about", - (msg, agent) => { + () => { return `šŸ’« This space bot was made by Hri7566.\nšŸš€ This bot is made possible by users like you. Thank you.\nšŸŒŒ Discord: @hri7566`; } ); diff --git a/src/commands/commands/general/help.ts b/src/commands/commands/general/help.ts index 81ae79c..59f3df1 100644 --- a/src/commands/commands/general/help.ts +++ b/src/commands/commands/general/help.ts @@ -7,7 +7,7 @@ export const help = new Command( ["help", "h", "commands", "cmds"], "get help bozo", "help [command]", - (msg, agent) => { + msg => { if (msg.argv[1]) { // Get command usage let command: Command | undefined; diff --git a/src/commands/commands/utility/color.ts b/src/commands/commands/utility/color.ts index a6dcdf2..8e1c23b 100644 --- a/src/commands/commands/utility/color.ts +++ b/src/commands/commands/utility/color.ts @@ -1,4 +1,3 @@ -import { MPPAgent } from "../../../services/mpp"; import { CosmicColor } from "../../../util/CosmicColor"; import { Command } from "../../Command"; @@ -7,7 +6,7 @@ export const color = new Command( ["color"], "colors, bozo", "color [ | ]", - (msg, agent) => { + msg => { if (msg.argv[3]) { // test for rgb try { diff --git a/src/commands/commands/utility/cursor.ts b/src/commands/commands/utility/cursor.ts index 35a2bad..6cf3b0d 100644 --- a/src/commands/commands/utility/cursor.ts +++ b/src/commands/commands/utility/cursor.ts @@ -1,4 +1,4 @@ -import { MPPAgent } from "../../../services/mpp"; +import type { MPPAgent } from "../../../services/mpp"; import { Command } from "../../Command"; export const cursor = new Command( @@ -7,7 +7,7 @@ export const cursor = new Command( "set the cursor bozo", "cursor ", (msg, agent) => { - if (!(agent as MPPAgent).client.isConnected) return; + if (agent.platform !== "mpp") return; if (!msg.argv[1]) return "Specify a mode."; const cursor = (agent as MPPAgent).cursor; diff --git a/src/commands/commands/utility/math.ts b/src/commands/commands/utility/math.ts index 91c70ad..8f8749b 100644 --- a/src/commands/commands/utility/math.ts +++ b/src/commands/commands/utility/math.ts @@ -6,7 +6,7 @@ export const math = new Command( ["math"], "math bozo", "math ", - (msg, agent) => { + msg => { try { const argcat = msg.argv.slice(1, msg.argv.length).join(" "); const answer = evaluate(argcat); diff --git a/src/commands/commands/utility/memory.ts b/src/commands/commands/utility/memory.ts index 444e30c..661e2fe 100644 --- a/src/commands/commands/utility/memory.ts +++ b/src/commands/commands/utility/memory.ts @@ -5,7 +5,7 @@ export const memory = new Command( ["memory", "mem"], "get the memory bozo", "memory", - (msg, agent) => { + () => { return `${(process.memoryUsage().heapUsed / 1000 / 1000).toFixed( 2 )} MB used / ${(process.memoryUsage().heapTotal / 1000 / 1000).toFixed( diff --git a/src/commands/commands/utility/role.ts b/src/commands/commands/utility/role.ts index 23da6a4..c1c0803 100644 --- a/src/commands/commands/utility/role.ts +++ b/src/commands/commands/utility/role.ts @@ -6,7 +6,7 @@ export const role = new Command( ["role"], "get your role bozo", "role", - (msg, agent) => { + msg => { const role = getRole(msg.user.role); if (!role) return `Your role: ${msg.user.role} (this role is broken)`; return `Your role: ${role.displayName} [${msg.user.role}]`; diff --git a/src/commands/commands/utility/uptime.ts b/src/commands/commands/utility/uptime.ts index 8a58867..01a6aa9 100644 --- a/src/commands/commands/utility/uptime.ts +++ b/src/commands/commands/utility/uptime.ts @@ -1,4 +1,3 @@ -import { MicroHandler } from "../../../services/console/MicroHandler"; import { padNum } from "../../../util/Logger"; import { Command } from "../../Command"; diff --git a/src/data/inventory.ts b/src/data/inventory.ts index 0996388..89cc9a7 100644 --- a/src/data/inventory.ts +++ b/src/data/inventory.ts @@ -1,4 +1,4 @@ -import { Inventory, Prisma, User } from "@prisma/client"; +import { Inventory } from "@prisma/client"; import { prisma } from "./prisma"; export async function createInventory(data: Omit) { diff --git a/src/data/user.ts b/src/data/user.ts index 959ee30..9a95a72 100644 --- a/src/data/user.ts +++ b/src/data/user.ts @@ -1,4 +1,4 @@ -import { Prisma, User } from "@prisma/client"; +import { User } from "@prisma/client"; import { prisma } from "./prisma"; export async function createUser(data: User) { diff --git a/src/economy/Balance.ts b/src/economy/Balance.ts index 2588dd9..17cb6cb 100644 --- a/src/economy/Balance.ts +++ b/src/economy/Balance.ts @@ -1,16 +1,17 @@ import { loadConfig } from "../util/config"; -const config = loadConfig("config/balance.yml", { +export const balanceConfig = loadConfig("config/balance.yml", { symbol: " star bits", after: true, - cutoff: 0 + cutoff: 0, + defaultBalance: 0 }); export function formatBalance( balance: number, - symbol: string = config.symbol, - after: boolean = config.after, - cutoff: number = config.cutoff + symbol: string = balanceConfig.symbol, + after: boolean = balanceConfig.after, + cutoff: number = balanceConfig.cutoff ) { if (after) return `${balance.toFixed(cutoff)}${symbol}`; else return `${symbol}${balance.toFixed(cutoff)}`; diff --git a/src/services/console/index.ts b/src/services/console/index.ts index 2138fe1..d7492f5 100644 --- a/src/services/console/index.ts +++ b/src/services/console/index.ts @@ -2,16 +2,11 @@ import { BaseCommandMessage, CommandHandler } from "../../commands/CommandHandler"; -import { loadConfig } from "../../util/config"; import { ServiceAgent } from "../ServiceAgent"; import readline from "readline"; import { MicroHandler } from "./MicroHandler"; import { Logger } from "../../util/Logger"; -const config = loadConfig("config/switchchat.yml", { - ownerOnly: false -}); - export class ConsoleAgent extends ServiceAgent { public desiredUser = { name: "šŸŸ‡ š™Žš™Ŗš™„š™šš™§ Cosmic", diff --git a/src/services/index.ts b/src/services/index.ts index 34ed145..c3348c6 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,9 +1,7 @@ -import EventEmitter from "events"; import { MPPAgent } from "./mpp"; import env from "../util/env"; import { ServiceAgent } from "./ServiceAgent"; import { loadConfig } from "../util/config"; -import { z } from "zod"; import { SwitchChatAgent } from "./switchchat"; import { ConsoleAgent } from "./console"; diff --git a/src/services/switchchat/index.ts b/src/services/switchchat/index.ts index 81c1f33..9ae8244 100644 --- a/src/services/switchchat/index.ts +++ b/src/services/switchchat/index.ts @@ -1,7 +1,6 @@ import { BaseCommandMessage, - CommandHandler, - CommandMessage + CommandHandler } from "../../commands/CommandHandler"; import { loadConfig } from "../../util/config"; import { ServiceAgent } from "../ServiceAgent"; diff --git a/src/util/config.ts b/src/util/config.ts index f42a0bf..cec86d5 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -1,6 +1,5 @@ import { existsSync, readFileSync, writeFileSync } from "fs"; import { parse, stringify } from "yaml"; -import { z } from "zod"; /** * Load a YAML config file and set default values if config path is nonexistent