Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from takejohn/feature/nyanpass-count
Browse files Browse the repository at this point in the history
にゃんぱすーカウントの取得 (#17)
  • Loading branch information
ringo360 authored Feb 25, 2024
2 parents 2cb03ed + 77e9f04 commit c236840
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
64 changes: 64 additions & 0 deletions commands/nyanpass.js
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;
7 changes: 7 additions & 0 deletions language/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@
"footer": "Sekai.Explode"
}
},
"nyanpass": {
"name": "nyanpass",
"description": "にゃんぱすーカウントを取得",
"title": "にゃんぱすーカウント",
"footer": "${0} 時点",
"button": "にゃんぱすーボタン"
},
"nettool": {
"name": "net_tool",
"description": "ネットワーク関連のコマンド",
Expand Down
7 changes: 7 additions & 0 deletions language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@
"footer": "Sekai.Explode"
}
},
"nyanpass": {
"name": "nyanpass",
"description": "Gets Nyanpass count",
"title": "Nyanpass Count",
"footer": "as of ${0}",
"button": "Nyanpass Button"
},
"nettool": {
"name": "net_tool",
"description": "A command related with networks",
Expand Down
7 changes: 7 additions & 0 deletions language/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@
"footer": "Sekai.Explode"
}
},
"nyanpass": {
"name": "nyanpass",
"description": "にゃんぱすーカウントを取得",
"title": "にゃんぱすーカウント",
"footer": "${0} 時点",
"button": "にゃんぱすーボタン"
},
"nettool": {
"name": "net_tool",
"description": "ネットワーク関連のコマンド",
Expand Down

0 comments on commit c236840

Please sign in to comment.