Await some rabbitmq methods, don't reset some config values on start

This commit is contained in:
Madeline 2022-11-06 18:59:31 +11:00
parent 4469acd390
commit 72faa449e0
2 changed files with 37 additions and 37 deletions

View File

@ -31,35 +31,35 @@ async function main() {
await initDatabase(); await initDatabase();
await Config.init(); await Config.init();
await BannedWords.init(); await BannedWords.init();
// only set endpointPublic, if not already set // // only set endpointPublic, if not already set
await Config.set({ // await Config.set({
cdn: { // cdn: {
endpointClient: "${location.host}", // endpointClient: "${location.host}",
endpointPrivate: `http://localhost:${port}`, // endpointPrivate: `http://localhost:${port}`,
}, // },
gateway: { // gateway: {
endpointClient: // endpointClient:
'${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}', // '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}',
endpointPrivate: `ws://localhost:${port}`, // endpointPrivate: `ws://localhost:${port}`,
...(!Config.get().gateway.endpointPublic && { // ...(!Config.get().gateway.endpointPublic && {
endpointPublic: `ws://localhost:${port}`, // endpointPublic: `ws://localhost:${port}`,
}), // }),
}, // },
// regions: { // regions: {
// default: "fosscord", // default: "fosscord",
// useDefaultAsOptimal: true, // useDefaultAsOptimal: true,
// available: [ // available: [
// { // {
// id: "fosscord", // id: "fosscord",
// name: "Fosscord", // name: "Fosscord",
// endpoint: "slowcord.maddy.k.vu:3004", // endpoint: "slowcord.maddy.k.vu:3004",
// vip: false, // vip: false,
// custom: false, // custom: false,
// deprecated: false, // deprecated: false,
// }, // },
// ], // ],
// }, // },
} as any); // } as any);
//Sentry //Sentry
if (Config.get().sentry.enabled) { if (Config.get().sentry.enabled) {

View File

@ -66,7 +66,7 @@ export async function listenEvent(
opts?: ListenEventOpts, opts?: ListenEventOpts,
) { ) {
if (RabbitMQ.connection) { if (RabbitMQ.connection) {
return rabbitListen( return await rabbitListen(
// @ts-ignore // @ts-ignore
opts?.channel || RabbitMQ.channel, opts?.channel || RabbitMQ.channel,
event, event,
@ -74,7 +74,7 @@ export async function listenEvent(
{ acknowledge: opts?.acknowledge }, { acknowledge: opts?.acknowledge },
); );
} else if (process.env.EVENT_TRANSMISSION === "process") { } else if (process.env.EVENT_TRANSMISSION === "process") {
const cancel = () => { const cancel = async () => {
process.removeListener("message", listener); process.removeListener("message", listener);
process.setMaxListeners(process.getMaxListeners() - 1); process.setMaxListeners(process.getMaxListeners() - 1);
}; };
@ -92,7 +92,7 @@ export async function listenEvent(
return cancel; return cancel;
} else { } else {
const listener = (opts: any) => callback({ ...opts, cancel }); const listener = (opts: any) => callback({ ...opts, cancel });
const cancel = () => { const cancel = async () => {
events.removeListener(event, listener); events.removeListener(event, listener);
events.setMaxListeners(events.getMaxListeners() - 1); events.setMaxListeners(events.getMaxListeners() - 1);
}; };
@ -115,13 +115,13 @@ async function rabbitListen(
autoDelete: true, autoDelete: true,
}); });
const cancel = () => { const cancel = async () => {
channel.cancel(q.queue); await channel.cancel(q.queue);
channel.unbindQueue(q.queue, id, ""); await channel.unbindQueue(q.queue, id, "");
}; };
channel.bindQueue(q.queue, id, ""); await channel.bindQueue(q.queue, id, "");
channel.consume( await channel.consume(
q.queue, q.queue,
(opts) => { (opts) => {
if (!opts) return; if (!opts) return;