Skip to content

Commit

Permalink
Add message option and improve handler
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasLamba2006 committed Jun 28, 2023
1 parent 132bf6b commit 41ad8a6
Show file tree
Hide file tree
Showing 16 changed files with 2,777 additions and 1,158 deletions.
34 changes: 34 additions & 0 deletions botconfig/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { ButtonBuilder, ButtonStyle, EmbedBuilder, ActionRowBuilder } = require("discord.js");
const allEmojis = require("./emojis.js");
module.exports = {
yes: new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setLabel("Yes")
.setCustomId("yes")
.setEmoji(allEmojis.nova_yes),
no: new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setLabel("No")
.setCustomId("no")
.setEmoji(allEmojis.nova_no),
cancel: new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setLabel("Cancel")
.setCustomId("cancel")
.setEmoji(allEmojis.nova_no),
/**
*
* @param {String} url | The URL to redirect to
* @param {String} label | The label of the button, defaults to "Click Here"
* @param {Snowflake} emoji | The emoji to use, defaults to the link emoji
* @returns {Discord.ButtonBuilder} | The button
*/
link: function (url, label = "Click Here", emoji = allEmojis.nova_link) {
return new ButtonBuilder()
.setStyle(ButtonStyle.Link)
.setLabel(label)
.setURL(url)
.setEmoji(emoji);
}

};
43 changes: 43 additions & 0 deletions botconfig/permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
AddReactions: "Add Reactions",
Administrator: "Administrator",
AttachFiles: "Attach files",
BanMembers: "Ban members",
ChangeNickname: "Change nickname",
Connect: "Connect",
CreateInstantInvite: "Create instant invite",
CreatePrivateThreads: "Create private threads",
CreatePublicThreads: "Create public threads",
DeafenMembers: "Deafen members",
EmbedLinks: "Embed links",
KickMembers: "Kick members",
ManageChannels: "Manage channels",
ManageEmojisAndStickers: "Manage emojis and stickers",
ManageEvents: "Manage Events",
ManageGuild: "Manage server",
ManageMessages: "Manage messages",
ManageNicknames: "Manage nicknames",
ManageRoles: "Manage roles",
ManageThreads: "Manage Threads",
ManageWebhooks: "Manage webhooks",
MentionEveryone: "Mention everyone",
ModerateMembers: "Moderate Members",
MoveMembers: "Move members",
MuteMembers: "Mute members",
PrioritySpeaker: "Priority speaker",
ReadMessageHistory: "Read message history",
RequestToSpeak: "Request to Speak",
SendMessages: "Send messages",
SendMessagesInThreads: "Send Messages In Threads",
SendTTSMessages: "Send TTS messages",
Speak: "Speak",
Stream: "Video",
UseApplicationCommands: "Use Application Commands",
UseEmbeddedActivities: "Use Embedded Activities",
UseExternalEmojis: "Use External Emojis",
UseExternalStickers: "Use External Stickers",
UseVAD: "Use voice activity",
ViewAuditLog: "View audit log",
ViewChannel: "View channel",
ViewGuildInsights: "View server insights",
};
130 changes: 130 additions & 0 deletions commands/Info/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
const { EmbedBuilder, PermissionFlagsBits } = require("discord.js");
const config = require("../../botconfig/config.js");

