aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-04-15 10:37:45 -0400
committerCara Salter <cara@devcara.com>2023-04-15 10:37:45 -0400
commit5058c8bbeff6b659787a8ab482ac89fc4a194076 (patch)
treeef768f7aa54482469c38e5bb818f96740dae85a0 /src
parent8edf3bf0ca81b942a165cde3bdea11ca755da955 (diff)
download142bot-5058c8bbeff6b659787a8ab482ac89fc4a194076.tar.gz
142bot-5058c8bbeff6b659787a8ab482ac89fc4a194076.zip
init spotify
Change-Id: I6796976649ee59f4e647148e77d76effa7315f73
Diffstat (limited to 'src')
-rw-r--r--src/bot.cpp2
-rw-r--r--src/db.cpp65
-rw-r--r--src/modules.cpp35
3 files changed, 101 insertions, 1 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index d5f21de..2bc6a6b 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -150,7 +150,7 @@ void Bot::onMessage(const dpp::message_create_t &message) {
result.push_back(std::string(begin, str));
} while (0 != *str++);
core->log(dpp::ll_debug, "Attempting to call FOREACH_MOD");
- FOREACH_MOD(I_OnCommand,OnCommand(message, result[0], result));
+ FOREACH_MOD(I_OnCommand,OnCommand(message, lowercase(result[0].erase(0,1)), result));
} else {
/* Call modules */
diff --git a/src/db.cpp b/src/db.cpp
index cea15c0..73a7f02 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -81,3 +81,68 @@ namespace db {
}
}
+
+#include <142bot/date.h>
+
+#include <142bot/iso_week.h>
+#include <iomanip>
+#include <sstream>
+#include <stdexcept> // std::invalid_argument
+
+namespace asdf
+{
+ timestamp from_iso8601_str( const std::string& s )
+ {
+ timestamp ts;
+ if( !from_iso8601_str( s, ts ) )
+ throw std::invalid_argument{
+ "failed to parse "
+ + s
+ + " as an ISO 8601 timestamp"
+ };
+ return ts;
+ }
+
+ bool from_iso8601_str( const std::string& s, timestamp& ts )
+ {
+ std::istringstream stream{ s };
+ stream >> date::parse( "%F %T%z", ts );
+ return !stream.fail();
+ }
+
+ std::string to_iso8601_str( const timestamp& ts )
+ {
+ return date::format( "%F %T%z", ts );
+ }
+
+ std::string to_http_ts_str( const timestamp& ts )
+ {
+ std::stringstream weekday_abbreviation;
+ weekday_abbreviation << static_cast< iso_week::year_weeknum_weekday >(
+ std::chrono::time_point_cast< date::days >( ts )
+ ).weekday();
+
+ return (
+ weekday_abbreviation.str()
+ // timestamps serialize to UTC/GMT by default
+ + date::format(
+ " %d-%m-%Y %H:%M:%S GMT",
+ std::chrono::time_point_cast< std::chrono::seconds >( ts )
+ )
+ );
+ }
+
+ timestamp from_unix_time( unsigned int unix_time )
+ {
+ return timestamp{ std::chrono::duration_cast<
+ std::chrono::microseconds
+ >( std::chrono::seconds{ unix_time } ) };
+ }
+
+ unsigned int to_unix_time( const timestamp& ts )
+ {
+ return std::chrono::duration_cast<
+ std::chrono::seconds
+ >( ts.time_since_epoch() ).count();
+ }
+} \ No newline at end of file
diff --git a/src/modules.cpp b/src/modules.cpp
index 4b636f9..e784c0c 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -470,4 +470,39 @@ void Module::EmbedSimple(const std::string &message, int64_t channelID)
} else {
bot->core->log(dpp::ll_error, fmt::format("Invalid channel {} passed to EmbedSimple", channelID));
}
+}
+
+void Module::EmbedError(int64_t channelId, std::exception &e) {
+ std::string msg = "Got an error running that command!\n\n```";
+ msg.append(e.what());
+ msg.append("\n```");
+ dpp::embed embed = dpp::embed()
+ .set_color(dpp::colors::red)
+ .set_title("Error")
+ .set_description(msg);
+
+ bot->core->message_create(dpp::message(channelId, embed));
+}
+
+
+void Module::EmbedError(const std::string &message, int64_t channelId) {
+ std::string msg = "Got an error running that command!\n\n```";
+ msg.append(message);
+ msg.append("\n```");
+ dpp::embed embed = dpp::embed()
+ .set_color(dpp::colors::red)
+ .set_title("Error")
+ .set_description(msg);
+
+ bot->core->message_create(dpp::message(channelId, embed));
+}
+
+
+void Module::EmbedSuccess(const std::string &message, int64_t channelId) {
+ dpp::embed embed = dpp::embed()
+ .set_color(dpp::colors::green)
+ .set_title("Success!")
+ .set_description(message);
+
+ bot->core->message_create(dpp::message(channelId, embed));
} \ No newline at end of file