Browse Source

added search

tarfeef101 4 years ago
parent
commit
8e749f26e8
2 changed files with 40 additions and 2 deletions
  1. 5 2
      README.md
  2. 35 0
      src/viki.js

+ 5 - 2
README.md

@@ -30,10 +30,13 @@ The bot recognizes commands sent by non-bot users, prepended with the `prefix` c
 - `price type weapon`
   - Returns riven price data for the `weapon` of mod type `type`, where `type` is either `rolled` or `unrolled`
   - e.g. `!price unrolled kuva bramma`
-- `addmusic querytype querystring`
-  - Looks up music in the host DB, and adds matching songs to the playlist, and starts playing if nothing is playing already
+- `search querytype querystring`
+  - Looks up music in the host DB, and adds responds w/ the results
   - Valid `querytypes` include `['track', 'title', 'song', 'artist', 'album']`
   - `querystring` is the actual query, so if `querytype` was `artist`, a valid `querystring` would be `green day`
+- `addmusic querytype querystring`
+  - Looks up music in the host DB, and adds matching songs to the playlist, and starts playing if nothing is playing already
+  - Same argument syntax as `search`
 - `stop`
   - Stops playback and clears the playlist
 - `next`

+ 35 - 0
src/viki.js

@@ -258,6 +258,41 @@ client.on('message', async msg =>
       }
       break;
 
+    // searches the DB for songs matching the user query, and responds w/ that info in chat
+    case 'search':
+      if (!(config.whitelist.includes(msg.author.tag)))
+      {
+        return msg.channel.send("Sorry, you're not allowed to run this command. Please contact the server owner to acquire that permission.")
+      }
+
+      var type = args[0];
+      if (!(musicTypes.includes(type)))
+      {
+        return msg.channel.send("Sorry, that is not a valid command. Please enter something from: " + musicTypesString);
+      }
+      if (type == 'song' || type == 'track') type = 'title'; // account for poor beets API
+      args.splice(0, 1);
+      const query = args.join(' '); // creates a single string of all args (the query)
+      var path; // this will hold the filepaths from our query
+      exec(`beet ls ${type}:${query} | wc -l`, function (error, stdout, stderr)
+      {
+        if (error)
+        {
+          return msg.channel.send(`Sorry, I encountered an issue looking for that: ${error}`);
+        }
+        else if (stdout === '\n' || stdout === '' || stdout === undefined)
+        {
+          return msg.channel.send('There were no results that matched your search. Please give the type and name of your query (e.g. song songname, album albumname...)');
+        }
+        else
+        {
+          var result = 'Results:\n';
+          result += stdout.trim();
+          msg.channel.send(result);
+        }
+      });
+      break;
+
     // add the songs returned by the user query to the playlist, start if nothing playing
     case 'addmusic':
       if (!(config.whitelist.includes(msg.author.tag)))