Skip to content

Commit 1e9a306

Browse files
Merge pull request #43 from Vault108/command-update-v14
Command update v14
2 parents 45f3689 + a9eca8b commit 1e9a306

File tree

8 files changed

+230
-227
lines changed

8 files changed

+230
-227
lines changed

DscEvents/interactionCreate.js

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,27 @@ const { permlevel } = require("../modules/functions.js");
33
const config = require("../config.js");
44

55
module.exports = async (client, interaction) => {
6-
// If it's not a command, stop.
7-
if (!interaction.isCommand()) return;
6+
if (!interaction.isChatInputCommand()) return;
87

9-
// Grab the settings for this server from Enmap.
10-
// If there is no guild, get default conf (DMs)
118
const settings = config.defaultSettings;
129

13-
// Get the user or member's permission level from the elevation
1410
const level = permlevel(interaction);
1511

16-
// Grab the command data from the client.container.slashcmds Collection
1712
const cmd = client.container.slashcmds.get(interaction.commandName);
1813

19-
// If that command doesn't exist, silently exit and do nothing
2014
if (!cmd) return;
2115

22-
// Since the permission system from Discord is rather limited in regarding to
23-
// Slash Commands, we'll just utilise our permission checker.
24-
if (level < client.container.levelCache[cmd.conf.permLevel]) {
25-
// Due to the nature of interactions we **must** respond to them otherwise
26-
// they will error out because we didn't respond to them.
27-
return await interaction.reply({
28-
content: `This command can only be used by ${cmd.conf.permLevel}'s only`,
29-
// This will basically set the ephemeral response to either announce
30-
// to everyone, or just the command executioner. But we **HAVE** to
31-
// respond.
32-
ephemeral: "true"
33-
});
34-
}
35-
36-
// If everything checks out, run the command
3716
try {
38-
await cmd.run(client, interaction);
17+
await cmd.execute(interaction);
3918
logger.log(`${config.permLevels.find(l => l.level === level).name} ${interaction.user.id} ran slash command ${interaction.commandName}`, "cmd");
4019

4120
} catch (e) {
4221
console.error(e);
43-
if (interaction.replied)
44-
interaction.followUp({ content: `There was a problem with your request.\n\`\`\`${e.message}\`\`\``, ephemeral: true })
45-
.catch(e => console.error("An error occurred following up on an error", e));
46-
else
47-
if (interaction.deferred)
48-
interaction.editReply({ content: `There was a problem with your request.\n\`\`\`${e.message}\`\`\``, ephemeral: true })
22+
if (interaction.replied || interaction.deferred)
23+
await interaction.followUp({ content: `There was a problem with your request.\n\`\`\`${e.message}\`\`\``, ephemeral: true })
4924
.catch(e => console.error("An error occurred following up on an error", e));
5025
else
51-
interaction.reply({ content: `There was a problem with your request.\n\`\`\`${e.message}\`\`\``, ephemeral: true })
26+
await interaction.reply({ content: `There was a problem with your request.\n\`\`\`${e.message}\`\`\``, ephemeral: true })
5227
.catch(e => console.error("An error occurred replying on an error", e));
5328
}
54-
};
29+
};

DscSlash/debug.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
2+
const os = require('os');
3+
4+
module.exports = {
5+
data: new SlashCommandBuilder()
6+
.setName("debug")
7+
.setDescription("Displays debug information."),
8+
9+
async execute(interaction) {
10+
const botPing = Date.now() - interaction.createdTimestamp; // Calculate bot latency
11+
const DebugEmbed = new EmbedBuilder()
12+
.setColor('#0099ff')
13+
.setTitle('STATISTICS')
14+
.addFields(
15+
{ name: 'System OS', value: `${os.type()} ${os.release()} (${os.arch()})`, inline: false },
16+
{ name: 'CPU', value: `${os.cpus()[0].model}`, inline: false },
17+
{ name: 'Total Memory', value: `${(os.totalmem() / 1024 / 1024 / 1024).toFixed(2)} GB`, inline: false },
18+
{ name: 'Free Memory', value: `${(os.freemem() / 1024 / 1024 / 1024).toFixed(2)} GB`, inline: false },
19+
{ name: 'Ping', value: `Bot: **${botPing}ms**\nAPI: **${interaction.client.ws.ping}ms**`, inline: false },
20+
)
21+
.setTimestamp();
22+
23+
await interaction.reply({ embeds: [DebugEmbed] });
24+
},
25+
};

