Skip to content

Commit be426ec

Browse files
committed
add simple listener to reapply tier roles when a user rejoins
1 parent 50dece6 commit be426ec

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "devdenbot",
3-
"version": "10.0.2",
3+
"version": "10.1.0",
44
"type": "module",
55
"main": "src/index.ts",
66
"engines": {

src/modules/xp/join.listener.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { DDUser, getOrCreateUserById } from "../../store/models/DDUser.js";
2+
import type { EventListener } from "../module.js";
3+
import { applyTierRoles } from "./xpRoles.util.js";
4+
export const RoleJoinListener: EventListener = {
5+
guildMemberAdd: async (client, member) => {
6+
const ddUser = await getOrCreateUserById(BigInt(member.id));
7+
8+
await applyTierRoles(client, member, ddUser);
9+
},
10+
};

src/modules/xp/xp.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type Module from "../module.js";
22
import { DailyRewardCommand } from "./dailyReward.command.js";
33
import { scheduleAllReminders } from "./dailyReward.reminder.js";
4+
import { RoleJoinListener } from "./join.listener.js";
45
import { LeaderboardCommand } from "./leaderboard.command.js";
56
import { ThreadListener } from "./threadStuff.listener.js";
67
import { XpCommand } from "./xp.command.js";
@@ -9,7 +10,7 @@ import { XpListener } from "./xp.listener.js";
910
export const XpModule: Module = {
1011
name: "xp",
1112
commands: [XpCommand, DailyRewardCommand, LeaderboardCommand],
12-
listeners: [XpListener, ThreadListener],
13+
listeners: [XpListener, ThreadListener, RoleJoinListener],
1314
onInit: async (_, client) => {
1415
await scheduleAllReminders(client);
1516
},

src/modules/xp/xpRoles.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function levelForXp(xp: bigint) {
5151
return level;
5252
}
5353

54-
async function applyTierRoles(
54+
export async function applyTierRoles(
5555
client: Client,
5656
user: GuildMember,
5757
ddUser: DDUser,

0 commit comments

Comments
 (0)