const settings = require("../../botconfig/settings.js");
const mongoose = require("mongoose");
module.exports = {
name: "ping", //the command name for the Slash Command
slashName: "ping", //the command name for the Slash Command
category: "Info",
description: "Gives you information on how fast the Bot is", //the command description for Slash Command Overview
cooldown: 1,
memberpermissions: [], //Only allow members with specific Permissions to execute a Commmand [OPTIONAL]
botpermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks],
requiredroles: [], //Only allow specific Users with a Role to execute a Command [OPTIONAL]
alloweduserids: [], //Only allow specific Users to execute a Command [OPTIONAL]
options: [
//OPTIONAL OPTIONS, make the array empty / dont add this option if you don't need options!
//INFORMATIONS! You can add Options, but mind that the NAME MUST BE LOWERCASED! AND NO SPACES!!!, for the CHOCIES you need to add a array of arrays; [ ["",""] , ["",""] ]
//{"Integer": { name: "ping_amount", description: "How many times do you want to ping?", required: true }}, //to use in the code: interacton.getInteger("ping_amount")
//{"String": { name: "ping_amount", description: "How many times do you want to ping?", required: true }}, //to use in the code: interacton.getString("ping_amount")
//{"User": { name: "ping_a_user", description: "To Ping a user lol", required: false }}, //to use in the code: interacton.getUser("ping_a_user")
//{"Channel": { name: "what_channel", description: "To Ping a Channel lol", required: false }}, //to use in the code: interacton.getChannel("what_channel")
//{"Role": { name: "what_role", description: "To Ping a Role lol", required: false }}, //to use in the code: interacton.getRole("what_role")
//{"IntChoices": { name: "what_ping", description: "What Ping do you want to get?", required: true, choices: [["Bot", 1], ["Discord Api", 2]] }, //here the second array input MUST BE A NUMBER // TO USE IN THE CODE: interacton.getInteger("what_ping")
//here the second array input MUST BE A STRING // TO USE IN THE CODE: interacton.getString("what_ping")
],
usage: "ping",
slashRun: async (client, interaction) => {
try {
//things u can directly access in an interaction!
const {
member,
channelId,
guildId,
applicationId,
commandName,
deferred,
replied,
ephemeral,
options,
id,
createdTimestamp,
} = interaction;
const { guild } = member;
await interaction.deferReply({ ephemeral: false }).catch((e) => {console.log(e)});
const ping = Math.floor(createdTimestamp - interaction.createdTimestamp);
const result = await mongoose.connection.db.admin().ping();
const mongooseSeconds = (result.ok % 60000) / 1000;
var pingSeconds = (ping % 60000) / 1000;
var apiSeconds = (client.ws.ping % 60000) / 1000;
interaction.editReply({
embeds: [
new EmbedBuilder()
.setTitle(`πŸ“ Pong!`)
.setColor(client.embed.color)
.addFields({
name: `πŸ“‘ Websocket Latency`,
value: `>>> \`\`\`yml
${ping}ms (${pingSeconds}s)\`\`\``,
inline: true,
},
{
name: `πŸ›° API Latency`,
value: `>>> \`\`\`yml
${client.ws.ping}ms (${apiSeconds}s)\`\`\``,
inline: true,
},
{
name: `πŸ“‚ Database Latency`,
value: `>>> \`\`\`yml
${result.ok}ms (${mongooseSeconds}s)\`\`\``,
inline: false,
})

]
});

} catch (e) {
console.log(e);
}
},
messageRun: async (
client,
message,
args,
plusArgs,
cmdUser,
text,
prefix
) => {
const msg = await message.reply({
embeds: [
new EmbedBuilder()
.setDescription(`Calculating ping...`)
.setColor(client.embed.color),
],
});
const ping = Math.floor(msg.createdTimestamp - message.createdTimestamp);
const result = await mongoose.connection.db.admin().ping();
const mongooseSeconds = (result.ok % 60000) / 1000;
var pingSeconds = (ping % 60000) / 1000;
var apiSeconds = (client.ws.ping % 60000) / 1000;
msg.edit({
embeds: [
new EmbedBuilder()
.setTitle(`πŸ“ Pong!`)
.setColor(client.embed.color)
.addFields({
name: `πŸ“‘ Websocket Latency`,
value: `>>> \`\`\`yml
${ping}ms (${pingSeconds}s)\`\`\``,
inline: true,
},
{
name: `πŸ›° API Latency`,
value: `>>> \`\`\`yml
${client.ws.ping}ms (${apiSeconds}s)\`\`\``,
inline: true,
},
{
name: `πŸ“‚ Database Latency`,
value: `>>> \`\`\`yml
${result.ok}ms (${mongooseSeconds}s)\`\`\``,
inline: false,
})

]
});
},
};
Loading

0 comments on commit 41ad8a6

Please sign in to comment.