diff options
| author | Cara Salter <cara@devcara.com> | 2023-04-03 16:42:00 -0400 | 
|---|---|---|
| committer | Cara Salter <cara@devcara.com> | 2023-04-06 21:13:46 +0000 | 
| commit | 3a3a1e5345ae8e133fa7800d9fcba2dbb779b8b9 (patch) | |
| tree | 9335eda96fa257fcf0e2b2305dc25e786af17d6a /modules/spotify/spotify.cpp | |
| parent | a9a97ac734e9fb4eaed06a14ed5df60a97e45887 (diff) | |
| download | 142bot-3a3a1e5345ae8e133fa7800d9fcba2dbb779b8b9.tar.gz 142bot-3a3a1e5345ae8e133fa7800d9fcba2dbb779b8b9.zip | |
spotify: Implement regex matching for spotify URLs
Change-Id: Iccaede4fcb46c60181567082b02725db7a9f83ac
Diffstat (limited to 'modules/spotify/spotify.cpp')
| -rw-r--r-- | modules/spotify/spotify.cpp | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/modules/spotify/spotify.cpp b/modules/spotify/spotify.cpp index 34d0f65..df7515d 100644 --- a/modules/spotify/spotify.cpp +++ b/modules/spotify/spotify.cpp @@ -15,6 +15,7 @@   *   * =====================================================================================   */ +#include <pcre.h>  #include <stdlib.h>  #include "cpr/cpr.h"  #include <142bot/modules.hpp> @@ -40,6 +41,22 @@ public:      virtual bool OnMessage(const dpp::message_create_t &message, const std::string& clean_message, bool mentioned, const std::vector<std::string> & mentions) {          bot->core->log(dpp::ll_debug, "Got message event");         +        const char* pcre_error; +        int pcre_error_ofs; + +        auto comp = pcre_compile("^https:\/\/open.spotify.com\/track\/([a-zA-Z0-9]+)(.*)$", PCRE_CASELESS, &pcre_error, &pcre_error_ofs, NULL); +        if (!comp) { +            bot->core->log(dpp::ll_error, pcre_error); +        } + +        int matcharr[90]; +        int matchcount = pcre_exec(comp, NULL, clean_message.c_str(), clean_message.length(), 0, 0, matcharr, 90); + +        if (matchcount > 0) { +            // We found a spotify URL! +            EmbedSimple("Found a spotify URL", message.msg.channel_id); +        } +          return true;      }  }; | 
