🎨 remove long relatives paths -> short module paths

This commit is contained in:
Flam3rboy
2021-09-12 21:09:29 +02:00
parent 7eea37d184
commit 60535f5159
79 changed files with 1633 additions and 261 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
import { CLOSECODES, Payload } from "../util/Constants";
import { Send } from "../util/Send";
import { setHeartbeat } from "../util/setHeartbeat";
import WebSocket from "../util/WebSocket";
import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
import { Send } from "@fosscord/gateway/util/Send";
import { setHeartbeat } from "@fosscord/gateway/util/setHeartbeat";
import WebSocket from "@fosscord/gateway/util/WebSocket";
export async function onHeartbeat(this: WebSocket, data: Payload) {
// TODO: validate payload
+5 -5
View File
@@ -1,5 +1,5 @@
import { CLOSECODES, Payload, OPCODES } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { CLOSECODES, Payload, OPCODES } from "@fosscord/gateway/util/Constants";
import WebSocket from "@fosscord/gateway/util/WebSocket";
import {
Channel,
checkToken,
@@ -17,12 +17,12 @@ import {
} from "@fosscord/util";
import { setupListener } from "../listener/listener";
import { IdentifySchema } from "../schema/Identify";
import { Send } from "../util/Send";
import { Send } from "@fosscord/gateway/util/Send";
// import experiments from "./experiments.json";
const experiments: any = [];
import { check } from "./instanceOf";
import { Recipient } from "../../../util/dist/entities/Recipient";
import { genSessionId } from "../util/SessionUtils";
import { Recipient } from "@fosscord/util";
import { genSessionId } from "@fosscord/gateway/util/SessionUtils";
// TODO: bot sharding
// TODO: check priviliged intents
+3 -3
View File
@@ -6,9 +6,9 @@ import {
Role,
} from "@fosscord/util";
import { LazyRequest } from "../schema/LazyRequest";
import { OPCODES, Payload } from "../util/Constants";
import { Send } from "../util/Send";
import WebSocket from "../util/WebSocket";
import { OPCODES, Payload } from "@fosscord/gateway/util/Constants";
import { Send } from "@fosscord/gateway/util/Send";
import WebSocket from "@fosscord/gateway/util/WebSocket";
import { check } from "./instanceOf";
import "missing-native-js-functions";
+2 -2
View File
@@ -1,5 +1,5 @@
import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
import WebSocket from "@fosscord/gateway/util/WebSocket";
export function onPresenceUpdate(this: WebSocket, data: Payload) {
// return this.close(CLOSECODES.Unknown_error);
+2 -2
View File
@@ -1,6 +1,6 @@
import { CLOSECODES, Payload } from "../util/Constants";
import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
import WebSocket from "../util/WebSocket";
import WebSocket from "@fosscord/gateway/util/WebSocket";
export function onRequestGuildMembers(this: WebSocket, data: Payload) {
// return this.close(CLOSECODES.Unknown_error);
+3 -3
View File
@@ -1,7 +1,7 @@
import { CLOSECODES, Payload } from "../util/Constants";
import { Send } from "../util/Send";
import { CLOSECODES, Payload } from "@fosscord/gateway/util/Constants";
import { Send } from "@fosscord/gateway/util/Send";
import WebSocket from "../util/WebSocket";
import WebSocket from "@fosscord/gateway/util/WebSocket";
export async function onResume(this: WebSocket, data: Payload) {
console.log("Got Resume -> cancel not implemented");
+33 -13
View File
@@ -1,9 +1,18 @@
import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema";
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { Payload } from "@fosscord/gateway/util/Constants";
import WebSocket from "@fosscord/gateway/util/WebSocket";
import { check } from "./instanceOf";
import { Config, emitEvent, Guild, Member, Region, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util";
import { genVoiceToken } from "../util/SessionUtils";
import {
Config,
emitEvent,
Guild,
Member,
Region,
VoiceServerUpdateEvent,
VoiceState,
VoiceStateUpdateEvent,
} from "@fosscord/util";
import { genVoiceToken } from "@fosscord/gateway/util/SessionUtils";
// TODO: check if a voice server is setup
// Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
@@ -14,21 +23,27 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
let voiceState: VoiceState;
try {
voiceState = await VoiceState.findOneOrFail({
where: { user_id: this.user_id }
where: { user_id: this.user_id },
});
if (voiceState.session_id !== this.session_id && body.channel_id === null) {
if (
voiceState.session_id !== this.session_id &&
body.channel_id === null
) {
//Should we also check guild_id === null?
//changing deaf or mute on a client that's not the one with the same session of the voicestate in the database should be ignored
return;
}
//If a user change voice channel between guild we should send a left event first
if (voiceState.guild_id !== body.guild_id && voiceState.session_id === this.session_id) {
if (
voiceState.guild_id !== body.guild_id &&
voiceState.session_id === this.session_id
) {
await emitEvent({
event: "VOICE_STATE_UPDATE",
data: { ...voiceState, channel_id: null },
guild_id: voiceState.guild_id,
})
});
}
//The event send by Discord's client on channel leave has both guild_id and channel_id as null
@@ -50,10 +65,11 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
voiceState.member = await Member.findOneOrFail({
where: { id: voiceState.user_id, guild_id: voiceState.guild_id },
relations: ["user", "roles"],
})
});
//If the session changed we generate a new token
if (voiceState.session_id !== this.session_id) voiceState.token = genVoiceToken();
if (voiceState.session_id !== this.session_id)
voiceState.token = genVoiceToken();
voiceState.session_id = this.session_id;
const { id, ...newObj } = voiceState;
@@ -69,13 +85,17 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
//If it's null it means that we are leaving the channel and this event is not needed
if (voiceState.channel_id !== null) {
const guild = await Guild.findOne({ id: voiceState.guild_id })
const guild = await Guild.findOne({ id: voiceState.guild_id });
const regions = Config.get().regions;
let guildRegion: Region;
if (guild && guild.region) {
guildRegion = regions.available.filter(r => (r.id === guild.region))[0]
guildRegion = regions.available.filter(
(r) => r.id === guild.region
)[0];
} else {
guildRegion = regions.available.filter(r => (r.id === regions.default))[0]
guildRegion = regions.available.filter(
(r) => r.id === regions.default
)[0];
}
await emitEvent({
+2 -2
View File
@@ -1,5 +1,5 @@
import { Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { Payload } from "@fosscord/gateway/util/Constants";
import WebSocket from "@fosscord/gateway/util/WebSocket";
import { onHeartbeat } from "./Heartbeat";
import { onIdentify } from "./Identify";
import { onLazyRequest } from "./LazyRequest";
+2 -2
View File
@@ -1,6 +1,6 @@
import { instanceOf } from "lambert-server";
import { CLOSECODES } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { CLOSECODES } from "@fosscord/gateway/util/Constants";
import WebSocket from "@fosscord/gateway/util/WebSocket";
export function check(this: WebSocket, schema: any, data: any) {
try {