From f78c7cf82726324fcee6b738e3d670bee02ad3ff Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Tue, 21 Nov 2023 16:10:08 -0500 Subject: autotools no more cmake! --- modules/Makefile.am | 23 ++++++++++++ modules/stoplight/main.cpp | 80 ----------------------------------------- modules/stoplight/stoplight.cpp | 80 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 80 deletions(-) create mode 100644 modules/Makefile.am delete mode 100644 modules/stoplight/main.cpp create mode 100644 modules/stoplight/stoplight.cpp (limited to 'modules') diff --git a/modules/Makefile.am b/modules/Makefile.am new file mode 100644 index 0000000..edf8278 --- /dev/null +++ b/modules/Makefile.am @@ -0,0 +1,23 @@ +pkglib_LTLIBRARIES = module_mmanager.la module_spotify.la module_reactions.la module_mail.la module_stoplight.la + +module_mmanager_la_SOURCES = mmanager/mmanager.cpp +module_mmanager_la_LDFLAGS = -avoid-version -shared -export-dynamic -module +module_mmanager_la_CXXFLAGS = -I ../include + + +module_spotify_la_SOURCES = spotify/spotify.cpp +module_spotify_la_LDFLAGS = -avoid-version -shared -export-dynamic -module +module_spotify_la_CXXFLAGS = -I ../include + + +module_reactions_la_SOURCES = reactions/reactions.cpp +module_reactions_la_LDFLAGS = -avoid-version -shared -export-dynamic -module +module_reactions_la_CXXFLAGS = -I ../include + +module_mail_la_SOURCES = mail/mail.cpp +module_mail_la_LDFLAGS = -avoid-version -shared -export-dynamic -module +module_mail_la_CXXFLAGS = -I ../include + +module_stoplight_la_SOURCES = stoplight/stoplight.cpp +module_stoplight_la_LDFLAGS = -avoid-version -shared -export-dynamic -module +module_stoplight_la_CXXFLAGS = -I ../include diff --git a/modules/stoplight/main.cpp b/modules/stoplight/main.cpp deleted file mode 100644 index 8740a12..0000000 --- a/modules/stoplight/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include <142bot/modules.hpp> -#include <142bot/util.hpp> -#include -#include -#include - -class StoplightModule: public Module { - std::string stoplightBaseUrl; - public: - StoplightModule(Bot* creator, ModuleLoader* ml): Module(creator,ml) { - ml->attach({I_OnSlashCommand}, this); - auto id = creator->cfg.value("application_id", ""); - dpp::slashcommand stoplight("stoplight", "Control the 142 stop light", creator->core->me.id); - stoplight.add_option( - /* Stop subcommand*/ - dpp::command_option(dpp::co_sub_command, "stop", "Stops the stoplight") - ); - stoplight.add_option( - /* start subcommand */ - dpp::command_option(dpp::co_sub_command, "start", "Starts the stoplight") - ); - stoplight.add_option( - /* shots */ - dpp::command_option(dpp::co_sub_command, "shots", "Triggers shots alarm subroutine") - .add_option(dpp::command_option(dpp::co_integer, "countdowntime", "Time to count down for", true)) - .add_option(dpp::command_option(dpp::co_integer, "gotime", "Time to shots for", true)) - ); - - // register command - creator->core->guild_command_create(stoplight, creator->cfg["main_guild"]); - creator->core->log(dpp::ll_info, "Registered stoplight"); - - this->stoplightBaseUrl = creator->cfg["stoplight_base"]; - - } - - virtual std::string version() { - return "0.1.0"; - } - - virtual std::string description() { - return "Stoplight control"; - } - - bool OnSlashCommand(const dpp::slashcommand_t &event) { - if (event.command.get_command_name() == "stoplight") { - dpp::command_interaction cmd_data = event.command.get_command_interaction(); - - auto subcommand = cmd_data.options[0]; - - this->bot->core->log(dpp::ll_debug, fmt::format("Got subcommand: {}", subcommand.name)); - - if (subcommand.name == "start") { - bot->core->log(dpp::ll_debug, "Attempting to start stoplight"); - cpr::Response r = cpr::Get(cpr::Url(fmt::format("{}/start", this->stoplightBaseUrl))); - - if (r.status_code != 200) { - bot->core->log(dpp::ll_error, r.text); - throw std::exception(); - } - event.reply(dpp::message("Started stoplight")); - - } else if (subcommand.name == "stop") { - bot->core->log(dpp::ll_debug, "Attempting to stop stoplight"); - cpr::Response r = cpr::Get(cpr::Url(fmt::format("{}/stop", this->stoplightBaseUrl))); - - if (r.status_code != 200) { - bot->core->log(dpp::ll_error, r.text); - throw std::exception(); - } - event.reply(dpp::message("Stopped stoplight")); - - } - } - return true; - } -}; - - -ENTRYPOINT(StoplightModule) \ No newline at end of file diff --git a/modules/stoplight/stoplight.cpp b/modules/stoplight/stoplight.cpp new file mode 100644 index 0000000..8740a12 --- /dev/null +++ b/modules/stoplight/stoplight.cpp @@ -0,0 +1,80 @@ +#include <142bot/modules.hpp> +#include <142bot/util.hpp> +#include +#include +#include + +class StoplightModule: public Module { + std::string stoplightBaseUrl; + public: + StoplightModule(Bot* creator, ModuleLoader* ml): Module(creator,ml) { + ml->attach({I_OnSlashCommand}, this); + auto id = creator->cfg.value("application_id", ""); + dpp::slashcommand stoplight("stoplight", "Control the 142 stop light", creator->core->me.id); + stoplight.add_option( + /* Stop subcommand*/ + dpp::command_option(dpp::co_sub_command, "stop", "Stops the stoplight") + ); + stoplight.add_option( + /* start subcommand */ + dpp::command_option(dpp::co_sub_command, "start", "Starts the stoplight") + ); + stoplight.add_option( + /* shots */ + dpp::command_option(dpp::co_sub_command, "shots", "Triggers shots alarm subroutine") + .add_option(dpp::command_option(dpp::co_integer, "countdowntime", "Time to count down for", true)) + .add_option(dpp::command_option(dpp::co_integer, "gotime", "Time to shots for", true)) + ); + + // register command + creator->core->guild_command_create(stoplight, creator->cfg["main_guild"]); + creator->core->log(dpp::ll_info, "Registered stoplight"); + + this->stoplightBaseUrl = creator->cfg["stoplight_base"]; + + } + + virtual std::string version() { + return "0.1.0"; + } + + virtual std::string description() { + return "Stoplight control"; + } + + bool OnSlashCommand(const dpp::slashcommand_t &event) { + if (event.command.get_command_name() == "stoplight") { + dpp::command_interaction cmd_data = event.command.get_command_interaction(); + + auto subcommand = cmd_data.options[0]; + + this->bot->core->log(dpp::ll_debug, fmt::format("Got subcommand: {}", subcommand.name)); + + if (subcommand.name == "start") { + bot->core->log(dpp::ll_debug, "Attempting to start stoplight"); + cpr::Response r = cpr::Get(cpr::Url(fmt::format("{}/start", this->stoplightBaseUrl))); + + if (r.status_code != 200) { + bot->core->log(dpp::ll_error, r.text); + throw std::exception(); + } + event.reply(dpp::message("Started stoplight")); + + } else if (subcommand.name == "stop") { + bot->core->log(dpp::ll_debug, "Attempting to stop stoplight"); + cpr::Response r = cpr::Get(cpr::Url(fmt::format("{}/stop", this->stoplightBaseUrl))); + + if (r.status_code != 200) { + bot->core->log(dpp::ll_error, r.text); + throw std::exception(); + } + event.reply(dpp::message("Stopped stoplight")); + + } + } + return true; + } +}; + + +ENTRYPOINT(StoplightModule) \ No newline at end of file -- cgit v1.2.3