Fix long messages and stop autofishing after five minutes

This commit is contained in:
Hri7566 2024-02-24 13:11:11 -05:00
parent 98a1f70307
commit 4073a87f4e
4 changed files with 45 additions and 20 deletions

View File

@ -16,7 +16,7 @@ export const nearby = new Command(
let loc = locations.find(loc => loc.id == inventory.location);
if (!loc) loc = locations[0];
logger.debug(loc.nearby);
// logger.debug(loc.nearby);
const nearbyList: string[] = [];

View File

@ -43,7 +43,12 @@ export async function tick() {
const r = Math.random();
if (r < 0.1) {
stopFishing(winner.id, winner.userID, winner.autofish);
stopFishing(
winner.id,
winner.userID,
winner.autofish,
winner.autofish_t
);
const animal = randomFish(inventory.location);
addItem(inventory.fishSack as TFishSack, animal);
await updateInventory(inventory);
@ -91,28 +96,42 @@ export function startFishing(
id: string,
userId: string,
isDM: boolean = false,
autofish: boolean = false
autofish: boolean = false,
autofish_t: number = Date.now()
) {
fishers[id + "~" + userId] = {
id,
userID: userId,
t: Date.now(),
isDM,
autofish
autofish,
autofish_t
};
}
export function stopFishing(
id: string,
userId: string,
autofish: boolean = false
autofish: boolean = false,
autofish_t: number = Date.now()
) {
let key = id + "~" + userId;
let fisher = fishers[key];
delete fishers[key];
const t = Date.now();
if (t > autofish_t + 5 * 60000) {
addBack(fisher.id, {
m: "sendchat",
message: `Friend @${fisher.userID}'s AUTOFISH has sibsided after 5.0 minutes.`,
isDM: fisher.isDM,
id: fisher.userID
});
return;
}
if (autofish) {
startFishing(id, userId, true, true);
startFishing(id, userId, true, true, autofish_t);
}
}

View File

@ -192,20 +192,25 @@ export class MPPNetBot {
let lines = text.split("\n");
for (const line of lines) {
if (line.length <= 510) {
(this.client as any).sendArray([
{
m: "a",
message: `\u034f${line
.split("\t")
.join("")
.split("\r")
.join("")}`,
reply_to: reply
}
]);
} else {
this.sendChat(line);
const splits = line.match(/.{510}|.{1,509}/gi);
if (!splits) continue;
for (const split of splits) {
if (split.length <= 510) {
(this.client as any).sendArray([
{
m: "a",
message: `\u034f${split
.split("\t")
.join("")
.split("\r")
.join("")}`,
reply_to: reply
}
]);
} else {
this.sendChat(split);
}
}
}
}

1
src/util/types.d.ts vendored
View File

@ -107,6 +107,7 @@ interface TFisher {
t: number;
isDM: boolean;
autofish: boolean;
autofish_t: number;
}
type TPokedex = IPokemon[];