Skip to content

Commit

Permalink
Merge branch 'main' into opt-out-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
theimperious1 authored Dec 22, 2024
2 parents 3e289cd + 6df5411 commit 04d5961
Show file tree
Hide file tree
Showing 36 changed files with 775 additions and 228 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ steps:
- apk update
- apk upgrade
- apk add --no-cache git
- cat docker-compose.host.yml
- docker compose -f docker-compose.host.yml --project-name tripbot up tripbot -d --force-recreate --build
# - tail -f /dev/null
environment:
Expand Down
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ GEMINI_KEY = <Optional>
# Other API Tokens
MOODLE_TOKEN = <Optional> # For Moodle API
GITHUB_TOKEN = <Optional> # For GitHub API
RAPID_TOKEN <Optional> # For RapidAPI
RAPID_TOKEN = <Optional> # For RapidAPI
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
17 changes: 11 additions & 6 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { SlashCommand } from '../../@types/commandDef';
import { embedTemplate } from '../../utils/embedTemplate';
import commandContext from '../../utils/context';
import aiChat, { aiModerate } from '../../../global/commands/g.ai';
import { aiModerate, handleAiMessageQueue } from '../../../global/commands/g.ai';

/* TODO
* only direct @ message should trigger a response
Expand Down 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 Expand Up @@ -2175,7 +2180,7 @@ export async function aiMessage(
}, 30000); // Failsafe to stop typing indicator after 30 seconds

try {
const chatResponse = await aiChat(aiPersona, messageList, messageData, attachmentInfo);
const chatResponse = await handleAiMessageQueue(aiPersona, messageList, messageData, attachmentInfo);
response = chatResponse.response;
promptTokens = chatResponse.promptTokens;
completionTokens = chatResponse.completionTokens;
Expand Down
20 changes: 10 additions & 10 deletions src/discord/commands/global/d.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,18 +828,18 @@ export async function helperButton(
### For a refresher on tripsitting please see the following resources:
- [TripSit Learning Portal](https://learn.tripsit.me>)
- [BlueLight's How To Tripsit](<https://docs.google.com/document/d/1vE3jl9imdT3o62nNGn19k5HZVOkECF3jhjra8GkgvwE>)
- [TripSit's How to Tripsit](<https://wiki.tripsit.me/wiki/How_To_Tripsit_Online>)
- [BlueLight's How To Tripsit](https://docs.google.com/document/d/1vE3jl9imdT3o62nNGn19k5HZVOkECF3jhjra8GkgvwE)
- [TripSit's How to Tripsit](https://wiki.tripsit.me/wiki/How_To_Tripsit_Online)
- Check the pins in this channel!
### If you're overwhelmed, ask for backup
### If you're overwhelmed, ask for backup:
- Giving no information is better than giving the wrong information!
### If someone is underage you can ping a Moderator and finish the session if you're comfortable.
- Underage users can use the web-chat anonymously but are not allowed to socialize, moderator will take care of this.
### We are NOT here to give medical advice, diagnose, or treat; or handle suicidal or self-harm situations.
- We're here to give harm reduction facts and *mild* mental health support, no one here is qualified to handle suicide of self-harm.
- If it seems like someone could use mental health services you can refer them to:
**Huddle Humans** - [Mental health support](<https://discord.gg/mentalhealth>)
**HealthyGamer** - [Mental health with a gaming twist](<https://discord.com/invite/H3yRwc7>)
### If someone is underage you can ping a Moderator and finish the session if you're comfortable:
- Underage users can use the web-chat anonymously but are not allowed to socialize, a Moderator will take care of this.
### We are NOT here to give medical advice, diagnose, or treat; or handle suicidal or self-harm situations:
- We're here to give harm reduction facts and *mild* mental health support, no one here is qualified to handle suicide or self-harm.
- If it seems like someone could use mental health services you can refer them to one of the servers below.
**Huddle Humans** - [Mental health support](https://discord.gg/mentalhealth)
**HealthyGamer** - [Mental health with a gaming twist](https://discord.com/invite/H3yRwc7)
**If you have any questions, please reach out!**
`);
Expand Down
51 changes: 37 additions & 14 deletions src/discord/commands/global/d.testkits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,43 @@ export default {
const embed = embedTemplate();

embed.setTitle('Test Kit Resources and information!');
// for (const entry of emsInfo) {
emsInfo.forEach(entry => {
const website = `\n[Website](${entry.website})`;
embed.addFields(
{
name: `${entry.name} (${entry.country})`,
value: stripIndents`${entry.website ? website : ''}\
${entry.description ? `
${entry.description}` : ''}
`,
inline: true,
},
);
});

const fieldsPerRow = 3; // Set fields per row to 3
const totalFields = emsInfo.length;

// Group fields into rows
const rows = Math.ceil(totalFields / fieldsPerRow); // Total number of rows

// Iterate over the number of rows and add fields to each row
for (let rowIndex = 0; rowIndex < rows; rowIndex += 1) {
const startIndex = rowIndex * fieldsPerRow;
const endIndex = Math.min(startIndex + fieldsPerRow, totalFields); // Prevent going out of bounds
const rowFields = emsInfo.slice(startIndex, endIndex); // Get fields for this row

rowFields.forEach((entry, index) => {
const website = entry.website ? `\n[Website](${entry.website})` : ''; // Move ternary outside template literal
const description = entry.description ? `\n${entry.description}` : '';
embed.addFields(
{
name: `${startIndex + index + 1}. ${entry.name} (${entry.country})`,
value: stripIndents`${website}${description}`,
inline: true, // Ensure all fields are inline
},
);
});

// Add invisible fields only if the row is not completely filled
if (rowFields.length < fieldsPerRow) {
const remainingSpaces = fieldsPerRow - rowFields.length;
for (let i = 0; i < remainingSpaces; i += 1) {
embed.addFields({
name: '\u200b', // Invisible field
value: '\u200b',
inline: true,
});
}
}
}
embed.setDescription(stripIndents`
[How to use a reagent test kit](https://dancesafe.org/testing-kit-instructions/)
[How to use fentanyl strips](https://dancesafe.org/fentanyl/)
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 04d5961

Please sign in to comment.