Skip to content

Commit

Permalink
Add mushroom potency graph
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Oct 19, 2023
1 parent d988097 commit 13c9f16
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
89 changes: 89 additions & 0 deletions src/discord/commands/guild/d.mushroom_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
ActionRowBuilder,
AttachmentBuilder,
ButtonBuilder,
ButtonInteraction,
ButtonStyle,
Colors,
SlashCommandBuilder,
} from 'discord.js';
import { SlashCommand } from '../../@types/commandDef';
import { embedTemplate } from '../../utils/embedTemplate';
// import mushroomInfo from '../../../global/commands/g.mushroomInfo';
import commandContext from '../../utils/context';
import { imageGet } from '../../utils/imageGet';

const F = f(__filename);

const source = 'https://www.oaklandhyphae510.com/post/preliminary-tryptamine-potency-analysis-from-dried-homogenized-fruit-bodies-of-psilocybe-mushrooms';

Check warning on line 18 in src/discord/commands/guild/d.mushroom_info.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 154. Maximum allowed is 120
const disclaimer = 'The following data is based on preliminary research and development methods, does not represent final data and requires further peer review before being taken more seriously than \'interesting\'. However, this does represent meaningful, comparable data to the cultivators, to the consumers, and to the public.';

Check warning on line 19 in src/discord/commands/guild/d.mushroom_info.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 331. Maximum allowed is 120
const article = 'https://tripsitter.com/magic-mushrooms/average-potency/';

async function mushroomPageOneEmbed() {
return {
embeds: [embedTemplate()
.setTitle('Mushroom Potency Info')
.setColor(Colors.Green)
.setDescription(`${disclaimer}
For more information check out [the source](${source}) and [this article](${article}).`)
.setImage('attachment://mushroomInfoA.png')],
files: [new AttachmentBuilder(await imageGet('mushroomInfoA'))],

components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId('mushroomPageTwo')
.setLabel('Show Visual')
.setStyle(ButtonStyle.Primary),
)],
};
}

async function mushroomPageTwoEmbed() {
return {
embeds: [embedTemplate()
.setTitle('Mushroom Potency Info')
.setColor(Colors.Green)
.setDescription(`${disclaimer}
For more information check out [the source](${source}) and [this article](${article}).`)
.setImage('attachment://mushroomInfoB.png')],
files: [new AttachmentBuilder(await imageGet('mushroomInfoB'))],

components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId('mushroomPageOne')
.setLabel('Back to Data')
.setStyle(ButtonStyle.Danger),
)],

};
}

export async function mushroomPageOne(
interaction:ButtonInteraction,
) {
// await interaction.deferUpdate();
await interaction.update(await mushroomPageOneEmbed());
}

export async function mushroomPageTwo(
interaction:ButtonInteraction,
) {
// await interaction.deferUpdate();
await interaction.update(await mushroomPageTwoEmbed());
}

export default {
data: new SlashCommandBuilder()
.setName('mushroom_info')
.setDescription('Displays different potencies of mushroom strains.')
.addBooleanOption(option => option.setName('ephemeral')
.setDescription('Set to "True" to show the response only to you')),
async execute(interaction) {
log.info(F, await commandContext(interaction));
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
await interaction.editReply(await mushroomPageOneEmbed());
return true;
},
} as SlashCommand;
6 changes: 3 additions & 3 deletions src/discord/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const interactionCreate: InteractionCreateEvent = {
name: 'interactionCreate',
async execute(interaction) {
const startTime = new Date().getTime();

Check failure on line 24 in src/discord/events/interactionCreate.ts

View workflow job for this annotation

GitHub Actions / Lint

'startTime' is assigned a value but never used
log.info(F, `interactionCreate event started at ${startTime}`);
// log.info(F, `interactionCreate event started at ${startTime}`);

// Don't run anything if the interaction is from a bot
if (interaction.user.bot) return;
Expand Down Expand Up @@ -70,15 +70,15 @@ export const interactionCreate: InteractionCreateEvent = {
if (interaction.isChatInputCommand()) {
// Slash command
// log.debug(F, `Interaction isChatInputCommand!`);
log.info(F, `Decided to run slash command in ${new Date().getTime() - startTime}ms`);
// log.info(F, `Decided to run slash command in ${new Date().getTime() - startTime}ms`);
commandRun(interaction, discordClient);
return;
}

if (interaction.type === InteractionType.ApplicationCommand
// Right click command
&& interaction.isContextMenuCommand()) {
log.debug(F, `interaction.isContextMenuCommand(): ${interaction.isContextMenuCommand()}`);
// log.debug(F, `interaction.isContextMenuCommand(): ${interaction.isContextMenuCommand()}`);
commandRun(interaction, discordClient);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/discord/utils/commandRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export async function commandRun(
discordClient: Client,
) {
const startTime = new Date().getTime();

Check failure on line 24 in src/discord/utils/commandRun.ts

View workflow job for this annotation

GitHub Actions / Lint

'startTime' is assigned a value but never used
log.info(F, `commandRun started at ${startTime}`);
// log.info(F, `commandRun started at ${startTime}`);
const { commandName } = interaction;

const command = discordClient.commands.get(commandName);

if (!command) return;

try {
log.info(F, `Executed the command in ${new Date().getTime() - startTime}ms`);
// log.info(F, `Executed the command in ${new Date().getTime() - startTime}ms`);
await command.execute(interaction);
// log.info(F, `commandRun finished in ${new Date().getTime() - startTime}ms`);
} catch (error) {
Expand Down
13 changes: 8 additions & 5 deletions src/discord/utils/imageGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const imageDef = {
Memphis: { path: `${assetsDirectory}/img/backgrounds/Memphis.png`, url: 'https://drive.google.com/uc?export=view&id=117XLPb59h6V9op7GG7A6FFSvh07Any7-' },
Connected: { path: `${assetsDirectory}/img/backgrounds/Connected.png`, url: 'https://drive.google.com/uc?export=view&id=11AVKT7xrjI2ZgIpxz7j0zstBkD6XOD4m' },
Binary: { path: `${assetsDirectory}/img/backgrounds/Binary.png`, url: 'https://drive.google.com/uc?export=view&id=11Ocm9oq5jCqnWleZEZyk9yPsdSpQl6oK' },
mushroomInfoA: { path: `${assetsDirectory}/img/mushroomInfoA.png`, url: 'https://i.gyazo.com/233df47085a0ac5493d8378111512b3d.png' },
mushroomInfoB: { path: `${assetsDirectory}/img/mushroomInfoB.png`, url: 'https://i.gyazo.com/2aae45e843da99867b82e9b1ad07d22b.png' },
} as {
[key: string]: { path: string;
url: string;
Expand Down Expand Up @@ -121,13 +123,14 @@ export async function imageGet(
// If it does not exist, it will download it from the internet and save it to that location
// Either way, it will return a working path to the image
const { path, url } = imageDef[imageName];
log.debug(F, `Checking ${path}`);
// log.debug(F, `Checking ${path}`);
if (!fs.existsSync(path)) {
log.debug(F, `Downloading ${url} to ${path}`);
// log.debug(F, `Downloading ${url} to ${path}`);
await downloadImage(url, path);
log.debug(F, `Downloaded ${url} to ${path}`);
} else {
log.debug(F, `Found ${path}`);
// log.debug(F, `Downloaded ${url} to ${path}`);
}
// else {
// log.debug(F, `Found ${path}`);
// }
return path;
}

0 comments on commit 13c9f16

Please sign in to comment.