diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts new file mode 100644 index 0000000..7356d64 --- /dev/null +++ b/src/events/guildMemberUpdate.ts @@ -0,0 +1,36 @@ +// 585600289747369987 +import { Member } from 'eris'; +import { Client, Event } from '../class'; +import { CloudServicesUtil } from '../util'; + +export default class GuildMemberAdd extends Event { + public client: Client; + + constructor(client: Client) { + super(client); + this.event = 'guildMemberAdd'; + } + + public async run(_, member: Member, oldMember: { roles: string[], premiumSince: number }) { + try { + if (member.roles.includes('585600289747369987') && !oldMember.roles.includes('585600289747369987')) { + const csAccountData = await CloudServicesUtil.fetchAccountStatus(member.id, this.client.config.internalKey); + if (csAccountData.tier > 1) return; + + const status = await CloudServicesUtil.upgradeT2(member.id, this.client.config.internalKey); + if (status !== 200) return; + } + + if (!member.roles.includes('585600289747369987') && oldMember.roles.includes('585600289747369987')) { + const csAccountData = await CloudServicesUtil.fetchAccountStatus(member.id, this.client.config.internalKey); + if (csAccountData.tier > 1) return; + + const status = await CloudServicesUtil.downgradeT2(member.id, this.client.config.internalKey); + if (status !== 200) return; + } + } catch (err) { + this.client.util.handleError(err); + } + } +} + diff --git a/src/events/index.ts b/src/events/index.ts index 43d1c5f..973913e 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,5 +1,6 @@ -export { default as CallBackHandler } from './CallBackHandler'; -export { default as CommandHandler } from './CommandHandler'; -export { default as guildMemberAdd } from './guildMemberAdd'; -export { default as messageReactionAdd } from './messageReactionAdd'; -export { default as ready } from './ready'; +export { default as CallBackHandler } from './CallBackHandler'; +export { default as CommandHandler } from './CommandHandler'; +export { default as guildMemberAdd } from './guildMemberAdd'; +export { default as guildMemberUpdate } from './guildMemberUpdate'; +export { default as messageReactionAdd } from './messageReactionAdd'; +export { default as ready } from './ready';