From 37515177e352f275678d2f2f3c57196f98515965 Mon Sep 17 00:00:00 2001 From: Minz Date: Wed, 3 Apr 2024 15:55:02 +0200 Subject: [PATCH] Add LFM Database integration --- commands/utility/lfm.js | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 commands/utility/lfm.js diff --git a/commands/utility/lfm.js b/commands/utility/lfm.js new file mode 100644 index 0000000..972547e --- /dev/null +++ b/commands/utility/lfm.js @@ -0,0 +1,43 @@ +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); +const { spotify } = require('../../config.json'); +const SpotifyWebApi = require('spotify-web-api-node'); +const https = require('https'); + +module.exports = { + category: 'utility', + global: true, + data: new SlashCommandBuilder() + .setName('lfm') + .setDescription('LastFM interactions') + .addSubcommand(subcommand => + subcommand + .setName('link') + .setDescription('Link your LastFM username') + .addStringOption(option => + option.setName('username') + .setRequired(true) + .setDescription('Your username')) + ) + .addSubcommand(subcommand => + subcommand + .setName('show') + .setDescription('Show your name as it is set in the database') + ), + async execute(interaction) { + let db = await interaction.client.localDB; + let discordId = interaction.member.id; + switch (interaction.options.getSubcommand()) { + case 'link': + let lastFmName = interaction.options.get('username').value; + db.run(`INSERT OR REPLACE INTO lastfm (discord_id, lastfm_name) VALUES (?,?)` ,[discordId, lastFmName]); + interaction.reply('Set username'); + break; + case 'show': + let lfmName = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[discordId]); + interaction.reply(JSON.stringify(lfmName) ?? 'No usrename on record'); + break + default: + break; + } + }, +}; \ No newline at end of file