Skip to content

Commit

Permalink
test: fetch all roles from server
Browse files Browse the repository at this point in the history
  • Loading branch information
tippfehlr committed Mar 12, 2024
1 parent c1523f7 commit f4ab841
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/modules/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ client.on(Events.PresenceUpdate, async (oldMember, newMember) => {
const startTime = Date.now();
stats.presenceUpdates++;

let debug = false;

if (newMember.userId === '712702707986595880' && newMember.guild?.id === '226115726509998090') {
debug = true;
}

// no activities changed
// if (oldMember?.activities.toString() === newMember?.activities.toString()) return;

Expand All @@ -174,6 +180,10 @@ client.on(Events.PresenceUpdate, async (oldMember, newMember) => {
// await newMember.member?.fetch(true);
// if (debug) console.timeEnd('fetch member ' + date);

if (debug) console.time('fetch roles');
await newMember.guild.roles.fetch();
if (debug) console.timeEnd('fetch roles');

if (
guildConfig.requiredRoleID !== null &&
newMember.member?.roles.cache.has(guildConfig.requiredRoleID)
Expand Down Expand Up @@ -264,6 +274,9 @@ client.on(Events.PresenceUpdate, async (oldMember, newMember) => {
}
newMember.member?.roles.add(role);
stats.rolesAdded++;
if (role.id === '1215707840912695326' && newMember.activities[0].name !== 'ASTRONEER' && newMember.guild?.name === 'ASTRONEER') {
log.debug(`${newMember.guild.name}: user ${newMember.userId} activities: ${newMember.activities.toString()}`);
}
};
permanentRoleIDsToBeAdded.forEach(roleID => {
addDiscordRoleToMember({ roleID, permanent: true });
Expand All @@ -290,7 +303,6 @@ client.on(Events.PresenceUpdate, async (oldMember, newMember) => {

// @deprecated remove all roles still in currentlyActiveActivities
(

prepare('SELECT * FROM currentlyActiveActivities WHERE userIDHash = ? AND guildID = ?')
.all(userIDHash, guildID) as DBCurrentlyActiveActivity[]
).forEach(activeActivity => {
Expand All @@ -311,11 +323,11 @@ client.on(Events.PresenceUpdate, async (oldMember, newMember) => {
});

client.on(Events.GuildCreate, guild => {
log.info(`Joined guild ${guild.name} (${guild.id})`);
log.info(`Joined guild ${guild.name}(${guild.id})`);
getGuildConfig(guild.id);
});

client.on(Events.GuildDelete, guild => log.info(`Left guild ${guild.name} (${guild.id})`));
client.on(Events.GuildDelete, guild => log.info(`Left guild ${guild.name}(${guild.id})`));

client.on(Events.Error, error => {
log.error(error, 'The Discord WebSocket has encountered an error')
Expand Down

0 comments on commit f4ab841

Please sign in to comment.