Compare commits
2 Commits
2d8217cea7
...
f6892a691a
Author | SHA1 | Date |
---|---|---|
Hri7566 | f6892a691a | |
Hri7566 | c645229cca |
|
@ -15,7 +15,7 @@ interface FishingContext {
|
||||||
token: string | null;
|
token: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AuthedFishingContext extends FishingContext {
|
interface PrivateFishingContext extends FishingContext {
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ export const privateProcedure = publicProcedure.use(async opts => {
|
||||||
if (!ctx.isAuthed) throw new TRPCError({ code: "UNAUTHORIZED" });
|
if (!ctx.isAuthed) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
|
|
||||||
return opts.next({
|
return opts.next({
|
||||||
ctx: opts.ctx as AuthedFishingContext
|
ctx: opts.ctx as PrivateFishingContext
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ export const appRouter = router({
|
||||||
command: privateProcedure
|
command: privateProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
channel: z.string(),
|
||||||
command: z.string(),
|
command: z.string(),
|
||||||
prefix: z.string(),
|
prefix: z.string(),
|
||||||
args: z.array(z.string()),
|
args: z.array(z.string()),
|
||||||
|
@ -68,9 +69,10 @@ export const appRouter = router({
|
||||||
)
|
)
|
||||||
.query(async opts => {
|
.query(async opts => {
|
||||||
const id = tokenToID(opts.ctx.token);
|
const id = tokenToID(opts.ctx.token);
|
||||||
const { command, args, prefix, user, isDM } = opts.input;
|
const { channel, command, args, prefix, user, isDM } = opts.input;
|
||||||
const out = await handleCommand(
|
const out = await handleCommand(
|
||||||
id,
|
id,
|
||||||
|
channel,
|
||||||
command,
|
command,
|
||||||
args,
|
args,
|
||||||
prefix,
|
prefix,
|
||||||
|
|
|
@ -7,11 +7,11 @@ export const fish = new Command(
|
||||||
"Send your LURE into a water for catching fish",
|
"Send your LURE into a water for catching fish",
|
||||||
"fish",
|
"fish",
|
||||||
"command.fishing.fish",
|
"command.fishing.fish",
|
||||||
async ({ id, command, args, prefix, part, user, isDM }) => {
|
async ({ id, channel, command, args, prefix, part, user, isDM }) => {
|
||||||
const fishing = getFishing(id, part.id);
|
const fishing = getFishing(id, part.id);
|
||||||
|
|
||||||
if (!fishing) {
|
if (!fishing) {
|
||||||
startFishing(id, part.id, isDM);
|
startFishing(id, part.id, channel, isDM);
|
||||||
return `Our friend ${part.name} casts LURE into a water for catching fish.`;
|
return `Our friend ${part.name} casts LURE into a water for catching fish.`;
|
||||||
} else {
|
} else {
|
||||||
return `Your lure is already in the water (since ${(
|
return `Your lure is already in the water (since ${(
|
||||||
|
|
|
@ -21,6 +21,7 @@ import { myid } from "./general/myid";
|
||||||
import { yeet } from "./inventory/yeet";
|
import { yeet } from "./inventory/yeet";
|
||||||
import { tree } from "./fishing/tree";
|
import { tree } from "./fishing/tree";
|
||||||
import { pick } from "./fishing/pick";
|
import { pick } from "./fishing/pick";
|
||||||
|
import { fid } from "./util/fid";
|
||||||
// import { give } from "./inventory/give";
|
// import { give } from "./inventory/give";
|
||||||
|
|
||||||
interface ICommandGroup {
|
interface ICommandGroup {
|
||||||
|
@ -58,7 +59,7 @@ commandGroups.push(inventoryGroup);
|
||||||
const utilGroup: ICommandGroup = {
|
const utilGroup: ICommandGroup = {
|
||||||
id: "util",
|
id: "util",
|
||||||
displayName: "Utility",
|
displayName: "Utility",
|
||||||
commands: [data, setcolor, memory, autofish, pokedex]
|
commands: [data, setcolor, memory, autofish, pokedex, fid]
|
||||||
};
|
};
|
||||||
|
|
||||||
commandGroups.push(utilGroup);
|
commandGroups.push(utilGroup);
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
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
|
||||||
|
);
|
|
@ -10,6 +10,7 @@ export const logger = new Logger("Command Handler");
|
||||||
|
|
||||||
export async function handleCommand(
|
export async function handleCommand(
|
||||||
id: string,
|
id: string,
|
||||||
|
channel: string,
|
||||||
command: string,
|
command: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
prefix: string,
|
prefix: string,
|
||||||
|
@ -62,6 +63,7 @@ export async function handleCommand(
|
||||||
try {
|
try {
|
||||||
const response = await foundCommand.callback({
|
const response = await foundCommand.callback({
|
||||||
id,
|
id,
|
||||||
|
channel,
|
||||||
command,
|
command,
|
||||||
args,
|
args,
|
||||||
prefix,
|
prefix,
|
||||||
|
|
|
@ -29,14 +29,14 @@ export async function tick() {
|
||||||
const user = await getUser(winner.userID);
|
const user = await getUser(winner.userID);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
stopFishing(winner.id, winner.userID, false);
|
stopFishing(winner.id, winner.userID, winner.channel, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inventory = await getInventory(user.inventoryId);
|
const inventory = await getInventory(user.inventoryId);
|
||||||
|
|
||||||
if (!inventory) {
|
if (!inventory) {
|
||||||
stopFishing(winner.id, winner.userID, false);
|
stopFishing(winner.id, winner.userID, winner.channel, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ export async function tick() {
|
||||||
stopFishing(
|
stopFishing(
|
||||||
winner.id,
|
winner.id,
|
||||||
winner.userID,
|
winner.userID,
|
||||||
|
winner.channel,
|
||||||
winner.autofish,
|
winner.autofish,
|
||||||
winner.autofish_t
|
winner.autofish_t
|
||||||
);
|
);
|
||||||
|
@ -58,6 +59,7 @@ export async function tick() {
|
||||||
const size = getSizeString(animal.size);
|
const size = getSizeString(animal.size);
|
||||||
addBack(winner.id, {
|
addBack(winner.id, {
|
||||||
m: "sendchat",
|
m: "sendchat",
|
||||||
|
channel: winner.channel,
|
||||||
message: `Our good friend @${user.id} caught a ${size} ${
|
message: `Our good friend @${user.id} caught a ${size} ${
|
||||||
animal.emoji || "🐟"
|
animal.emoji || "🐟"
|
||||||
}${animal.name}! ready to ${prefixes[0]}eat or ${
|
}${animal.name}! ready to ${prefixes[0]}eat or ${
|
||||||
|
@ -87,6 +89,7 @@ export function stopFisherTick() {
|
||||||
export function startFishing(
|
export function startFishing(
|
||||||
id: string,
|
id: string,
|
||||||
userID: string,
|
userID: string,
|
||||||
|
channel: string,
|
||||||
isDM: boolean = false,
|
isDM: boolean = false,
|
||||||
autofish: boolean = false,
|
autofish: boolean = false,
|
||||||
autofish_t: number = Date.now()
|
autofish_t: number = Date.now()
|
||||||
|
@ -94,6 +97,7 @@ export function startFishing(
|
||||||
fishers[id + "~" + userID] = {
|
fishers[id + "~" + userID] = {
|
||||||
id,
|
id,
|
||||||
userID,
|
userID,
|
||||||
|
channel,
|
||||||
t: Date.now(),
|
t: Date.now(),
|
||||||
isDM,
|
isDM,
|
||||||
autofish,
|
autofish,
|
||||||
|
@ -104,6 +108,7 @@ export function startFishing(
|
||||||
export function stopFishing(
|
export function stopFishing(
|
||||||
id: string,
|
id: string,
|
||||||
userID: string,
|
userID: string,
|
||||||
|
channel: string,
|
||||||
autofish: boolean = false,
|
autofish: boolean = false,
|
||||||
autofish_t: number = Date.now()
|
autofish_t: number = Date.now()
|
||||||
) {
|
) {
|
||||||
|
@ -120,6 +125,7 @@ export function stopFishing(
|
||||||
1000 /
|
1000 /
|
||||||
60
|
60
|
||||||
).toFixed(2)} minutes.`,
|
).toFixed(2)} minutes.`,
|
||||||
|
channel: fisher.channel,
|
||||||
isDM: fisher.isDM,
|
isDM: fisher.isDM,
|
||||||
id: fisher.userID
|
id: fisher.userID
|
||||||
});
|
});
|
||||||
|
@ -127,7 +133,7 @@ export function stopFishing(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autofish) {
|
if (autofish) {
|
||||||
startFishing(id, userID, true, true, autofish_t);
|
startFishing(id, userID, channel, true, true, autofish_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ rl.on("line", async line => {
|
||||||
const args = msg.a.split(" ");
|
const args = msg.a.split(" ");
|
||||||
|
|
||||||
const command = await trpc.command.query({
|
const command = await trpc.command.query({
|
||||||
|
channel: logger.id,
|
||||||
args: args.slice(1, args.length),
|
args: args.slice(1, args.length),
|
||||||
command: args[0].substring(usedPrefix.length),
|
command: args[0].substring(usedPrefix.length),
|
||||||
prefix: usedPrefix,
|
prefix: usedPrefix,
|
||||||
|
@ -77,6 +78,10 @@ setInterval(async () => {
|
||||||
// this.logger.debug(backs);
|
// this.logger.debug(backs);
|
||||||
for (const back of backs) {
|
for (const back of backs) {
|
||||||
if (typeof back.m !== "string") return;
|
if (typeof back.m !== "string") return;
|
||||||
|
if (typeof back.channel === "string") {
|
||||||
|
if (back.channel !== logger.id) return;
|
||||||
|
}
|
||||||
|
|
||||||
b.emit(back.m, back);
|
b.emit(back.m, back);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ export interface DiscordBotConfig {
|
||||||
token?: string;
|
token?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const trpc = gettRPC(process.env.DISCORD_FISHING_TOKEN as string);
|
|
||||||
|
|
||||||
export class DiscordBot extends EventEmitter {
|
export class DiscordBot extends EventEmitter {
|
||||||
public client: Discord.Client;
|
public client: Discord.Client;
|
||||||
public logger = new Logger("Discord Bot");
|
public logger = new Logger("Discord Bot");
|
||||||
|
@ -19,6 +17,7 @@ export class DiscordBot extends EventEmitter {
|
||||||
public server?: Discord.Guild;
|
public server?: Discord.Guild;
|
||||||
public defaultChannel?: Discord.TextChannel;
|
public defaultChannel?: Discord.TextChannel;
|
||||||
public b = new EventEmitter();
|
public b = new EventEmitter();
|
||||||
|
public trpc = gettRPC(process.env.DISCORD_FISHING_TOKEN as string);
|
||||||
|
|
||||||
constructor(public conf: DiscordBotConfig) {
|
constructor(public conf: DiscordBotConfig) {
|
||||||
super();
|
super();
|
||||||
|
@ -95,7 +94,7 @@ export class DiscordBot extends EventEmitter {
|
||||||
let prefixes: string[];
|
let prefixes: string[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prefixes = await trpc.prefixes.query();
|
prefixes = await this.trpc.prefixes.query();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
this.logger.warn("Unable to contact server");
|
this.logger.warn("Unable to contact server");
|
||||||
|
@ -110,7 +109,8 @@ export class DiscordBot extends EventEmitter {
|
||||||
|
|
||||||
const args = msg.content.split(" ");
|
const args = msg.content.split(" ");
|
||||||
|
|
||||||
const command = await trpc.command.query({
|
const command = await this.trpc.command.query({
|
||||||
|
channel: msg.channelId,
|
||||||
args: args.slice(1, args.length),
|
args: args.slice(1, args.length),
|
||||||
command: args[0].substring(usedPrefix.length),
|
command: args[0].substring(usedPrefix.length),
|
||||||
prefix: usedPrefix,
|
prefix: usedPrefix,
|
||||||
|
@ -132,7 +132,8 @@ export class DiscordBot extends EventEmitter {
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const backs = (await trpc.backs.query()) as IBack<unknown>[];
|
const backs =
|
||||||
|
(await this.trpc.backs.query()) as IBack<unknown>[];
|
||||||
if (backs.length > 0) {
|
if (backs.length > 0) {
|
||||||
// this.logger.debug(backs);
|
// this.logger.debug(backs);
|
||||||
for (const back of backs) {
|
for (const back of backs) {
|
||||||
|
@ -183,6 +184,11 @@ export class DiscordBot extends EventEmitter {
|
||||||
this.b.on("sendchat", msg => {
|
this.b.on("sendchat", msg => {
|
||||||
// this.logger.debug("sendchat message:", msg);
|
// this.logger.debug("sendchat message:", msg);
|
||||||
if (!this.defaultChannel) return;
|
if (!this.defaultChannel) return;
|
||||||
|
|
||||||
|
if (typeof msg.channel === "string") {
|
||||||
|
if (msg.channel !== this.defaultChannel.id) return;
|
||||||
|
}
|
||||||
|
|
||||||
this.defaultChannel.send(
|
this.defaultChannel.send(
|
||||||
msg.message.split(`@${msg.id}`).join(`<@${msg.id}>`)
|
msg.message.split(`@${msg.id}`).join(`<@${msg.id}>`)
|
||||||
);
|
);
|
||||||
|
|
|
@ -12,12 +12,12 @@ export interface MPPNetBotConfig {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const trpc = gettRPC(process.env.MPP_FISHING_TOKEN as string);
|
|
||||||
|
|
||||||
export class MPPNetBot {
|
export class MPPNetBot {
|
||||||
public client: Client;
|
public client: Client;
|
||||||
public b = new EventEmitter();
|
public b = new EventEmitter();
|
||||||
public logger: Logger;
|
public logger: Logger;
|
||||||
|
public trpc = gettRPC(process.env.MPP_FISHING_TOKEN as string);
|
||||||
|
public started = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public config: MPPNetBotConfig,
|
public config: MPPNetBotConfig,
|
||||||
|
@ -32,11 +32,14 @@ export class MPPNetBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
|
this.logger.debug("Starting");
|
||||||
this.client.start();
|
this.client.start();
|
||||||
|
this.started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop() {
|
public stop() {
|
||||||
this.client.stop();
|
this.client.stop();
|
||||||
|
this.started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bindEventListeners() {
|
public bindEventListeners() {
|
||||||
|
@ -54,7 +57,7 @@ export class MPPNetBot {
|
||||||
let prefixes: string[];
|
let prefixes: string[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prefixes = await trpc.prefixes.query();
|
prefixes = await this.trpc.prefixes.query();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
this.logger.warn("Unable to contact server");
|
this.logger.warn("Unable to contact server");
|
||||||
|
@ -69,7 +72,8 @@ export class MPPNetBot {
|
||||||
|
|
||||||
const args = msg.a.split(" ");
|
const args = msg.a.split(" ");
|
||||||
|
|
||||||
const command = await trpc.command.query({
|
const command = await this.trpc.command.query({
|
||||||
|
channel: this.client.channel._id,
|
||||||
args: args.slice(1, args.length),
|
args: args.slice(1, args.length),
|
||||||
command: args[0].substring(usedPrefix.length),
|
command: args[0].substring(usedPrefix.length),
|
||||||
prefix: usedPrefix,
|
prefix: usedPrefix,
|
||||||
|
@ -120,7 +124,7 @@ export class MPPNetBot {
|
||||||
let prefixes: string[];
|
let prefixes: string[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prefixes = await trpc.prefixes.query();
|
prefixes = await this.trpc.prefixes.query();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
this.logger.warn("Unable to contact server");
|
this.logger.warn("Unable to contact server");
|
||||||
|
@ -135,7 +139,8 @@ export class MPPNetBot {
|
||||||
|
|
||||||
const args = msg.a.split(" ");
|
const args = msg.a.split(" ");
|
||||||
|
|
||||||
const command = await trpc.command.query({
|
const command = await this.trpc.command.query({
|
||||||
|
channel: this.client.channel._id,
|
||||||
args: args.slice(1, args.length),
|
args: args.slice(1, args.length),
|
||||||
command: args[0].substring(usedPrefix.length),
|
command: args[0].substring(usedPrefix.length),
|
||||||
prefix: usedPrefix,
|
prefix: usedPrefix,
|
||||||
|
@ -155,7 +160,8 @@ export class MPPNetBot {
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const backs = (await trpc.backs.query()) as IBack<unknown>[];
|
const backs =
|
||||||
|
(await this.trpc.backs.query()) as IBack<unknown>[];
|
||||||
if (backs.length > 0) {
|
if (backs.length > 0) {
|
||||||
// this.logger.debug(backs);
|
// this.logger.debug(backs);
|
||||||
for (const back of backs) {
|
for (const back of backs) {
|
||||||
|
@ -182,6 +188,11 @@ export class MPPNetBot {
|
||||||
|
|
||||||
this.b.on("sendchat", msg => {
|
this.b.on("sendchat", msg => {
|
||||||
// this.logger.debug("sendchat message:", msg);
|
// this.logger.debug("sendchat message:", msg);
|
||||||
|
|
||||||
|
if (typeof msg.channel === "string") {
|
||||||
|
if (msg.channel !== this.client.channel._id) return;
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.isDM) {
|
if (msg.isDM) {
|
||||||
this.sendDM(msg.message, msg.id);
|
this.sendDM(msg.message, msg.id);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { loadConfig } from "@util/config";
|
import { loadConfig } from "@util/config";
|
||||||
import { MPPNetBot, type MPPNetBotConfig } from "./Bot";
|
import { MPPNetBot, type MPPNetBotConfig } from "./Bot";
|
||||||
|
import { Logger } from "@util/Logger";
|
||||||
|
|
||||||
const bots = [];
|
const logger = new Logger("big brain");
|
||||||
|
|
||||||
|
const bots: MPPNetBot[] = [];
|
||||||
|
|
||||||
const defaults = loadConfig("config/bots.yml", [
|
const defaults = loadConfig("config/bots.yml", [
|
||||||
{
|
{
|
||||||
|
@ -26,5 +29,4 @@ export function initBot(conf: MPPNetBotConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MPPNetBot as Bot };
|
export { MPPNetBot as Bot };
|
||||||
|
|
||||||
export default MPPNetBot;
|
export default MPPNetBot;
|
||||||
|
|
|
@ -10,6 +10,7 @@ interface ICommandResponse {
|
||||||
|
|
||||||
interface IContextProps {
|
interface IContextProps {
|
||||||
id: string;
|
id: string;
|
||||||
|
channel: string;
|
||||||
command: string;
|
command: string;
|
||||||
args: string[];
|
args: string[];
|
||||||
prefix: string;
|
prefix: string;
|
||||||
|
@ -106,6 +107,7 @@ interface ILocation {
|
||||||
interface TFisher {
|
interface TFisher {
|
||||||
id: string;
|
id: string;
|
||||||
userID: string;
|
userID: string;
|
||||||
|
channel: string;
|
||||||
t: number;
|
t: number;
|
||||||
isDM: boolean;
|
isDM: boolean;
|
||||||
autofish: boolean;
|
autofish: boolean;
|
||||||
|
|
Loading…
Reference in New Issue