-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { type CommandInteraction, SlashCommandBuilder } from 'discord.js' | ||
|
||
import { type Command } from '../interfaces/Command' | ||
import { generateWeeklyTargetsEmbed } from '../modules/weeklyTargets' | ||
|
||
/** | ||
* Returns weekly targets. | ||
*/ | ||
export const weeklytargets: Command = { | ||
data: new SlashCommandBuilder() | ||
.setName('weeklytargets') | ||
.setDescription('Returns weekly target info for a given week (default current week).') | ||
.addNumberOption(option => | ||
option.setName('weeks') | ||
.setDescription('Optional: Number of weeks ahead to look; use negative numbers to look back.')), | ||
run: async (interaction: CommandInteraction): Promise<void> => { | ||
if (!interaction.isChatInputCommand()) return | ||
|
||
const weeks = interaction.options.getNumber('weeks') ?? 0 | ||
const embed = generateWeeklyTargetsEmbed(weeks) | ||
await interaction.reply({ embeds: [embed] }) | ||
}, | ||
guildCommand: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { EmbedBuilder } from 'discord.js' | ||
|
||
import * as weeklyTargets from '../data/weeklyTargets.json' | ||
|
||
const MS_IN_WEEK = 1000 * 60 * 60 * 24 * 7 | ||
const ROTATION_START = new Date(Date.UTC(2021, 1, 2, 8)) | ||
|
||
/** | ||
* Generates an embed containing weekly targets to be used in messages. | ||
* @param weeks number of weeks away from current week to search | ||
* @returns a message embed containing the weekly targets info | ||
*/ | ||
export const generateWeeklyTargetsEmbed = (weeks: number): EmbedBuilder => { | ||
const numWeeks = Math.round((Date.now().valueOf() - ROTATION_START.valueOf()) / MS_IN_WEEK) + weeks | ||
const carnivaleTargets = Object.entries(weeklyTargets.carnivale).map(([_, t]) => t[numWeeks % t.length]) | ||
const duties = Object.entries(weeklyTargets.duties).map(([_, t]) => `<:logTarget:943678198116384768> ${t[numWeeks % t.length]}`).filter(t => !t.includes('???')).join('\n') | ||
const primes = Object.entries(weeklyTargets.primes).map(([_, t]) => `<:primeTarget:943678179007143947> ${t[numWeeks % t.length]}`).filter(t => !t.includes('???')).join('\n') | ||
return new EmbedBuilder() | ||
.setTitle('Blue Mage Weekly Targets') | ||
.setDescription('[Challenge descriptions/explanations](https://discord.com/channels/762797677133561887/943624070069633085/970802848558350426)') | ||
.setAuthor({ name: 'Blue Academy', iconURL: 'https://i.imgur.com/y8SyjUa.png', url: 'https://discord.gg/blueacademy' }) | ||
.addFields( | ||
{ name: '__Masked Carnivale Targets__', value: `:third_place: ${carnivaleTargets[0]}\n:second_place: ${carnivaleTargets[1]}\n:first_place: ${carnivaleTargets[2]}`, inline: false }, | ||
{ name: '__Blue Mage Log Targets__', value: duties, inline: false }, | ||
{ name: '__Blue Mage Prime Targets__', value: primes, inline: false }) | ||
} |