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,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue