Skip to content

Commit

Permalink
Merge pull request #47 from juddisjudd/master
Browse files Browse the repository at this point in the history
update: dependency update / native cmd
  • Loading branch information
juddisjudd authored May 1, 2024
2 parents 56df729 + 53e1aba commit 1d614a7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"eslint": "^9.1.1",
"nodemon": "^3.1.0",
"prettier": "3.2.5",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"dependencies": {
Expand Down
19 changes: 6 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions src/commands/misc/natives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Command } from '../../interfaces/command';
import axios from 'axios';

const Native: Command = {
data: new SlashCommandBuilder()
.setName('native')
.setDescription('Get information on a specific GTA V native function.')
.addStringOption((option) =>
option.setName('namespace').setDescription('The namespace of the native').setRequired(true)
)
.addStringOption((option) =>
option.setName('function').setDescription('The native function name').setRequired(true)
),
async run(interaction: CommandInteraction) {
const namespaceOption = interaction.options.get('namespace', true);
const functionNameOption = interaction.options.get('function', true);
const namespace = namespaceOption.value as string;
const functionName = functionNameOption.value as string;

await fetchNativeAndSendEmbed(interaction, namespace, functionName);
},
};

async function fetchNativeAndSendEmbed(interaction: CommandInteraction, namespace: string, functionName: string) {
try {
const fileContent = await fetchNativeFromGitHub(namespace, functionName);

const embed = new EmbedBuilder()
.setTitle(`${functionName} - Native Function`)
.setDescription(fileContent)
.setColor('#0099FF');

await interaction.reply({ embeds: [embed] });
} catch (error) {
console.error('Failed to fetch native function data:', error);
await interaction.reply({ content: 'An error occurred while fetching the native function data.', ephemeral: true });
}
}

async function fetchNativeFromGitHub(namespace: string, functionName: string): Promise<string> {
const url = `https://raw.githubusercontent.com/citizenfx/natives/master/${namespace}/${functionName}.md`;
const response = await axios.get(url);
return response.data;
}

export default Native;

0 comments on commit 1d614a7

Please sign in to comment.