generated from lucxjo/template
Added schecks to prevent creating multiple roles.
Fixes #4 but need to allow feature to be disabled in guild config Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
2d4504dbe0
commit
78a8c63c3d
14
.runner
14
.runner
|
@ -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"
|
||||
]
|
||||
}
|
|
@ -30,6 +30,30 @@ export class MemberEvent {
|
|||
async memberUpdate([oldM, newM]: ArgsOf<"guildMemberUpdate">) {
|
||||
if (oldM.premiumSince !== newM.premiumSince) {
|
||||
if (newM != null) {
|
||||
const m = await prisma.member.findUnique({
|
||||
where: {
|
||||
dgid_duid: {
|
||||
dgid: newM.guild.id,
|
||||
duid: newM.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (m?.booster_role_id != null && newM.premiumSince != null) {
|
||||
return;
|
||||
} else if (newM.premiumSince == null) {
|
||||
await prisma.member.update({
|
||||
where: {
|
||||
id: m?.id,
|
||||
},
|
||||
data: {
|
||||
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 {
|
||||
const guild = newM.guild;
|
||||
|
||||
const role = await guild.roles.create({
|
||||
|
@ -67,6 +91,8 @@ export class MemberEvent {
|
|||
},
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue