generated from lucxjo/template
(#2) Members now created in db on join and leave.
Boosters now have a role created for them and added to their profile. Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
530e99a7d0
commit
17d8746767
|
@ -34,3 +34,7 @@ COPY --from=build-runner /tmp/app/build /app/build
|
||||||
|
|
||||||
# Start bot
|
# Start bot
|
||||||
CMD [ "npm", "run", "start" ]
|
CMD [ "npm", "run", "start" ]
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source=https://git.ludoviko.ch/lucxjo/er
|
||||||
|
LABEL org.opencontainers.image.description="A Discord bot for the Young Royals guild"
|
||||||
|
LABEL org.opencontainers.image.licenses="GPL-3.0-or-later"
|
||||||
|
|
73
src/events/member_event.ts
Normal file
73
src/events/member_event.ts
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import { ArgsOf, Discord, On } from "discordx";
|
||||||
|
import { prisma } from "../main.js";
|
||||||
|
|
||||||
|
@Discord()
|
||||||
|
export class MemberEvent {
|
||||||
|
@On({ event: "guildMemberAdd" })
|
||||||
|
async memberJoin([member]: ArgsOf<"guildMemberAdd">) {
|
||||||
|
await prisma.member.create({
|
||||||
|
data: {
|
||||||
|
dgid: member.guild.id,
|
||||||
|
duid: member.id,
|
||||||
|
name: member.displayName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@On({ event: "guildMemberRemove" })
|
||||||
|
async memberRemove([member]: ArgsOf<"guildMemberRemove">) {
|
||||||
|
await prisma.member.delete({
|
||||||
|
where: {
|
||||||
|
dgid_duid: {
|
||||||
|
duid: member.id,
|
||||||
|
dgid: member.guild.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@On({ event: "guildMemberUpdate" })
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue