Add myid command and fix command usage and various module imports
This commit is contained in:
parent
677a1a958a
commit
ab034384bb
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()}.`;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
);
|
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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) =>
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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<unknown>[];
|
||||
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));
|
||||
});
|
||||
|
|
|
@ -111,3 +111,15 @@ interface TFisher {
|
|||
}
|
||||
|
||||
type TPokedex = IPokemon[];
|
||||
|
||||
type TBehavior<T> = () => Promise<T>;
|
||||
type TBehaviorMap<T> = Record<T, TBehavior>;
|
||||
|
||||
interface IItemBehaviorData {
|
||||
status: boolean;
|
||||
text: string;
|
||||
userID: string;
|
||||
}
|
||||
|
||||
type TItemBehavior = Behavior<IItemBehaviorData>;
|
||||
type TItemBehaviorMap = TBehaviorMap<TItemBehavior>;
|
||||
|
|
Loading…
Reference in New Issue