-
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
7 changed files
with
95 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,41 @@ | ||
import { SlashCommandBuilder } from "discord.js"; | ||
import { Command } from "../lib/command"; | ||
import { Embeds } from "../lib/utils/embeds"; | ||
|
||
export const Minecraft: Command = { | ||
data: new SlashCommandBuilder() | ||
.setName('minecraft') | ||
.setDescription('Gets the status of a Minecraft server') | ||
.addStringOption(option => option.setName("address").setRequired(true).setDescription("The address of the server")) | ||
.addIntegerOption(option => option.setName("port").setDescription("The port of the server")), | ||
execute: async (client, interaction) => { | ||
let address = interaction.options.getString("address", true); | ||
let port = interaction.options.getNumber("port", false) ?? 25565; | ||
|
||
let status = await MinecraftServer.ping(address, port).catch(_ => null); | ||
if (status) { | ||
let embed = Embeds.create() | ||
.setAuthor({ name: 'Minecraft Server Status' }) | ||
.setTitle(`${address}${port == 25565 ? "" : `:${port}`}`) | ||
.setDescription(status.description.text) | ||
.addFields({ name: 'Players', value: `${status.players.online}/${status.players.max}` }); | ||
if (status.favicon) embed.setThumbnail(status.favicon); | ||
await Embeds.send(interaction, () => embed); | ||
return; | ||
} | ||
|
||
await Embeds.send(interaction, embed => embed | ||
.setTitle(`${address}${port == 25565 ? "" : `:${port}`}`) | ||
.setDescription(`Server did not respond to ping. :sad:`)); | ||
// let embed = Embeds.create() | ||
// .setAuthor({ name: 'Now Playing' }) | ||
// .setTitle(playing.getTitle()) | ||
// .setURL(playing.getUrl()) | ||
// .setDescription(` | ||
// by ${playing.getAuthor()} \n | ||
// ${bar} ${Time.format(connection.resource?.playbackDuration)}/${Time.format(playing.getDuration(), "seconds")} | ||
// `) | ||
// .setThumbnail(playing.getThumbnailUrl()) | ||
// .addFields({ name: '\u200B', value: `Next in the queue (${Text.number(queue.length, "song")}):` }) | ||
}, | ||
} |
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,25 @@ | ||
|
||
namespace MinecraftServer { | ||
|
||
export interface Status { | ||
previewsChat: boolean; | ||
enforcesSecureChat: boolean; | ||
preventsChatReports: boolean; | ||
description: { | ||
text: string; | ||
}; | ||
players: { | ||
max: number; | ||
online: number; | ||
}; | ||
version: { | ||
name: string; | ||
protocol: number; | ||
} | ||
favicon: string; | ||
} | ||
|
||
export const ping = async (host: string, port: number = 25565, timeout: number = 3000, protocolVersion: number = 47): Promise<Status> => | ||
new Promise((resolve, reject) => new (require('mcping-js')) | ||
.MinecraftServer(host, port).ping(timeout, protocolVersion, (err: any, res: any) => res ? resolve(res) : reject(err))); | ||
} |
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