Cleanup 1
This commit is contained in:
parent
59edf1601c
commit
58706b4eb8
|
@ -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);
|
||||
|
|
|
@ -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)}`;
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -30,7 +30,7 @@ export const magic8ball = new Command(
|
|||
["magic8ball", "8ball", "8"],
|
||||
"magic8ball bozo",
|
||||
"magic8ball <question>",
|
||||
(msg, agent) => {
|
||||
msg => {
|
||||
/**
|
||||
* Magic 8 ball command
|
||||
*
|
||||
|
|
|
@ -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`;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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}]`;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { MicroHandler } from "../../../services/console/MicroHandler";
|
||||
import { padNum } from "../../../util/Logger";
|
||||
import { Command } from "../../Command";
|
||||
|
||||
|
|
|
@ -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">) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)}`;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
BaseCommandMessage,
|
||||
CommandHandler,
|
||||
CommandMessage
|
||||
CommandHandler
|
||||
} from "../../commands/CommandHandler";
|
||||
import { loadConfig } from "../../util/config";
|
||||
import { ServiceAgent } from "../ServiceAgent";
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue