diff --git a/Dockerfile b/Dockerfile index 566555f..f0dc8ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,3 +34,7 @@ COPY --from=build-runner /tmp/app/build /app/build # Start bot 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" diff --git a/src/events/member_event.ts b/src/events/member_event.ts new file mode 100644 index 0000000..bd85a0e --- /dev/null +++ b/src/events/member_event.ts @@ -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, + }, + }); + } + } + } + } +}