From 3a3a1e5345ae8e133fa7800d9fcba2dbb779b8b9 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Mon, 3 Apr 2023 16:42:00 -0400 Subject: spotify: Implement regex matching for spotify URLs Change-Id: Iccaede4fcb46c60181567082b02725db7a9f83ac --- modules/spotify/spotify.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/spotify') 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 #include #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 & 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; } }; -- cgit v1.2.3