Skip to content

Commit

Permalink
rework the way opt out works once more (TESTING ON PROD HELL YEAH)
Browse files Browse the repository at this point in the history
  • Loading branch information
electron271 committed Dec 5, 2024
1 parent 91aac03 commit 42e5a99
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
41 changes: 40 additions & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function updateUserLookup(prisma, user) {
const member = await user.client.guilds.cache.get(process.env.DISCORD_SERVER_ID)?.members.fetch(user.id);
await prisma.userLookup.upsert({
where: { id: BigInt(user.id) },
update: { username: user.username, fullOptOut: false, roles: member?.roles.cache.map((role) => role.id) },
update: { username: user.username, roles: member?.roles.cache.map((role) => role.id) },
create: { id: BigInt(user.id), username: user.username, roles: member?.roles.cache.map((role) => role.id) },
});
}
Expand Down Expand Up @@ -220,6 +220,32 @@ All user ids are encrypted for privacy.
}
break;

case 'toggleoptout':
const user4 = await prisma.userLookup.findUnique({
where: { id: BigInt(message.author.id) },
});
if (user4) {
const updated2 = await prisma.userLookup.update({
where: { id: BigInt(message.author.id) },
data: { fullOptOut: !user4.fullOptOut },
});
if (updated2.fullOptOut) {
message.channel.send(`Full opt-out set to true. **Please remember all data is fully anonymized and encrypted. Please only use this if you REALLY need to.**`);
} else {
message.channel.send(`Full opt-out set to false. **Thank you for contributing to the graph!**`);
}
} else {
await prisma.userLookup.create({
data: {
id: BigInt(message.author.id),
username: message.author.username,
fullOptOut: true,
},
});
message.channel.send(`Full opt-out set to true. **Please remember all data is fully anonymized and encrypted. Please only use this if you REALLY need to.**`);
}
break;

case 'forcetoggleoptout': // intended to toggle people who left the server
if (message.author.id !== process.env.BOT_OWNER) {
message.channel.send('You are not authorized to use this command.');
Expand Down Expand Up @@ -299,5 +325,18 @@ client.on(Events.GuildMemberRemove, async (member) => {
await generateGEXF();
});

// on server join opt in that user
client.on(Events.GuildMemberAdd, async (member) => {
console.log(`User ${member.user.username} joined the server. Opting in...`);
await prisma.userLookup.upsert({
where: { id: BigInt(member.id) },
update: { fullOptOut: false },
create: { id: BigInt(member.id), username: member.user.username, fullOptOut: false },
});

// update graph
await generateGEXF();
});

// Start the bot
client.login(process.env.DISCORD_TOKEN);
2 changes: 1 addition & 1 deletion src/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Total users: <2>
Total unique mentions: <3>
Total non-anonymous users: <4>
Total anonymous users: <5>
Total users who left and got opted out: <6>
Total users who left and got opted out/opted out: <6>
Endpoints
=========
Expand Down

0 comments on commit 42e5a99

Please sign in to comment.