Merge branch 'master' into unittests

This commit is contained in:
Flam3rboy
2021-09-20 21:49:42 +02:00
70 changed files with 2258 additions and 1227 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ export async function setupListener(this: WebSocket) {
});
const guilds = members.map((x) => x.guild);
const recipients = await Recipient.find({
where: { user_id: this.user_id },
where: { user_id: this.user_id, closed: false },
relations: ["channel"],
});
const dm_channels = recipients.map((x) => x.channel);
@@ -116,7 +116,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
.has("VIEW_CHANNEL")
)
return;
// TODO: check if user has permission to channel
//No break needed here, we need to call the listenEvent function below
case "GUILD_CREATE":
this.events[id] = await listenEvent(id, consumer, listenOpts);
break;
+19 -19
View File
@@ -88,20 +88,17 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const user_guild_settings_entries = members.map((x) => x.settings);
const recipients = await Recipient.find({
where: { user_id: this.user_id },
where: { user_id: this.user_id, closed: false },
relations: ["channel", "channel.recipients", "channel.recipients.user"],
// TODO: public user selection
});
const channels = recipients.map((x) => {
// @ts-ignore
x.channel.recipients = x.channel.recipients?.map((x) => x.user);
// @ts-ignore
users = users.concat(x.channel.recipients);
if (x.channel.type === ChannelType.DM) {
x.channel.recipients = [
// @ts-ignore
x.channel.recipients.find((x) => x.id !== this.user_id),
];
//TODO is this needed? check if users in group dm that are not friends are sent in the READY event
//users = users.concat(x.channel.recipients);
if (x.channel.isDm()) {
x.channel.recipients = x.channel.recipients!.filter((x) => x.id !== this.user_id);
}
return x.channel;
});
@@ -111,16 +108,19 @@ export async function onIdentify(this: WebSocket, data: Payload) {
});
if (!user) return this.close(CLOSECODES.Authentication_failed);
const public_user = {
username: user.username,
discriminator: user.discriminator,
id: user.id,
public_flags: user.public_flags,
avatar: user.avatar,
bot: user.bot,
bio: user.bio,
};
users.push(public_user);
for (let relation of user.relationships) {
const related_user = relation.to
const public_related_user = {
username: related_user.username,
discriminator: related_user.discriminator,
id: related_user.id,
public_flags: related_user.public_flags,
avatar: related_user.avatar,
bot: related_user.bot,
bio: related_user.bio,
};
users.push(public_related_user);
}
const session_id = genSessionId();
this.session_id = session_id; //Set the session of the WebSocket object
@@ -201,7 +201,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
// @ts-ignore
experiments: experiments, // TODO
guild_join_requests: [], // TODO what is this?
users: users.unique(), // TODO
users: users.unique(),
merged_members: merged_members,
// shard // TODO: only for bots sharding
// application // TODO for applications
+1
View File
@@ -21,5 +21,6 @@ export default {
8: onRequestGuildMembers,
// 9: Invalid Session
// 10: Hello
// 13: Dm_update
14: onLazyRequest,
};