This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from takejohn/feature/nyanpass-count
にゃんぱすーカウントの取得 (#17)
- Loading branch information
Showing
4 changed files
with
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// @ts-check | ||
|
||
const { SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require('discord.js'); | ||
const { LANG, strFormat } = require('../util/languages'); | ||
const axios = require('axios').default | ||
|
||
/** | ||
* @typedef {Object} NyanpassData | ||
* @property {string} time | ||
* @property {string} count | ||
*/ | ||
|
||
let axiosNyanpass; | ||
|
||
async function getNyanpass() { | ||
/** @type {import('axios').AxiosResponse<NyanpassData>} */ | ||
const res = await axios.get('https://nyanpass.com/api/get_count'); | ||
return res.data; | ||
} | ||
|
||
/** | ||
* | ||
* @returns {Promise<import('discord.js').InteractionReplyOptions>} | ||
*/ | ||
async function createReply() { | ||
const { time, count } = await getNyanpass(); | ||
const embed = new EmbedBuilder() | ||
.setTitle(LANG.commands.nyanpass.title) | ||
.setColor(0xe75297) | ||
.setDescription('```' + count.padStart(15) + '```') | ||
.setFooter({ | ||
text: strFormat(LANG.commands.nyanpass.footer, [time]) | ||
}); | ||
const component = new ButtonBuilder() | ||
.setStyle(ButtonStyle.Link) | ||
.setEmoji('✋') | ||
.setLabel(LANG.commands.nyanpass.button) | ||
.setURL('https://nyanpass.com/') | ||
/** @type {ActionRowBuilder<ButtonBuilder>} */ | ||
const row = new ActionRowBuilder(); | ||
row.addComponents(component); | ||
return { | ||
embeds: [embed], | ||
components: [row] | ||
}; | ||
} | ||
|
||
/** @type {import("../util/types").Command} */ | ||
const commandNyanpass = { | ||
data: new SlashCommandBuilder() | ||
.setName(LANG.commands.nyanpass.name) | ||
.setDescription(LANG.commands.nyanpass.description), | ||
|
||
async execute(interaction) { | ||
const firstNyanpass = await getNyanpass(); | ||
await interaction.reply(await createReply()); | ||
const interval = setInterval(async () => { | ||
await interaction.editReply(await createReply()); | ||
}, 3_000); | ||
setTimeout(() => clearInterval(interval), 60_000); | ||
} | ||
}; | ||
|
||
module.exports = commandNyanpass; |
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
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