Compare commits

..

No commits in common. "f6892a691a824cb5b9eb1bb3150677af79561fd6" and "2d8217cea73d0631886b32cbf2b7805da8ab3d90" have entirely different histories.

11 changed files with 23 additions and 73 deletions

View File

@ -15,7 +15,7 @@ interface FishingContext {
token: string | null;
}
interface PrivateFishingContext extends FishingContext {
interface AuthedFishingContext extends FishingContext {
token: string;
}
@ -43,7 +43,7 @@ export const privateProcedure = publicProcedure.use(async opts => {
if (!ctx.isAuthed) throw new TRPCError({ code: "UNAUTHORIZED" });
return opts.next({
ctx: opts.ctx as PrivateFishingContext
ctx: opts.ctx as AuthedFishingContext
});
});
@ -55,7 +55,6 @@ export const appRouter = router({
command: privateProcedure
.input(
z.object({
channel: z.string(),
command: z.string(),
prefix: z.string(),
args: z.array(z.string()),
@ -69,10 +68,9 @@ export const appRouter = router({
)
.query(async opts => {
const id = tokenToID(opts.ctx.token);
const { channel, command, args, prefix, user, isDM } = opts.input;
const { command, args, prefix, user, isDM } = opts.input;
const out = await handleCommand(
id,
channel,
command,
args,
prefix,

View File

@ -7,11 +7,11 @@ export const fish = new Command(
"Send your LURE into a water for catching fish",
"fish",
"command.fishing.fish",
async ({ id, channel, command, args, prefix, part, user, isDM }) => {
async ({ id, command, args, prefix, part, user, isDM }) => {
const fishing = getFishing(id, part.id);
if (!fishing) {
startFishing(id, part.id, channel, isDM);
startFishing(id, part.id, isDM);
return `Our friend ${part.name} casts LURE into a water for catching fish.`;
} else {
return `Your lure is already in the water (since ${(

View File

@ -21,7 +21,6 @@ import { myid } from "./general/myid";
import { yeet } from "./inventory/yeet";
import { tree } from "./fishing/tree";
import { pick } from "./fishing/pick";
import { fid } from "./util/fid";
// import { give } from "./inventory/give";
interface ICommandGroup {
@ -59,7 +58,7 @@ commandGroups.push(inventoryGroup);
const utilGroup: ICommandGroup = {
id: "util",
displayName: "Utility",
commands: [data, setcolor, memory, autofish, pokedex, fid]
commands: [data, setcolor, memory, autofish, pokedex]
};
commandGroups.push(utilGroup);

View File

@ -1,13 +0,0 @@
import Command from "@server/commands/Command";
export const fid = new Command(
"fid",
["fid"],
"Get internal ID",
"fid",
"command.util.fid",
async props => {
return props.id;
},
false
);

View File

@ -10,7 +10,6 @@ export const logger = new Logger("Command Handler");
export async function handleCommand(
id: string,
channel: string,
command: string,
args: string[],
prefix: string,
@ -63,7 +62,6 @@ export async function handleCommand(
try {
const response = await foundCommand.callback({
id,
channel,
command,
args,
prefix,

View File

@ -29,14 +29,14 @@ export async function tick() {
const user = await getUser(winner.userID);
if (!user) {
stopFishing(winner.id, winner.userID, winner.channel, false);
stopFishing(winner.id, winner.userID, false);
return;
}
const inventory = await getInventory(user.inventoryId);
if (!inventory) {
stopFishing(winner.id, winner.userID, winner.channel, false);
stopFishing(winner.id, winner.userID, false);
return;
}
@ -49,7 +49,6 @@ export async function tick() {
stopFishing(
winner.id,
winner.userID,
winner.channel,
winner.autofish,
winner.autofish_t
);
@ -59,7 +58,6 @@ export async function tick() {
const size = getSizeString(animal.size);
addBack(winner.id, {
m: "sendchat",
channel: winner.channel,
message: `Our good friend @${user.id} caught a ${size} ${
animal.emoji || "🐟"
}${animal.name}! ready to ${prefixes[0]}eat or ${
@ -89,7 +87,6 @@ export function stopFisherTick() {
export function startFishing(
id: string,
userID: string,
channel: string,
isDM: boolean = false,
autofish: boolean = false,
autofish_t: number = Date.now()
@ -97,7 +94,6 @@ export function startFishing(
fishers[id + "~" + userID] = {
id,
userID,
channel,
t: Date.now(),
isDM,
autofish,
@ -108,7 +104,6 @@ export function startFishing(
export function stopFishing(
id: string,
userID: string,
channel: string,
autofish: boolean = false,
autofish_t: number = Date.now()
) {
@ -125,7 +120,6 @@ export function stopFishing(
1000 /
60
).toFixed(2)} minutes.`,
channel: fisher.channel,
isDM: fisher.isDM,
id: fisher.userID
});
@ -133,7 +127,7 @@ export function stopFishing(
}
if (autofish) {
startFishing(id, userID, channel, true, true, autofish_t);
startFishing(id, userID, true, true, autofish_t);
}
}

View File

@ -54,7 +54,6 @@ rl.on("line", async line => {
const args = msg.a.split(" ");
const command = await trpc.command.query({
channel: logger.id,
args: args.slice(1, args.length),
command: args[0].substring(usedPrefix.length),
prefix: usedPrefix,
@ -78,10 +77,6 @@ setInterval(async () => {
// this.logger.debug(backs);
for (const back of backs) {
if (typeof back.m !== "string") return;
if (typeof back.channel === "string") {
if (back.channel !== logger.id) return;
}
b.emit(back.m, back);
}
}

View File

@ -10,6 +10,8 @@ export interface DiscordBotConfig {
token?: string;
}
const trpc = gettRPC(process.env.DISCORD_FISHING_TOKEN as string);
export class DiscordBot extends EventEmitter {
public client: Discord.Client;
public logger = new Logger("Discord Bot");
@ -17,7 +19,6 @@ export class DiscordBot extends EventEmitter {
public server?: Discord.Guild;
public defaultChannel?: Discord.TextChannel;
public b = new EventEmitter();
public trpc = gettRPC(process.env.DISCORD_FISHING_TOKEN as string);
constructor(public conf: DiscordBotConfig) {
super();
@ -94,7 +95,7 @@ export class DiscordBot extends EventEmitter {
let prefixes: string[];
try {
prefixes = await this.trpc.prefixes.query();
prefixes = await trpc.prefixes.query();
} catch (err) {
this.logger.error(err);
this.logger.warn("Unable to contact server");
@ -109,8 +110,7 @@ export class DiscordBot extends EventEmitter {
const args = msg.content.split(" ");
const command = await this.trpc.command.query({
channel: msg.channelId,
const command = await trpc.command.query({
args: args.slice(1, args.length),
command: args[0].substring(usedPrefix.length),
prefix: usedPrefix,
@ -132,8 +132,7 @@ export class DiscordBot extends EventEmitter {
setInterval(async () => {
try {
const backs =
(await this.trpc.backs.query()) as IBack<unknown>[];
const backs = (await trpc.backs.query()) as IBack<unknown>[];
if (backs.length > 0) {
// this.logger.debug(backs);
for (const back of backs) {
@ -184,11 +183,6 @@ export class DiscordBot extends EventEmitter {
this.b.on("sendchat", msg => {
// this.logger.debug("sendchat message:", msg);
if (!this.defaultChannel) return;
if (typeof msg.channel === "string") {
if (msg.channel !== this.defaultChannel.id) return;
}
this.defaultChannel.send(
msg.message.split(`@${msg.id}`).join(`<@${msg.id}>`)
);

View File

@ -12,12 +12,12 @@ export interface MPPNetBotConfig {
};
}
const trpc = gettRPC(process.env.MPP_FISHING_TOKEN as string);
export class MPPNetBot {
public client: Client;
public b = new EventEmitter();
public logger: Logger;
public trpc = gettRPC(process.env.MPP_FISHING_TOKEN as string);
public started = false;
constructor(
public config: MPPNetBotConfig,
@ -32,14 +32,11 @@ export class MPPNetBot {
}
public start() {
this.logger.debug("Starting");
this.client.start();
this.started = true;
}
public stop() {
this.client.stop();
this.started = false;
}
public bindEventListeners() {
@ -57,7 +54,7 @@ export class MPPNetBot {
let prefixes: string[];
try {
prefixes = await this.trpc.prefixes.query();
prefixes = await trpc.prefixes.query();
} catch (err) {
this.logger.error(err);
this.logger.warn("Unable to contact server");
@ -72,8 +69,7 @@ export class MPPNetBot {
const args = msg.a.split(" ");
const command = await this.trpc.command.query({
channel: this.client.channel._id,
const command = await trpc.command.query({
args: args.slice(1, args.length),
command: args[0].substring(usedPrefix.length),
prefix: usedPrefix,
@ -124,7 +120,7 @@ export class MPPNetBot {
let prefixes: string[];
try {
prefixes = await this.trpc.prefixes.query();
prefixes = await trpc.prefixes.query();
} catch (err) {
this.logger.error(err);
this.logger.warn("Unable to contact server");
@ -139,8 +135,7 @@ export class MPPNetBot {
const args = msg.a.split(" ");
const command = await this.trpc.command.query({
channel: this.client.channel._id,
const command = await trpc.command.query({
args: args.slice(1, args.length),
command: args[0].substring(usedPrefix.length),
prefix: usedPrefix,
@ -160,8 +155,7 @@ export class MPPNetBot {
setInterval(async () => {
try {
const backs =
(await this.trpc.backs.query()) as IBack<unknown>[];
const backs = (await trpc.backs.query()) as IBack<unknown>[];
if (backs.length > 0) {
// this.logger.debug(backs);
for (const back of backs) {
@ -188,11 +182,6 @@ export class MPPNetBot {
this.b.on("sendchat", msg => {
// this.logger.debug("sendchat message:", msg);
if (typeof msg.channel === "string") {
if (msg.channel !== this.client.channel._id) return;
}
if (msg.isDM) {
this.sendDM(msg.message, msg.id);
} else {

View File

@ -1,10 +1,7 @@
import { loadConfig } from "@util/config";
import { MPPNetBot, type MPPNetBotConfig } from "./Bot";
import { Logger } from "@util/Logger";
const logger = new Logger("big brain");
const bots: MPPNetBot[] = [];
const bots = [];
const defaults = loadConfig("config/bots.yml", [
{
@ -29,4 +26,5 @@ export function initBot(conf: MPPNetBotConfig) {
}
export { MPPNetBot as Bot };
export default MPPNetBot;

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

@ -10,7 +10,6 @@ interface ICommandResponse {
interface IContextProps {
id: string;
channel: string;
command: string;
args: string[];
prefix: string;
@ -107,7 +106,6 @@ interface ILocation {
interface TFisher {
id: string;
userID: string;
channel: string;
t: number;
isDM: boolean;
autofish: boolean;