DscSlash/mylevel.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1+
const { SlashCommandBuilder } = require("discord.js");
12
const config = require("../config.js");
2-
const { version } = require("discord.js");
3-
const { codeBlock } = require("@discordjs/builders");
43
const { permlevel } = require("../modules/functions.js");
5-
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
6-
const level = permlevel(interaction);
74

5+
module.exports = {
6+
data: new SlashCommandBuilder()
7+
.setName("mylevel")
8+
.setDescription("Gives Bot Command Access Level"),
9+
async execute(interaction) {
10+
const level = permlevel(interaction);
811
const friendly = config.permLevels.find(l => l.level === level).name;
9-
await interaction.deferReply();
10-
const reply = await interaction.editReply(`Your permission level is: ${level} - ${friendly}`);
11-
// await interaction.editReply(`Pong! Latency is ${reply.createdTimestamp - interaction.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms.`);
12-
};
13-
14-
exports.commandData = {
15-
name: "mylevel",
16-
description: "Gives Bot Command Access Level",
17-
options: [],
18-
defaultPermission: true,
19-
};
20-
21-
// Set guildOnly to true if you want it to be available on guilds only.
22-
// Otherwise false is global.
23-
exports.conf = {
24-
permLevel: "User",
25-
guildOnly: false
26-
};
12+
13+
await interaction.reply(`Your permission level is: **${level}** - **${friendly}**`);
14+
},
15+
};

DscSlash/ping.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
2-
await interaction.deferReply();
3-
const reply = await interaction.editReply("Ping?");
4-
await interaction.editReply(`Pong! Latency is ${reply.createdTimestamp - interaction.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms.`);
5-
};
1+
const { SlashCommandBuilder } = require("discord.js");
62

7-
exports.commandData = {
8-
name: "ping",
9-
description: "Pongs when pinged.",
10-
options: [],
11-
defaultPermission: true,
12-
};
13-
14-
// Set guildOnly to true if you want it to be available on guilds only.
15-
// Otherwise false is global.
16-
exports.conf = {
17-
permLevel: "User",
18-
guildOnly: false
3+
module.exports = {
4+
data: new SlashCommandBuilder()
5+
.setName("ping")
6+
.setDescription("Pongs when pinged."),
7+
async execute(interaction) {
8+
const botPing = Date.now() - interaction.createdTimestamp;
9+
await interaction.reply({
10+
content: `Pong! Latency is **${botPing}ms**. API Latency is **${Math.round(interaction.client.ws.ping)}ms**.`,
11+
ephemeral: true,
12+
});
13+
},
1914
};

DscSlash/reboot.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
2-
await interaction.deferReply();
3-
const reply = await interaction.editReply("Bot initiating logout and shutdown");
4-
// await interaction.editReply(`Bot initiating logout and shutdown`);
5-
try
6-
{
7-
await client.container.SLbot.close();
8-
}
9-
catch (error)
10-
{
11-
logger.log(`SL: Error when logging out client`, "error");
12-
logger.log(error, "error");
13-
}
14-
process.exit(0);
1+
const { SlashCommandBuilder } = require("discord.js");
152

16-
};
17-
18-
exports.commandData = {
19-
name: "reboot",
20-
description: "Shuts down the bot. If running under PM2, bot will restart automatically.",
21-
options: [],
22-
defaultPermission: true,
23-
};
24-
25-
// Set guildOnly to true if you want it to be available on guilds only.
26-
// Otherwise false is global.
27-
exports.conf = {
28-
permLevel: "Bot Admin",
29-
guildOnly: false
30-
};
3+
module.exports = {
4+
data: new SlashCommandBuilder()
5+
.setName("reboot")
6+
.setDescription("Shuts down the bot. If running under PM2, bot will restart automatically."),
7+
8+
async execute(interaction) {
9+
await interaction.reply({ content: "Bot initiating logout and shutdown..." });
10+
11+
try {
12+
await interaction.client.container.SLbot.close();
13+
} catch (error) {
14+
// Assuming logger is defined elsewhere
15+
logger.log(`SL: Error when logging out client`, "error");
16+
logger.log(error, "error");
17+
}
18+
19+
process.exit(0);
20+
},
21+
};

