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 Command from "@server/commands/Command";
|
||||||
import { logger } from "@server/commands/handler";
|
import { getInventory } from "@server/data/inventory";
|
||||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
|
||||||
import { locations } from "@server/fish/locations";
|
import { locations } from "@server/fish/locations";
|
||||||
|
|
||||||
export const look = new Command(
|
export const look = new Command(
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { logger } from "@server/commands/handler";
|
import { getInventory } from "@server/data/inventory";
|
||||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
|
||||||
import { locations } from "@server/fish/locations";
|
import { locations } from "@server/fish/locations";
|
||||||
|
|
||||||
export const nearby = new Command(
|
export const nearby = new Command(
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { getInventory } from "@server/data/inventory";
|
|
||||||
import { getFishing, stopFishing } from "@server/fish/fishers";
|
import { getFishing, stopFishing } from "@server/fish/fishers";
|
||||||
import { locations } from "@server/fish/locations";
|
|
||||||
|
|
||||||
export const reel = new Command(
|
export const reel = new Command(
|
||||||
"reel",
|
"reel",
|
||||||
["reel", "rool", "stopfishing", "stopfoshing"],
|
["reel", "rool", "stopfishing", "stopfoshing"],
|
||||||
"Reel in and stop fishing",
|
"Reel in and stop fishing",
|
||||||
"fishing",
|
"reel",
|
||||||
"command.fishing.reel",
|
"command.fishing.reel",
|
||||||
async ({ id, command, args, prefix, part, user }) => {
|
async ({ id, command, args, prefix, part, user }) => {
|
||||||
const fishing = getFishing(id, part.id);
|
const fishing = getFishing(id, part.id);
|
||||||
|
|
|
@ -1,24 +1,22 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { commandGroups } from "..";
|
|
||||||
import { logger } from "@server/commands/handler";
|
|
||||||
import { CosmicColor } from "@util/CosmicColor";
|
import { CosmicColor } from "@util/CosmicColor";
|
||||||
|
|
||||||
export const color = new Command(
|
export const color = new Command(
|
||||||
"color",
|
"color",
|
||||||
["color"],
|
["color"],
|
||||||
"Get the name of a color",
|
"Get the name of a color",
|
||||||
"color",
|
"color [hex color]",
|
||||||
"command.general.color",
|
"command.general.color",
|
||||||
async ({ id, command, args, prefix, part, user }) => {
|
async ({ id, command, args, prefix, part, user }) => {
|
||||||
let color = args[0];
|
let color = args[0];
|
||||||
let out1 = `Friend ${part.name}: That color is`;
|
let out = `Friend ${part.name}: That color is`;
|
||||||
|
|
||||||
if (!color) {
|
if (!color) {
|
||||||
color = part.color;
|
color = part.color;
|
||||||
out1 = `Friend ${part.name}, your color is`;
|
out = `Friend ${part.name}, your color is`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const c = new CosmicColor(color);
|
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 Command from "@server/commands/Command";
|
||||||
import { commandGroups } from "..";
|
import { commandGroups } from "..";
|
||||||
import { logger } from "@server/commands/handler";
|
|
||||||
|
|
||||||
export const help = new Command(
|
export const help = new Command(
|
||||||
"help",
|
"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 { color } from "./general/color";
|
||||||
import { autofish } from "./util/autofish";
|
import { autofish } from "./util/autofish";
|
||||||
import { pokedex } from "./util/pokedex";
|
import { pokedex } from "./util/pokedex";
|
||||||
|
import { myid } from "./general/myid";
|
||||||
|
|
||||||
interface ICommandGroup {
|
interface ICommandGroup {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -29,7 +30,7 @@ export const commandGroups: ICommandGroup[] = [];
|
||||||
const generalGroup: ICommandGroup = {
|
const generalGroup: ICommandGroup = {
|
||||||
id: "general",
|
id: "general",
|
||||||
displayName: "General",
|
displayName: "General",
|
||||||
commands: [help, color]
|
commands: [help, color, myid]
|
||||||
};
|
};
|
||||||
|
|
||||||
commandGroups.push(generalGroup);
|
commandGroups.push(generalGroup);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { addBack } from "@server/backs";
|
import { addBack } from "@server/backs";
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { logger } from "@server/commands/handler";
|
|
||||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||||
import { CosmicColor } from "@util/CosmicColor";
|
import { CosmicColor } from "@util/CosmicColor";
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ export const sack = new Command(
|
||||||
"sack",
|
"sack",
|
||||||
["sack", "caught"],
|
["sack", "caught"],
|
||||||
"Look at your fish sack",
|
"Look at your fish sack",
|
||||||
"sack",
|
"sack [user ID]",
|
||||||
"command.inventory.sack",
|
"command.inventory.sack",
|
||||||
async ({ id, command, args, prefix, part, user }) => {
|
async ({ id, command, args, prefix, part, user }) => {
|
||||||
if (args[0]) {
|
if (args[0]) {
|
||||||
let decidedUser: User = user;
|
let foundUser: User = user;
|
||||||
decidedUser = (await prisma.user.findFirst({
|
foundUser = (await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
name: {
|
name: {
|
||||||
contains: args[0]
|
contains: args[0]
|
||||||
|
@ -20,8 +20,8 @@ export const sack = new Command(
|
||||||
}
|
}
|
||||||
})) as User;
|
})) as User;
|
||||||
|
|
||||||
if (!decidedUser)
|
if (!foundUser)
|
||||||
decidedUser = (await prisma.user.findFirst({
|
foundUser = (await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: {
|
id: {
|
||||||
contains: args[0]
|
contains: args[0]
|
||||||
|
@ -29,15 +29,15 @@ export const sack = new Command(
|
||||||
}
|
}
|
||||||
})) as User;
|
})) 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)
|
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;
|
const fishSack = inv.fishSack as TFishSack;
|
||||||
|
|
||||||
return `Contents of ${decidedUser.name}'s fish sack: ${
|
return `Contents of ${foundUser.name}'s fish sack: ${
|
||||||
fishSack
|
fishSack
|
||||||
.map(
|
.map(
|
||||||
(fish: IFish) =>
|
(fish: IFish) =>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { logger } from "@server/commands/handler";
|
|
||||||
import { getInventory, updateInventory } from "@server/data/inventory";
|
import { getInventory, updateInventory } from "@server/data/inventory";
|
||||||
import { locations, saveObjects } from "@server/fish/locations";
|
import { locations, saveObjects } from "@server/fish/locations";
|
||||||
import { go } from "../fishing/go";
|
import { go } from "../fishing/go";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { prefixes } from "@server/commands/prefixes";
|
|
||||||
import { getFishing, startFishing } from "@server/fish/fishers";
|
import { getFishing, startFishing } from "@server/fish/fishers";
|
||||||
import { reel } from "../fishing/reel";
|
import { reel } from "../fishing/reel";
|
||||||
|
|
||||||
|
|
|
@ -94,14 +94,14 @@ export function stopFisherTick() {
|
||||||
|
|
||||||
export function startFishing(
|
export function startFishing(
|
||||||
id: string,
|
id: string,
|
||||||
userId: string,
|
userID: string,
|
||||||
isDM: boolean = false,
|
isDM: boolean = false,
|
||||||
autofish: boolean = false,
|
autofish: boolean = false,
|
||||||
autofish_t: number = Date.now()
|
autofish_t: number = Date.now()
|
||||||
) {
|
) {
|
||||||
fishers[id + "~" + userId] = {
|
fishers[id + "~" + userID] = {
|
||||||
id,
|
id,
|
||||||
userID: userId,
|
userID,
|
||||||
t: Date.now(),
|
t: Date.now(),
|
||||||
isDM,
|
isDM,
|
||||||
autofish,
|
autofish,
|
||||||
|
@ -111,11 +111,11 @@ export function startFishing(
|
||||||
|
|
||||||
export function stopFishing(
|
export function stopFishing(
|
||||||
id: string,
|
id: string,
|
||||||
userId: string,
|
userID: string,
|
||||||
autofish: boolean = false,
|
autofish: boolean = false,
|
||||||
autofish_t: number = Date.now()
|
autofish_t: number = Date.now()
|
||||||
) {
|
) {
|
||||||
let key = id + "~" + userId;
|
let key = id + "~" + userID;
|
||||||
let fisher = fishers[key];
|
let fisher = fishers[key];
|
||||||
delete fishers[key];
|
delete fishers[key];
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ export function stopFishing(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autofish) {
|
if (autofish) {
|
||||||
startFishing(id, userId, true, true, autofish_t);
|
startFishing(id, userID, true, true, autofish_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFishing(id: string, userId: string) {
|
export function getFishing(id: string, userID: string) {
|
||||||
return fishers[id + "~" + userId];
|
return fishers[id + "~" + userID];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,12 @@ const rl = createInterface({
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user = {
|
||||||
|
_id: "stdin",
|
||||||
|
name: "CLI",
|
||||||
|
color: "#abe3d6"
|
||||||
|
};
|
||||||
|
|
||||||
(globalThis as unknown as any).rl = rl;
|
(globalThis as unknown as any).rl = rl;
|
||||||
rl.setPrompt("> ");
|
rl.setPrompt("> ");
|
||||||
rl.prompt();
|
rl.prompt();
|
||||||
|
@ -24,11 +30,7 @@ rl.on("line", async line => {
|
||||||
|
|
||||||
const msg = {
|
const msg = {
|
||||||
a: line,
|
a: line,
|
||||||
p: {
|
p: user
|
||||||
_id: "stdin",
|
|
||||||
name: "CLI",
|
|
||||||
color: "#abe3d6"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let prefixes: string[];
|
let prefixes: string[];
|
||||||
|
@ -65,3 +67,27 @@ rl.on("line", async line => {
|
||||||
logger.info(cliMd(command.response));
|
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 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