mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: Running in bun 🚀
This commit is contained in:
parent
025a957a8b
commit
9a298ee927
@ -60,6 +60,7 @@ export function createShardManager(options: CreateShardManager) {
|
||||
*/
|
||||
identify: async function (shardId: number) {
|
||||
let shard = this.shards.get(shardId);
|
||||
|
||||
if (!shard) {
|
||||
shard = createShard({
|
||||
...this.createShardOptions,
|
||||
|
@ -18,14 +18,14 @@ export function spawnShards(gateway: GatewayManager) {
|
||||
gateway.prepareBuckets();
|
||||
|
||||
// SPREAD THIS OUT TO DIFFERENT WORKERS TO BEGIN STARTING UP
|
||||
gateway.buckets.forEach(async (bucket, bucketId) => {
|
||||
gateway.buckets.forEach((bucket, bucketId) => {
|
||||
// gateway.debug("GW DEBUG", `2. Running forEach loop in spawnShards function.`);
|
||||
|
||||
for (const worker of bucket.workers) {
|
||||
// gateway.debug("GW DEBUG", `3. Running for of loop in spawnShards function.`);
|
||||
|
||||
for (const shardId of worker.queue) {
|
||||
await gateway.tellWorkerToIdentify(worker.id, shardId, bucketId);
|
||||
gateway.tellWorkerToIdentify(worker.id, shardId, bucketId).catch(console.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ export function createShard(
|
||||
compress: options.gatewayConfig.compress ?? false,
|
||||
intents: options.gatewayConfig.intents ?? 0,
|
||||
properties: {
|
||||
os: options.gatewayConfig?.properties?.os ?? Deno.build.os,
|
||||
os: options.gatewayConfig?.properties?.os ?? "linux",
|
||||
browser: options.gatewayConfig?.properties?.browser ?? "Discordeno",
|
||||
device: options.gatewayConfig?.properties?.device ?? "Discordeno",
|
||||
},
|
||||
|
@ -14,7 +14,6 @@ export async function handleMessage(shard: Shard, message_: MessageEvent<any>):
|
||||
// Discord might send zlib compressed payloads.
|
||||
if (shard.gatewayConfig.compress && message instanceof Blob) {
|
||||
message = decoder.decode(decompressWith(new Uint8Array(await message.arrayBuffer())));
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// Safeguard incase decompression failed to make a string.
|
||||
|
@ -24,6 +24,7 @@ export async function runMethod<T = any>(
|
||||
);
|
||||
|
||||
const errorStack = new Error("Location:");
|
||||
|
||||
// @ts-ignore Breaks deno deploy. Luca said add ts-ignore until it's fixed
|
||||
Error.captureStackTrace?.(errorStack);
|
||||
|
||||
|
@ -17,18 +17,22 @@ export interface RestSendRequestOptions {
|
||||
}
|
||||
|
||||
export async function sendRequest<T>(rest: RestManager, options: RestSendRequestOptions): Promise<T> {
|
||||
try {
|
||||
try {
|
||||
// CUSTOM HANDLER FOR USER TO LOG OR WHATEVER WHENEVER A FETCH IS MADE
|
||||
rest.debug(`[REST - fetching] URL: ${options.url} | ${JSON.stringify(options)}`);
|
||||
|
||||
const newURL = options.url.startsWith(BASE_URL) ? options.url : `${BASE_URL}/v${rest.version}/${options.url}`;
|
||||
|
||||
rest.debug(`[REST - url data] URL: ${newURL}`);
|
||||
|
||||
const response = await fetch(
|
||||
options.url.startsWith(BASE_URL) ? options.url : `${BASE_URL}/v${rest.version}/${options.url}`,
|
||||
{
|
||||
new Request(newURL, {
|
||||
method: options.method,
|
||||
headers: options.payload?.headers,
|
||||
body: options.payload?.body,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
rest.debug(`[REST - fetched] URL: ${options.url} | ${JSON.stringify(options)}`);
|
||||
|
||||
const bucketIdFromHeaders = rest.processRequestHeaders(
|
||||
|
22
tests/bun.js
Normal file
22
tests/bun.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { GatewayIntents, Session } from "./deps.ts";
|
||||
|
||||
const token = "lol";
|
||||
const intents = GatewayIntents.MessageContent | GatewayIntents.Guilds | GatewayIntents.GuildMessages;
|
||||
const session = new Session({ token, intents });
|
||||
|
||||
// uncomment to debug stuff
|
||||
// session.on("debug", (any) => {
|
||||
// console.debug(any);
|
||||
// })
|
||||
|
||||
session.on("ready", (payload) => {
|
||||
console.log("Logged in as:", payload.user.username);
|
||||
});
|
||||
|
||||
session.on("messageCreate", (message) => {
|
||||
if (message.content.startsWith("ping")) {
|
||||
message.reply({ content: "pong!" }).catch((err) => console.error(err));
|
||||
}
|
||||
});
|
||||
|
||||
await session.start();
|
Loading…
x
Reference in New Issue
Block a user