Skip to content

Commit

Permalink
Merge branch 'main' into temp-mindset-role-additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipperooni committed Jan 7, 2025
2 parents caec745 + 95f2c64 commit 981229b
Show file tree
Hide file tree
Showing 28 changed files with 868 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ WOLFRAM_TOKEN = <Optional> # For WolframAlpha API
IMGUR_ID = <Optional> # For Imgur API
IMGUR_SECRET = <Optional> # For Imgur API
YOUTUBE_TOKEN = <Optional> # For YouTube API
IMDB_TOKEN = <Optional> # For IMDB API
```
IMDB_TOKEN = <Optional> # For IMDB API
8 changes: 4 additions & 4 deletions .github/workflows/PullRequestOpenAll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
NODE_OPTIONS: --max-old-space-size=7168
steps:
- uses: actions/checkout@v3
- name: Use Node.js '21.1.0'
- name: Use Node.js '22.9.0'
uses: actions/setup-node@v3
with:
node-version: '21.1.0'
node-version: '22.9.0'
cache: 'npm'
- name: Update npm
run: npm install -g npm && npm --version
Expand All @@ -43,10 +43,10 @@ jobs:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Use Node.js '20.5.0'
# - name: Use Node.js '22.9.0'
# uses: actions/setup-node@v3
# with:
# node-version: '20.5.0'
# node-version: '22.9.0'
# cache: 'npm'
# - name: Update npm
# run: npm install -g npm && npm --version
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/PushToMain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
NODE_OPTIONS: --max-old-space-size=7168
steps:
- uses: actions/checkout@v3
- name: Use Node.js '21.1.0'
- name: Use Node.js '22.9.0'
uses: actions/setup-node@v3
with:
node-version: '21.1.0'
node-version: '22.9.0'
cache: 'npm'
- name: Update npm
run: npm install -g npm && npm --version
Expand All @@ -37,10 +37,10 @@ jobs:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Use Node.js '20.5.0'
# - name: Use Node.js '22.9.0'
# uses: actions/setup-node@v3
# with:
# node-version: '20.5.0'
# node-version: '22.9.0'
# cache: 'npm'
# - name: Update npm
# run: npm install -g npm && npm --version
Expand Down
13 changes: 9 additions & 4 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,12 @@ async function personasPage(

// If the user is a developer in the home guild, show the buttonAiModify button
const tripsitGuild = await discordClient.guilds.fetch(env.DISCORD_GUILD_ID);
const tripsitMember = await tripsitGuild.members.fetch(interaction.user.id);
let tripsitMember = null;
try {
tripsitMember = await tripsitGuild.members.fetch(interaction.user.id);
} catch (err) {
// do nothing
}

const components = [
new ActionRowBuilder<ButtonBuilder>()
Expand All @@ -1149,7 +1154,7 @@ async function personasPage(
});

log.debug(F, 'Adding three buttons to personaButtons');
if (tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
if (tripsitMember && tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
components.push(
new ActionRowBuilder<ButtonBuilder>()
.addComponents(buttonAiNew, buttonAiModify, buttonAiDelete),
Expand Down Expand Up @@ -1182,7 +1187,7 @@ async function personasPage(
);
}

if (tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
if (tripsitMember && tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
components.push(
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
menuAiPublic,
Expand All @@ -1196,7 +1201,7 @@ async function personasPage(
};
}

if (tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
if (tripsitMember && tripsitMember.roles.cache.has(env.ROLE_DEVELOPER)) {
log.debug(F, 'Adding buttonAiNew to components');
components.push(
new ActionRowBuilder<ButtonBuilder>()
Expand Down
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
11 changes: 9 additions & 2 deletions src/discord/commands/global/d.tripsitmode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ async function tripsitmodeOn(
const now = new Date();
const diff = now.getTime() - createdDate.getTime();
const minutes = Math.floor(diff / 1000 / 60);
// const seconds = Math.floor(diff / 1000); // Uncomment this for dev server
if (minutes > 5) {
const helperStr = `and/or ${roleHelper}`;
// log.debug(F, `Target has open ticket, and it was created over 5 minutes ago!`);
Expand All @@ -247,9 +248,15 @@ async function tripsitmodeOn(
// If the meta thread exists, update the name and ping the team
if (ticketData.meta_thread_id) {
let metaMessage = '';
if (minutes > 5) {
if (minutes > 5) { // Switch to seconds > 10 for dev server
const helperString = `and/or ${roleHelper}`;
metaMessage = `Hey ${roleTripsitter} ${guildData.role_helper ?? helperString} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`; // eslint-disable-line max-len
try {
metaMessage = `Hey ${roleTripsitter} ${guildData.role_helper ? helperString : ''} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`;

Check warning on line 254 in src/discord/commands/global/d.tripsitmode.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 182. Maximum allowed is 120
} catch (err) {
// If for example helper role has been deleted but the ID is still stored, do this
metaMessage = `Hey ${roleTripsitter} team, ${interaction.member} has indicated that ${target.displayName} needs assistance!`;

Check warning on line 257 in src/discord/commands/global/d.tripsitmode.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 137. Maximum allowed is 120
log.error(F, `Stored Helper ID for guild ${guildData.id} is no longer valid. Role is unfetchable or deleted.`);

Check warning on line 258 in src/discord/commands/global/d.tripsitmode.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 123. Maximum allowed is 120
}
} else {
metaMessage = `${interaction.member} has indicated that ${target.displayName} needs assistance!`;
}
Expand Down
Loading

0 comments on commit 981229b

Please sign in to comment.