Skip to content

Commit

Permalink
feat(invites): Handle invite gateaway events
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Apr 9, 2020
1 parent 7698091 commit dd3d2a2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/invites/services/Tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class TrackingService extends IMService {
private inviteStoreUpdate: { [guildId: string]: number } = {};

public async init() {
this.client.on('inviteCreate', this.onInviteCreate.bind(this));
this.client.on('inviteDelete', this.onDeleteInvite.bind(this));
this.client.on('channelCreate', this.onChannelCreate.bind(this));
this.client.on('channelUpdate', this.onChannelUpdate.bind(this));
this.client.on('channelDelete', this.onChannelDelete.bind(this));
Expand Down Expand Up @@ -106,6 +108,44 @@ export class TrackingService extends IMService {
}
}

private async onInviteCreate(guild: Guild, invite: Invite) {
await this.client.db.saveInviteCodes([
{
createdAt: invite.createdAt ? new Date(invite.createdAt) : new Date(),
code: invite.code,
channelId: invite.channel ? invite.channel.id : null,
maxAge: invite.maxAge,
maxUses: invite.maxUses,
uses: invite.uses,
temporary: invite.temporary,
guildId: guild.id,
inviterId: invite.inviter ? invite.inviter.id : null,
clearedAmount: 0,
isVanity: false,
isWidget: false
}
]);
}

private async onDeleteInvite(guild: Guild, invite: Invite) {
await this.client.db.saveInviteCodes([
{
createdAt: invite.createdAt ? new Date(invite.createdAt) : new Date(),
code: invite.code,
channelId: invite.channel ? invite.channel.id : null,
maxAge: invite.maxAge,
maxUses: invite.maxUses,
uses: invite.uses,
temporary: invite.temporary,
guildId: guild.id,
inviterId: invite.inviter ? invite.inviter.id : null,
clearedAmount: 0,
isVanity: false,
isWidget: false
}
]);
}

private async onChannelCreate(channel: AnyChannel) {
if (!(channel instanceof GuildChannel)) {
return;
Expand Down

0 comments on commit dd3d2a2

Please sign in to comment.