Skip to content

Commit

Permalink
Added weeklytargets command.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoarkGit committed Aug 23, 2023
1 parent f4a99cc commit 83f45b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- `/register [character] [server] [id]`: register a character to a Discord user using character info or ID
- `/spell [name]`: returns info about a given Blue Mage spell
- `/[type] [topic]`: returns a shortcut previously saved under the `type` category
- `/weeklytargets [weeks]`: returns weekly target info for current week or the week `weeks` away

## Moderator commands
- `/bulkban [prefix]`: bans all users whose name starts with a given prefix
Expand Down
24 changes: 24 additions & 0 deletions src/commands/weeklytargets.ts
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
}
26 changes: 26 additions & 0 deletions src/modules/weeklyTargets.ts
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 })
}

0 comments on commit 83f45b8

Please sign in to comment.