diff --git a/package.json b/package.json index 3bf34ed..812ce59 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 344da96..4a9182c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,8 +43,8 @@ importers: specifier: 3.2.5 version: 3.2.5 ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@20.10.7)(typescript@5.4.5) + specifier: ^10.9.2 + version: 10.9.2(@types/node@20.10.7)(typescript@5.4.5) typescript: specifier: ^5.4.5 version: 5.4.5 @@ -228,11 +228,6 @@ packages: engines: {node: '>=0.4.0'} hasBin: true - acorn@8.7.0: - resolution: {integrity: sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==} - engines: {node: '>=0.4.0'} - hasBin: true - ajv@6.12.6: resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} @@ -736,8 +731,8 @@ packages: ts-mixer@6.0.3: resolution: {integrity: sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==} - ts-node@10.9.1: - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} + ts-node@10.9.2: + resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} hasBin: true peerDependencies: '@swc/core': '>=1.2.50' @@ -1008,8 +1003,6 @@ snapshots: acorn@8.11.3: {} - acorn@8.7.0: {} - ajv@6.12.6: dependencies: fast-deep-equal: 3.1.3 @@ -1505,7 +1498,7 @@ snapshots: ts-mixer@6.0.3: {} - ts-node@10.9.1(@types/node@20.10.7)(typescript@5.4.5): + ts-node@10.9.2(@types/node@20.10.7)(typescript@5.4.5): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.8 @@ -1513,7 +1506,7 @@ snapshots: '@tsconfig/node14': 1.0.1 '@tsconfig/node16': 1.0.2 '@types/node': 20.10.7 - acorn: 8.7.0 + acorn: 8.11.3 acorn-walk: 8.2.0 arg: 4.1.3 create-require: 1.1.1 diff --git a/src/commands/misc/natives.ts b/src/commands/misc/natives.ts new file mode 100644 index 0000000..2b7adb7 --- /dev/null +++ b/src/commands/misc/natives.ts @@ -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 { + const url = `https://raw.githubusercontent.com/citizenfx/natives/master/${namespace}/${functionName}.md`; + const response = await axios.get(url); + return response.data; +} + +export default Native; \ No newline at end of file