diff --git a/.runner b/.runner deleted file mode 100644 index e2c6fc7..0000000 --- a/.runner +++ /dev/null @@ -1,14 +0,0 @@ -{ - "WARNING": "This file is automatically generated by act-runner. Do not edit it manually unless you know what you are doing. Removing this file will cause act runner to re-register as a new runner.", - "id": 1, - "uuid": "174b9b82-0e04-44fe-a2b4-025557d65c60", - "name": "Louiss-MBP.lan", - "token": "e043b8b3e648abb069765370c25f09fbd24aecec", - "address": "https://git.ludoviko.ch/", - "labels": [ - "ubuntu-latest:docker://node:16-bullseye", - "ubuntu-22.04:docker://node:16-bullseye", - "ubuntu-20.04:docker://node:16-bullseye", - "ubuntu-18.04:docker://node:16-buster" - ] -} diff --git a/src/events/member_event.ts b/src/events/member_event.ts index bd85a0e..29cd5be 100644 --- a/src/events/member_event.ts +++ b/src/events/member_event.ts @@ -30,42 +30,68 @@ export class MemberEvent { async memberUpdate([oldM, newM]: ArgsOf<"guildMemberUpdate">) { if (oldM.premiumSince !== newM.premiumSince) { if (newM != null) { - const guild = newM.guild; - - const role = await guild.roles.create({ - name: newM.nickname ?? newM.displayName, - reason: `${newM.nickname ?? newM.displayName} just boosted!`, - }); - - await newM.roles.add(role); - const m = await prisma.member.findUnique({ where: { dgid_duid: { - dgid: guild.id, + dgid: newM.guild.id, duid: newM.id, }, }, }); - if (m) { + if (m?.booster_role_id != null && newM.premiumSince != null) { + return; + } else if (newM.premiumSince == null) { await prisma.member.update({ where: { - id: m.id, + id: m?.id, }, data: { - booster_role_id: role.id, + booster_role_id: null, }, }); + const r = await newM.guild.roles.fetch(m!.booster_role_id!); + if (r) await newM.guild.roles.delete(r); + return; } else { - await prisma.member.create({ - data: { - duid: newM.id, - dgid: guild.id, - booster_role_id: role.id, - name: newM.displayName, + const guild = newM.guild; + + const role = await guild.roles.create({ + name: newM.nickname ?? newM.displayName, + reason: `${newM.nickname ?? newM.displayName} just boosted!`, + }); + + await newM.roles.add(role); + + const m = await prisma.member.findUnique({ + where: { + dgid_duid: { + dgid: guild.id, + duid: newM.id, + }, }, }); + + if (m) { + await prisma.member.update({ + where: { + id: m.id, + }, + data: { + booster_role_id: role.id, + }, + }); + } else { + await prisma.member.create({ + data: { + duid: newM.id, + dgid: guild.id, + booster_role_id: role.id, + name: newM.displayName, + }, + }); + } + return; } } }