2023-04-01 21:49:27 -04:00
|
|
|
import gateWayEvents from '../gateway/dispatch.js'
|
|
|
|
|
import { message } from '../messages/message.js';
|
|
|
|
|
import {Interaction} from '../interactions/interaction.js';
|
|
|
|
|
import Guild from '../guilds/Guild.js';
|
2023-03-18 18:02:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description Returns true if this is a READY event and false otherwise
|
|
|
|
|
* @param {Object} msg
|
|
|
|
|
* @returns {Promise<Boolean>}
|
|
|
|
|
*/
|
2023-04-01 21:49:27 -04:00
|
|
|
export default async function handleEvents(msgObj, token, id) {
|
2023-03-18 18:02:17 -04:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const op = msgObj["op"];
|
|
|
|
|
const t = msgObj["t"];
|
|
|
|
|
|
|
|
|
|
if (op == 10) return resolve({op: op, heartBeat: msgObj["d"]["heartbeat_interval"]});
|
|
|
|
|
|
2023-03-24 20:32:27 -04:00
|
|
|
else if (op != 0) { resolve(false); }
|
|
|
|
|
|
|
|
|
|
else if (t == gateWayEvents.Ready) {
|
|
|
|
|
resolve({op: op, t: t, config: msgObj["d"]["user_settings"], profile: msgObj["d"]["user"]}); //, guilds: msgObj["d"]["guilds"]
|
2023-03-20 12:45:20 -04:00
|
|
|
}
|
|
|
|
|
else if (t == gateWayEvents.MessageCreate) {
|
2023-03-19 18:02:21 -04:00
|
|
|
const msg = new message(msgObj["d"], token);
|
2023-03-18 18:02:17 -04:00
|
|
|
resolve({op: op, t: t, message: msg});
|
|
|
|
|
}
|
2023-03-20 12:45:20 -04:00
|
|
|
else if (t == gateWayEvents.InteractionCreate) {
|
|
|
|
|
resolve({op: op, t: t, interaction: new Interaction(msgObj["d"], token, id)});
|
|
|
|
|
}
|
2023-03-24 20:32:27 -04:00
|
|
|
else if (t == gateWayEvents.GuildCreate) {
|
|
|
|
|
resolve({op: op, t: t, guild: new Guild(msgObj["d"], token)});
|
|
|
|
|
}
|
2023-03-18 18:02:17 -04:00
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
// console.log(t);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|