diff --git a/src/api/commands/groups/fishing/look.ts b/src/api/commands/groups/fishing/look.ts index 1aa7fcd..20014de 100644 --- a/src/api/commands/groups/fishing/look.ts +++ b/src/api/commands/groups/fishing/look.ts @@ -1,6 +1,5 @@ import Command from "@server/commands/Command"; -import { logger } from "@server/commands/handler"; -import { getInventory, updateInventory } from "@server/data/inventory"; +import { getInventory } from "@server/data/inventory"; import { locations } from "@server/fish/locations"; export const look = new Command( diff --git a/src/api/commands/groups/fishing/nearby.ts b/src/api/commands/groups/fishing/nearby.ts index f0a5cb1..58abd59 100644 --- a/src/api/commands/groups/fishing/nearby.ts +++ b/src/api/commands/groups/fishing/nearby.ts @@ -1,6 +1,5 @@ import Command from "@server/commands/Command"; -import { logger } from "@server/commands/handler"; -import { getInventory, updateInventory } from "@server/data/inventory"; +import { getInventory } from "@server/data/inventory"; import { locations } from "@server/fish/locations"; export const nearby = new Command( diff --git a/src/api/commands/groups/fishing/reel.ts b/src/api/commands/groups/fishing/reel.ts index 63f7743..a1a443f 100644 --- a/src/api/commands/groups/fishing/reel.ts +++ b/src/api/commands/groups/fishing/reel.ts @@ -1,13 +1,11 @@ import Command from "@server/commands/Command"; -import { getInventory } from "@server/data/inventory"; import { getFishing, stopFishing } from "@server/fish/fishers"; -import { locations } from "@server/fish/locations"; export const reel = new Command( "reel", ["reel", "rool", "stopfishing", "stopfoshing"], "Reel in and stop fishing", - "fishing", + "reel", "command.fishing.reel", async ({ id, command, args, prefix, part, user }) => { const fishing = getFishing(id, part.id); diff --git a/src/api/commands/groups/general/color.ts b/src/api/commands/groups/general/color.ts index 24e659a..5998535 100644 --- a/src/api/commands/groups/general/color.ts +++ b/src/api/commands/groups/general/color.ts @@ -1,24 +1,22 @@ import Command from "@server/commands/Command"; -import { commandGroups } from ".."; -import { logger } from "@server/commands/handler"; import { CosmicColor } from "@util/CosmicColor"; export const color = new Command( "color", ["color"], "Get the name of a color", - "color", + "color [hex color]", "command.general.color", async ({ id, command, args, prefix, part, user }) => { let color = args[0]; - let out1 = `Friend ${part.name}: That color is`; + let out = `Friend ${part.name}: That color is`; if (!color) { color = part.color; - out1 = `Friend ${part.name}, your color is`; + out = `Friend ${part.name}, your color is`; } const c = new CosmicColor(color); - return `${out1} ${c.getName().toLowerCase()}.`; + return `${out} ${c.getName().toLowerCase()}.`; } ); diff --git a/src/api/commands/groups/general/help.ts b/src/api/commands/groups/general/help.ts index 866d687..d1d1824 100644 --- a/src/api/commands/groups/general/help.ts +++ b/src/api/commands/groups/general/help.ts @@ -1,6 +1,5 @@ import Command from "@server/commands/Command"; import { commandGroups } from ".."; -import { logger } from "@server/commands/handler"; export const help = new Command( "help", diff --git a/src/api/commands/groups/general/myid.ts b/src/api/commands/groups/general/myid.ts new file mode 100644 index 0000000..e610515 --- /dev/null +++ b/src/api/commands/groups/general/myid.ts @@ -0,0 +1,13 @@ +import Command from "@server/commands/Command"; + +export const myid = new Command( + "myid", + ["myid"], + "Get your own ID", + "myid", + "command.general.myid", + async ({ id, command, args, prefix, part, user }) => { + return `Your ID: \`${part.id}\``; + }, + false +); diff --git a/src/api/commands/groups/index.ts b/src/api/commands/groups/index.ts index 5aac5b6..08bc978 100644 --- a/src/api/commands/groups/index.ts +++ b/src/api/commands/groups/index.ts @@ -17,6 +17,7 @@ import { pokemon } from "./inventory/pokemon"; import { color } from "./general/color"; import { autofish } from "./util/autofish"; import { pokedex } from "./util/pokedex"; +import { myid } from "./general/myid"; interface ICommandGroup { id: string; @@ -29,7 +30,7 @@ export const commandGroups: ICommandGroup[] = []; const generalGroup: ICommandGroup = { id: "general", displayName: "General", - commands: [help, color] + commands: [help, color, myid] }; commandGroups.push(generalGroup); diff --git a/src/api/commands/groups/inventory/eat.ts b/src/api/commands/groups/inventory/eat.ts index 1cb2b14..67e5b3e 100644 --- a/src/api/commands/groups/inventory/eat.ts +++ b/src/api/commands/groups/inventory/eat.ts @@ -1,6 +1,5 @@ import { addBack } from "@server/backs"; import Command from "@server/commands/Command"; -import { logger } from "@server/commands/handler"; import { getInventory, updateInventory } from "@server/data/inventory"; import { CosmicColor } from "@util/CosmicColor"; diff --git a/src/api/commands/groups/inventory/sack.ts b/src/api/commands/groups/inventory/sack.ts index fc6a3db..3440c6b 100644 --- a/src/api/commands/groups/inventory/sack.ts +++ b/src/api/commands/groups/inventory/sack.ts @@ -7,12 +7,12 @@ export const sack = new Command( "sack", ["sack", "caught"], "Look at your fish sack", - "sack", + "sack [user ID]", "command.inventory.sack", async ({ id, command, args, prefix, part, user }) => { if (args[0]) { - let decidedUser: User = user; - decidedUser = (await prisma.user.findFirst({ + let foundUser: User = user; + foundUser = (await prisma.user.findFirst({ where: { name: { contains: args[0] @@ -20,8 +20,8 @@ export const sack = new Command( } })) as User; - if (!decidedUser) - decidedUser = (await prisma.user.findFirst({ + if (!foundUser) + foundUser = (await prisma.user.findFirst({ where: { id: { contains: args[0] @@ -29,15 +29,15 @@ export const sack = new Command( } })) as User; - if (!decidedUser) return `User "${args[0]}" not found.`; + if (!foundUser) return `User "${args[0]}" not found.`; - const inv = await getInventory(decidedUser.inventoryId); + const inv = await getInventory(foundUser.inventoryId); if (!inv) - return `This message should be impossible to see because friend ${decidedUser.name}'s fish sack (and, by extension, their entire inventory) does not exist.`; + return `This message should be impossible to see because friend ${foundUser.name}'s fish sack (and, by extension, their entire inventory) does not exist.`; const fishSack = inv.fishSack as TFishSack; - return `Contents of ${decidedUser.name}'s fish sack: ${ + return `Contents of ${foundUser.name}'s fish sack: ${ fishSack .map( (fish: IFish) => diff --git a/src/api/commands/groups/inventory/take.ts b/src/api/commands/groups/inventory/take.ts index 916e4be..3695460 100644 --- a/src/api/commands/groups/inventory/take.ts +++ b/src/api/commands/groups/inventory/take.ts @@ -1,5 +1,4 @@ import Command from "@server/commands/Command"; -import { logger } from "@server/commands/handler"; import { getInventory, updateInventory } from "@server/data/inventory"; import { locations, saveObjects } from "@server/fish/locations"; import { go } from "../fishing/go"; diff --git a/src/api/commands/groups/util/autofish.ts b/src/api/commands/groups/util/autofish.ts index 119853c..f2e75df 100644 --- a/src/api/commands/groups/util/autofish.ts +++ b/src/api/commands/groups/util/autofish.ts @@ -1,5 +1,4 @@ import Command from "@server/commands/Command"; -import { prefixes } from "@server/commands/prefixes"; import { getFishing, startFishing } from "@server/fish/fishers"; import { reel } from "../fishing/reel"; diff --git a/src/api/fish/fishers.ts b/src/api/fish/fishers.ts index 73c274d..6e6c747 100644 --- a/src/api/fish/fishers.ts +++ b/src/api/fish/fishers.ts @@ -94,14 +94,14 @@ export function stopFisherTick() { export function startFishing( id: string, - userId: string, + userID: string, isDM: boolean = false, autofish: boolean = false, autofish_t: number = Date.now() ) { - fishers[id + "~" + userId] = { + fishers[id + "~" + userID] = { id, - userID: userId, + userID, t: Date.now(), isDM, autofish, @@ -111,11 +111,11 @@ export function startFishing( export function stopFishing( id: string, - userId: string, + userID: string, autofish: boolean = false, autofish_t: number = Date.now() ) { - let key = id + "~" + userId; + let key = id + "~" + userID; let fisher = fishers[key]; delete fishers[key]; @@ -131,10 +131,10 @@ export function stopFishing( } if (autofish) { - startFishing(id, userId, true, true, autofish_t); + startFishing(id, userID, true, true, autofish_t); } } -export function getFishing(id: string, userId: string) { - return fishers[id + "~" + userId]; +export function getFishing(id: string, userID: string) { + return fishers[id + "~" + userID]; } diff --git a/src/cli/index.ts b/src/cli/index.ts index 8019018..d6bfe8a 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -14,6 +14,12 @@ const rl = createInterface({ output: process.stdout }); +const user = { + _id: "stdin", + name: "CLI", + color: "#abe3d6" +}; + (globalThis as unknown as any).rl = rl; rl.setPrompt("> "); rl.prompt(); @@ -24,11 +30,7 @@ rl.on("line", async line => { const msg = { a: line, - p: { - _id: "stdin", - name: "CLI", - color: "#abe3d6" - } + p: user }; let prefixes: string[]; @@ -65,3 +67,27 @@ rl.on("line", async line => { logger.info(cliMd(command.response)); } }); + +setInterval(async () => { + try { + const backs = (await trpc.backs.query()) as IBack[]; + if (backs.length > 0) { + // this.logger.debug(backs); + for (const back of backs) { + if (typeof back.m !== "string") return; + b.emit(back.m, back); + } + } + } catch (err) { + return; + } +}, 1000 / 20); + +b.on("color", msg => { + if (typeof msg.color !== "string" || typeof msg.id !== "string") return; + user.color = msg.color; +}); + +b.on("sendchat", msg => { + logger.info(cliMd(msg.message)); +}); diff --git a/src/util/types.d.ts b/src/util/types.d.ts index d1109d0..c977973 100644 --- a/src/util/types.d.ts +++ b/src/util/types.d.ts @@ -111,3 +111,15 @@ interface TFisher { } type TPokedex = IPokemon[]; + +type TBehavior = () => Promise; +type TBehaviorMap = Record; + +interface IItemBehaviorData { + status: boolean; + text: string; + userID: string; +} + +type TItemBehavior = Behavior; +type TItemBehaviorMap = TBehaviorMap;