|
|
@ -9,6 +9,7 @@ import Payload from "./Payload"; |
|
|
|
import {IdentityPayloadType, ReadyEventType, RequestMemberPayloadType} from "../interfaces/payload_types"; |
|
|
|
|
|
|
|
import * as Cursor from 'pg-cursor'; |
|
|
|
import DiscordRedis from "./DiscordRedis"; |
|
|
|
|
|
|
|
export default class DiscordWebSocketData { |
|
|
|
static sql_get_guild_as_unavailable = `
|
|
|
@ -56,11 +57,13 @@ export default class DiscordWebSocketData { |
|
|
|
userid: number = null; |
|
|
|
ident_data?: IdentityPayloadType; |
|
|
|
participates_in_guild: number[] = []; |
|
|
|
redis_connection: DiscordRedis; |
|
|
|
|
|
|
|
heartbeat_timer: Timer; |
|
|
|
|
|
|
|
constructor(ws: WebSocket) { |
|
|
|
this.ws = ws; |
|
|
|
this.redis_connection = new DiscordRedis(this); |
|
|
|
} |
|
|
|
|
|
|
|
send(payload: Payload){ |
|
|
@ -107,6 +110,8 @@ export default class DiscordWebSocketData { |
|
|
|
logger.info('Closing websocket: %d - %s', code, reason); |
|
|
|
logger.info('Clearing timeout'); |
|
|
|
clearTimeout(this.heartbeat_timer); |
|
|
|
logger.info('Closing redis connection'); |
|
|
|
this.redis_connection.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@ -185,6 +190,7 @@ export default class DiscordWebSocketData { |
|
|
|
this.userid = user_id['id']; |
|
|
|
this.authenticated = true; |
|
|
|
this.ident_data = data; |
|
|
|
await this.redis_connection.connect(); |
|
|
|
|
|
|
|
logger.info(`User ID ${this.userid} has logged in`); |
|
|
|
} |
|
|
@ -297,6 +303,10 @@ export default class DiscordWebSocketData { |
|
|
|
|
|
|
|
logger.info(`Sending GUILD_CREATE for guild ${guild.id}`); |
|
|
|
this.send(payload); |
|
|
|
|
|
|
|
this.redis_connection.subscribe([`dapi.private-guild.${guild.id}`]); |
|
|
|
let subscribe_channel_names = channels.rows.filter(row => row.type == 0).map(row => `dapi.private-channel.${row.id}`); |
|
|
|
await this.redis_connection.subscribe(subscribe_channel_names); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|