modrinth command
This commit is contained in:
parent
bc0725595d
commit
8852026e2c
5 changed files with 110 additions and 1 deletions
|
@ -30,6 +30,12 @@ import 'dotenv/config';
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(...tags.map((b) => ({ name: b.name, value: b.name })))
|
.addChoices(...tags.map((b) => ({ name: b.name, value: b.name })))
|
||||||
),
|
),
|
||||||
|
new SlashCommandBuilder()
|
||||||
|
.setName('modrinth')
|
||||||
|
.setDescription('Get info on a Modrinth project')
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option.setName('id').setDescription('The ID or slug').setRequired(true)
|
||||||
|
),
|
||||||
].map((command) => command.toJSON());
|
].map((command) => command.toJSON());
|
||||||
|
|
||||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
|
||||||
|
|
99
src/commands/modrinth.ts
Normal file
99
src/commands/modrinth.ts
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
type Side = 'required' | 'optional' | 'unsupported';
|
||||||
|
|
||||||
|
export interface ModrinthProject {
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
categories: string[];
|
||||||
|
client_side: Side;
|
||||||
|
server_side: Side;
|
||||||
|
project_type: 'mod' | 'modpack';
|
||||||
|
downloads: number;
|
||||||
|
icon_url: string | null;
|
||||||
|
id: string;
|
||||||
|
team: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
import {
|
||||||
|
type CacheType,
|
||||||
|
type CommandInteraction,
|
||||||
|
EmbedBuilder,
|
||||||
|
} from 'discord.js';
|
||||||
|
|
||||||
|
import { COLORS } from '../constants';
|
||||||
|
|
||||||
|
export const modrinthCommand = async (i: CommandInteraction<CacheType>) => {
|
||||||
|
await i.deferReply();
|
||||||
|
|
||||||
|
const { value: id } = i.options.get('id') ?? { value: null };
|
||||||
|
|
||||||
|
if (!id || typeof id !== 'string') {
|
||||||
|
await i.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle('Error!')
|
||||||
|
.setDescription('You need to provide a valid mod ID!')
|
||||||
|
.setColor(COLORS.red),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = (await fetch('https://api.modrinth.com/v2/project/' + id).then(
|
||||||
|
(a) => a.json()
|
||||||
|
)) as ModrinthProject | { error: string; description: string };
|
||||||
|
|
||||||
|
if ('error' in data) {
|
||||||
|
console.error(data);
|
||||||
|
|
||||||
|
await i.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle('Error!')
|
||||||
|
.setDescription(`\`${data.error}\` ${data.description}`)
|
||||||
|
.setColor(COLORS.red),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await i.editReply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle(data.title)
|
||||||
|
.setDescription(data.description)
|
||||||
|
.setThumbnail(data.icon_url ?? '')
|
||||||
|
.setURL(`https://modrinth.com/project/${data.slug}`)
|
||||||
|
.setFields([
|
||||||
|
{
|
||||||
|
name: 'Categories',
|
||||||
|
value: data.categories.join(', '),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Project type',
|
||||||
|
value: data.project_type,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Downloads',
|
||||||
|
value: data.downloads.toString(),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Client',
|
||||||
|
value: data.client_side,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Server',
|
||||||
|
value: data.server_side,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.setColor(COLORS.green),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
|
@ -23,7 +23,7 @@ export const ETA_MESSAGES = [
|
||||||
'In PolyMC 2.0.0',
|
'In PolyMC 2.0.0',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const COLORS: { [color: string]: number } = {
|
export const COLORS = {
|
||||||
red: 0xef4444,
|
red: 0xef4444,
|
||||||
green: 0x22c55e,
|
green: 0x22c55e,
|
||||||
blue: 0x60a5fa,
|
blue: 0x60a5fa,
|
||||||
|
|
|
@ -18,6 +18,7 @@ import random from 'just-random';
|
||||||
import { green, bold, yellow } from 'kleur/colors';
|
import { green, bold, yellow } from 'kleur/colors';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { getTags } from './tagsTags';
|
import { getTags } from './tagsTags';
|
||||||
|
import { modrinthCommand } from './commands/modrinth';
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -137,6 +138,8 @@ client.on('interactionCreate', async (interaction) => {
|
||||||
await membersCommand(interaction);
|
await membersCommand(interaction);
|
||||||
} else if (commandName === 'stars') {
|
} else if (commandName === 'stars') {
|
||||||
await starsCommand(interaction);
|
await starsCommand(interaction);
|
||||||
|
} else if (commandName === 'modrinth') {
|
||||||
|
await modrinthCommand(interaction);
|
||||||
} else if (commandName === 'rolypoly') {
|
} else if (commandName === 'rolypoly') {
|
||||||
await interaction.reply(
|
await interaction.reply(
|
||||||
'https://media.discordapp.net/attachments/985048903126769764/985051373886382100/rollin-time.gif?width=324&height=216'
|
'https://media.discordapp.net/attachments/985048903126769764/985051373886382100/rollin-time.gif?width=324&height=216'
|
||||||
|
|
|
@ -18,6 +18,7 @@ export const getTags = async (): Promise<Tag[]> => {
|
||||||
|
|
||||||
return raw.map((tag) => {
|
return raw.map((tag) => {
|
||||||
if (tag.embed?.color) {
|
if (tag.embed?.color) {
|
||||||
|
// @ts-expect-error f
|
||||||
tag.embed.color = COLORS[tag.embed.color];
|
tag.embed.color = COLORS[tag.embed.color];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue