aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-04-03 16:42:00 -0400
committerCara Salter <cara@devcara.com>2023-04-03 16:43:11 -0400
commitb66bf922cc2d8eb3a623d1f776ab6a144832f587 (patch)
tree9335eda96fa257fcf0e2b2305dc25e786af17d6a
parenta4eb22699714d8ea0c0ba3ee16fc48231a307831 (diff)
download142bot-b66bf922cc2d8eb3a623d1f776ab6a144832f587.tar.gz
142bot-b66bf922cc2d8eb3a623d1f776ab6a144832f587.zip
spotify: Implement regex matching for spotify URLs
Change-Id: Iccaede4fcb46c60181567082b02725db7a9f83ac
-rw-r--r--modules/spotify/spotify.cpp17
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;
}
};