DscSlash/stats.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
const { version } = require("discord.js");
2-
const { codeBlock } = require("@discordjs/builders");
1+
const { SlashCommandBuilder, EmbedBuilder, version } = require("discord.js");
32
const { DurationFormatter } = require("@sapphire/time-utilities");
43
const durationFormatter = new DurationFormatter();
4+
const packageinfo = require("../package.json");
5+
const name = packageinfo.name;
6+
const dversion = packageinfo.version;
7+
const dependencies = packageinfo.dependencies;
8+
console.log(`package name: ${name}`);
9+
console.log(`package version: ${dversion}`);
10+
console.log(`dependencies:`, dependencies);
11+
const os = require('os');
512

6-
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
7-
const duration = durationFormatter.format(client.uptime);
8-
const stats = codeBlock("asciidoc", `= STATISTICS =
9-
• Mem Usage :: ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB
10-
• Uptime :: ${duration}
11-
• Users :: ${client.guilds.cache.map(g => g.memberCount).reduce((a, b) => a + b).toLocaleString()}
12-
• Servers :: ${client.guilds.cache.size.toLocaleString()}
13-
• Channels :: ${client.channels.cache.size.toLocaleString()}
14-
• Discord.js :: v${version}
15-
• Node :: ${process.version}`);
16-
await interaction.reply(stats);
17-
};
13+
module.exports = {
14+
data: new SlashCommandBuilder()
15+
.setName("stats")
16+
.setDescription("Show's the bots stats."),
1817

19-
exports.commandData = {
20-
name: "stats",
21-
description: "Show's the bots stats.",
22-
options: [],
23-
defaultPermission: true,
24-
};
18+
async execute(interaction) {
19+
const duration = durationFormatter.format(interaction.client.uptime);
20+
const statsEmbed = new EmbedBuilder()
21+
.setColor('#0099ff')
22+
.setTitle('STATISTICS')
23+
.addFields(
24+
{ name: 'Memory Usage', value: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`, inline: true },
25+
{ name: 'Uptime', value: duration, inline: true },
26+
{ name: 'Users', value: (interaction.client.guilds.cache.map(g => g.memberCount).reduce((a, b) => a + b)).toLocaleString(), inline: true },
27+
{ name: 'Servers', value: interaction.client.guilds.cache.size.toLocaleString(), inline: true },
28+
{ name: 'Channels', value: interaction.client.channels.cache.size.toLocaleString(), inline: true },
29+
{ name: 'Discord.js', value: `v${version}`, inline: true },
30+
{ name: 'Node.js', value: process.version, inline: true },
31+
{ name: 'Bot Version', value: `v${dversion}`, inline: true },
32+
)
33+
.setTimestamp();
2534

26-
// Set guildOnly to true if you want it to be available on guilds only.
27-
// Otherwise false is global.
28-
exports.conf = {
29-
permLevel: "User",
30-
guildOnly: false
35+
await interaction.reply({ embeds: [statsEmbed] });
36+
},
3137
};

DscSlash/teleport.js

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,39 @@ function parseSLURL(slurl) {
1616
const { permlevel } = require('../modules/functions.js');
1717
const config = require('../config.js');
1818

19-
exports.run = async (client, interaction) => {
20-
// Check admin permission
21-
const member = interaction.member;
22-
const userPermLevel = permlevel(interaction);
23-
const requiredLevel = config.permLevels.find(l => l.name === 'Bot Admin')?.level || 10;
24-
if (userPermLevel < requiredLevel) {
25-
await interaction.reply({ content: 'You do not have permission to use this command.', ephemeral: true });
26-
return;
27-
}
19+
module.exports = {
20+
data: new SlashCommandBuilder()
21+
.setName('teleport')
22+
.setDescription('Teleport the bot to a Second Life SLURL')
23+
.addStringOption(option =>
24+
option.setName('slurl')
25+
.setDescription('Second Life SLURL (e.g., http://maps.secondlife.com/secondlife/Region/x/y/z)')
26+
.setRequired(true)),
27+
async execute(interaction) {
28+
const userPermLevel = permlevel(interaction);
29+
const requiredLevel = config.permLevels.find(l => l.name === 'Bot Admin')?.level || 10;
30+
if (userPermLevel < requiredLevel) {
31+
return interaction.reply({ content: 'You do not have permission to use this command.', ephemeral: true });
32+
}
2833

29-
await interaction.deferReply();
30-
const slurl = interaction.options.getString('slurl');
31-
const loc = parseSLURL(slurl);
32-
if (!loc) {
33-
await interaction.editReply('Invalid SLURL format. Please use a link like http://maps.secondlife.com/secondlife/Region/xxx/yyy/zzz');
34-
return;
35-
}
36-
await interaction.editReply(`Attempting teleport to ${loc.region} (${loc.x}, ${loc.y}, ${loc.z})...`);
37-
try {
38-
// Use teleportTo(regionName, position, lookAt)
39-
const { Vector3 } = client.container.nmv;
40-
const position = new Vector3(loc.x, loc.y, loc.z);
41-
const lookAt = position;
42-
await client.container.SLbot.clientCommands.teleport.teleportTo(loc.region, position, lookAt);
43-
await interaction.followUp(`Teleport successful to ${loc.region} (${loc.x}, ${loc.y}, ${loc.z})`);
44-
} catch (err) {
45-
await interaction.followUp(`Teleport failed: ${err.message}`);
46-
}
47-
};
34+
await interaction.deferReply();
35+
const slurl = interaction.options.getString('slurl');
36+
const loc = parseSLURL(slurl);
4837

49-
exports.commandData = {
50-
name: 'teleport',
51-
description: 'Teleport the bot to a Second Life SLURL',
52-
options: [
53-
{
54-
name: 'slurl',
55-
description: 'Second Life SLURL (e.g. http://maps.secondlife.com/secondlife/Region/x/y/z)',
56-
type: 3, // STRING
57-
required: true
38+
if (!loc) {
39+
return interaction.editReply('Invalid SLURL format. Please use a link like http://maps.secondlife.com/secondlife/Region/x/y/z');
5840
}
59-
],
60-
defaultPermission: true,
61-
};
6241

63-
exports.conf = {
64-
permLevel: 'Bot Admin',
65-
guildOnly: false
66-
};
42+
await interaction.editReply(`Attempting teleport to ${loc.region} (${loc.x}, ${loc.y}, ${loc.z})...`);
43+
44+
try {
45+
const { Vector3 } = interaction.client.container.nmv;
46+
const position = new Vector3(loc.x, loc.y, loc.z);
47+
const lookAt = position;
48+
await interaction.client.container.SLbot.clientCommands.teleport.teleportTo(loc.region, position, lookAt);
49+
await interaction.followUp(`Teleport successful to ${loc.region} (${loc.x}, ${loc.y}, ${loc.z})`);
50+
} catch (err) {
51+
await interaction.followUp(`Teleport failed: ${err.message}`);
52+
}
53+
},
54+
};

0 commit comments

Comments
 (0)