Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove and apply Helper role on-demand and no introductions for people who have had the role previously #848

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions src/discord/commands/global/d.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,22 @@ export async function helperButton(
}

// Do everything else

const role = await interaction.guild?.roles.fetch(guildData.role_helper);

const user = await db.users.findUnique({
where: {
discord_id: target.user.id,
},
});

const userHasBeenAHelper = user?.last_was_helper !== null;

if (!user) {
log.error(F, `No user found for discord_id: ${target.user.id}`);
return;
}

if (!role) {
await interaction.reply({
content: stripIndents`It looks like the guilds helper role was deleted, talk to the server admin about this! They may need to re-run \`/setup tripsit\``,
Expand All @@ -662,17 +676,32 @@ export async function helperButton(
return;
}

// If the role being requested is the Helper or Contributor role, check if they have been banned first
if (role.id === guildData.role_helper && userData.helper_role_ban) {
await interaction.editReply({ content: 'Unable to add this role. If you feel this is an error, please talk to the team!' });
return;
}

if (target.roles.cache.has(role.id)) {
await target.roles.remove(role);
await interaction.reply({
content: stripIndents`You already have the helper role!`,
content: stripIndents`Your helper role has been removed. If you ever want to re-apply it, just click the button again!`,
ephemeral: true,
});
return;
}

// If the role being requested is the Helper or Contributor role, check if they have been banned first
if (role.id === guildData.role_helper && userData.helper_role_ban) {
await interaction.editReply({ content: 'Unable to add this role. If you feel this is an error, please talk to the team!' });
if (userHasBeenAHelper && !target.roles.cache.has(role.id)) {
await target.roles.add(role);
if (interaction.guild.id === env.DISCORD_GUILD_ID) {
const channelTripsitters = await interaction.guild?.channels.fetch(env.CHANNEL_TRIPSITTERS) as TextChannel;
await channelTripsitters.send(stripIndents`${target.displayName} has re-joined as a ${role.name}.`);
}
const metaChannel = await interaction.guild?.channels.fetch(guildData.channel_tripsitmeta) as TextChannel;
await interaction.reply({
content: stripIndents`Welcome back, go check out ${metaChannel}!`,
ephemeral: true,
});
return;
}

Expand Down Expand Up @@ -746,8 +775,22 @@ export async function helperButton(
// log.debug(F, `introMessage: ${introMessage}`);

await target.roles.add(role);

// Update the last date when they were given the helper role
await db.users.upsert({
where: {
discord_id: interaction.user.id,
},
create: {
discord_id: interaction.user.id,
},
update: {
last_was_helper: new Date(),
},
});

const metaChannel = await i.guild?.channels.fetch(guildData.channel_tripsitmeta) as TextChannel;
await i.editReply({ content: `Added role ${role.name}, go check out ${metaChannel}!` });
await i.editReply({ content: `Added role ${role.name}, go check out ${metaChannel}! If you ever want to remove it, just click the button again.` });

if (metaChannel.id === guildData.channel_tripsitmeta) {
const introString = `
Expand Down Expand Up @@ -801,7 +844,6 @@ export async function helperButton(
**If you have any questions, please reach out!**
`);
}

if (i.guild.id === env.DISCORD_GUILD_ID) {
const channelTripsitters = await i.guild?.channels.fetch(env.CHANNEL_TRIPSITTERS) as TextChannel;
const roleTripsitter = await i.guild?.roles.fetch(guildData.role_tripsitter) as Role;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "last_was_helper" TIMESTAMP(3);
1 change: 1 addition & 0 deletions src/prisma/tripbot/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ model users {
wordle_scores wordle_scores[]
connections_scores connections_scores[]
mini_scores mini_scores[]
last_was_helper DateTime?
}

model wordle_scores {
Expand Down
Loading