Cleanup 1

This commit is contained in:
Hri7566 2023-12-02 17:21:01 -05:00
parent 59edf1601c
commit 58706b4eb8
19 changed files with 68 additions and 78 deletions

View File

@ -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<T = unknown> {
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);

View File

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

View File

@ -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(

View File

@ -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 <question>",
(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}`;
}
);

View File

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

View File

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

View File

@ -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 [<r> <g> <b> | <hex>]",
(msg, agent) => {
msg => {
if (msg.argv[3]) {
// test for rgb
try {

View File

@ -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 <mode>",
(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;

View File

@ -6,7 +6,7 @@ export const math = new Command(
["math"],
"math bozo",
"math <expression>",
(msg, agent) => {
msg => {
try {
const argcat = msg.argv.slice(1, msg.argv.length).join(" ");
const answer = evaluate(argcat);

View File

@ -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(

View File

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

View File

@ -1,4 +1,3 @@
import { MicroHandler } from "../../../services/console/MicroHandler";
import { padNum } from "../../../util/Logger";
import { Command } from "../../Command";

View File

@ -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<Inventory, "id">) {

View File

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

View File

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

View File

@ -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<readline.ReadLine> {
public desiredUser = {
name: "🟇 𝙎𝙪𝙥𝙚𝙧 Cosmic",

View File

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

View File

@ -1,7 +1,6 @@
import {
BaseCommandMessage,
CommandHandler,
CommandMessage
CommandHandler
} from "../../commands/CommandHandler";
import { loadConfig } from "../../util/config";
import { ServiceAgent } from "../ServiceAgent";

View File

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