mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
fix: events
This commit is contained in:
parent
b1134946b1
commit
781ef10e8c
@ -40,43 +40,13 @@ export class Session extends EventEmitter {
|
|||||||
options: SessionOptions;
|
options: SessionOptions;
|
||||||
|
|
||||||
// TODO: improve this with CreateShardManager etc
|
// TODO: improve this with CreateShardManager etc
|
||||||
rest?: ReturnType<typeof createRestManager>;
|
rest: ReturnType<typeof createRestManager>;
|
||||||
gateway?: ReturnType<typeof createGatewayManager>;
|
gateway: ReturnType<typeof createGatewayManager>;
|
||||||
|
|
||||||
constructor(options: SessionOptions) {
|
constructor(options: SessionOptions) {
|
||||||
super();
|
super();
|
||||||
this.options = options;
|
this.options = options;
|
||||||
// TODO: set botId in Session.botId or something
|
|
||||||
}
|
|
||||||
|
|
||||||
/** TODO: move this */
|
|
||||||
static #toSnakeCase(str: string) {
|
|
||||||
// probably not a fast implementation
|
|
||||||
return str.replace(/[A-Z]/g, (char) => "_" + char.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
override on(event: "ready", func: Events["ready"]): this;
|
|
||||||
override on(event: "messageCreate", func: Events["messageCreate"]): this;
|
|
||||||
override on(event: "raw", func: Events["raw"]): this;
|
|
||||||
override on(event: keyof Events, func: Events[keyof Events]): this {
|
|
||||||
return super.on(Session.#toSnakeCase(event), func);
|
|
||||||
}
|
|
||||||
|
|
||||||
override off(event: "ready", func: Events["ready"]): this;
|
|
||||||
override off(event: "messageCreate", func: Events["messageCreate"]): this;
|
|
||||||
override off(event: "raw", func: Events["raw"]): this;
|
|
||||||
override off(event: keyof Events, func: Events[keyof Events]): this {
|
|
||||||
return super.off(Session.#toSnakeCase(event), func);
|
|
||||||
}
|
|
||||||
|
|
||||||
override once(event: "ready", func: Events["ready"]): this;
|
|
||||||
override once(event: "messageCreate", func: Events["messageCreate"]): this;
|
|
||||||
override once(event: "raw", func: Events["raw"]): this;
|
|
||||||
override once(event: keyof Events, func: Events[keyof Events]): this {
|
|
||||||
return super.once(Session.#toSnakeCase(event), func);
|
|
||||||
}
|
|
||||||
|
|
||||||
async start() {
|
|
||||||
const defHandler: DiscordRawEventHandler = (shard, data) => {
|
const defHandler: DiscordRawEventHandler = (shard, data) => {
|
||||||
this.emit("raw", data, shard.id);
|
this.emit("raw", data, shard.id);
|
||||||
|
|
||||||
@ -102,8 +72,38 @@ export class Session extends EventEmitter {
|
|||||||
},
|
},
|
||||||
handleDiscordPayload: this.options.rawHandler ?? defHandler,
|
handleDiscordPayload: this.options.rawHandler ?? defHandler,
|
||||||
});
|
});
|
||||||
|
// TODO: set botId in Session.botId or something
|
||||||
|
}
|
||||||
|
|
||||||
const getGatewayBot = () => this.rest!.runMethod<DiscordGetGatewayBot>(this.rest!, "GET", Routes.GATEWAY_BOT());
|
/** TODO: move this */
|
||||||
|
static #toSnakeCase(str: string) {
|
||||||
|
// probably not a fast implementation
|
||||||
|
return str.replace(/[A-Z]/g, (char) => "_" + char.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
override on(event: "ready", func: Events["ready"]): this;
|
||||||
|
override on(event: "messageCreate", func: Events["messageCreate"]): this;
|
||||||
|
override on(event: "raw", func: Events["raw"]): this;
|
||||||
|
override on(event: keyof Events, func: Events[keyof Events]): this {
|
||||||
|
return super.on(Session.#toSnakeCase(event).toUpperCase(), func);
|
||||||
|
}
|
||||||
|
|
||||||
|
override off(event: "ready", func: Events["ready"]): this;
|
||||||
|
override off(event: "messageCreate", func: Events["messageCreate"]): this;
|
||||||
|
override off(event: "raw", func: Events["raw"]): this;
|
||||||
|
override off(event: keyof Events, func: Events[keyof Events]): this {
|
||||||
|
return super.off(Session.#toSnakeCase(event).toUpperCase(), func);
|
||||||
|
}
|
||||||
|
|
||||||
|
override once(event: "ready", func: Events["ready"]): this;
|
||||||
|
override once(event: "messageCreate", func: Events["messageCreate"]): this;
|
||||||
|
override once(event: "raw", func: Events["raw"]): this;
|
||||||
|
override once(event: keyof Events, func: Events[keyof Events]): this {
|
||||||
|
return super.once(Session.#toSnakeCase(event).toUpperCase(), func);
|
||||||
|
}
|
||||||
|
|
||||||
|
async start() {
|
||||||
|
const getGatewayBot = () => this.rest.runMethod<DiscordGetGatewayBot>(this.rest, "GET", Routes.GATEWAY_BOT());
|
||||||
|
|
||||||
// check if is empty
|
// check if is empty
|
||||||
if (!Object.keys(this.options.gateway?.data ?? {}).length) {
|
if (!Object.keys(this.options.gateway?.data ?? {}).length) {
|
||||||
|
@ -11,7 +11,7 @@ const session = new Discord.Session({
|
|||||||
});
|
});
|
||||||
|
|
||||||
session.on("ready", (payload) => console.log(payload));
|
session.on("ready", (payload) => console.log(payload));
|
||||||
session.on("message", (payload) => console.log(payload));
|
session.on("messageCreate", (payload) => console.log(payload));
|
||||||
// session.on("raw", (data, shardId) => console.log(shardId, data));
|
// session.on("raw", (data, shardId) => console.log(shardId, data));
|
||||||
|
|
||||||
console.log("hello");
|
console.log("hello");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user