Compare commits
No commits in common. "75fbd177616309bb2ccdcfdba6c52cc2dff33d4f" and "62c7107233b431cd7867d726757db163baaa00b6" have entirely different histories.
75fbd17761
...
62c7107233
67
src/main.cpp
67
src/main.cpp
@ -1,19 +1,74 @@
|
||||
#include <string>
|
||||
#include <dpp/dpp.h>
|
||||
#include <dpp/channel.h>
|
||||
#include <dpp/unicode_emoji.h>
|
||||
|
||||
#include "utils.hpp"
|
||||
#include "pymenu.hpp"
|
||||
#include "config.h"
|
||||
|
||||
int main(int ac, char **av, char** env)
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
(void) ac;
|
||||
dpp::cluster bot(get_token(av, env), dpp::i_default_intents | dpp::i_message_content);
|
||||
dpp::cluster bot(ac == 2 ? av[1] : BOT_TOKEN, dpp::i_default_intents | dpp::i_message_content);
|
||||
|
||||
bot.on_log(dpp::utility::cout_logger());
|
||||
|
||||
on_react(bot);
|
||||
on_message(bot);
|
||||
bot.on_message_create([&bot](const dpp::message_create_t& event)
|
||||
{
|
||||
if (event.msg.author.id == bot.me.id)
|
||||
{
|
||||
bot.message_add_reaction(event.msg, dpp::unicode_emoji::white_check_mark);
|
||||
}
|
||||
else
|
||||
{
|
||||
dpp::channel channel = bot.channel_get_sync(event.msg.channel_id);
|
||||
dpp::channel category = bot.channel_get_sync(channel.parent_id);
|
||||
|
||||
|
||||
if (category.is_category() == false || category.name != GROCERY_LIST_CATEGORY)
|
||||
return;
|
||||
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sea_green)
|
||||
.set_title(event.msg.content)
|
||||
.set_author(event.msg.author.username, "", "")
|
||||
.set_footer(dpp::embed_footer().set_text("PyMenuVersion:2.0"));
|
||||
|
||||
std::string str = event.msg.content;
|
||||
|
||||
unsigned int quantity;
|
||||
float price;
|
||||
|
||||
get_article_data(str, quantity, price);
|
||||
|
||||
if (quantity != 0)
|
||||
embed.add_field("Quantity", std::to_string(quantity));
|
||||
|
||||
if (price != 0)
|
||||
embed.add_field("Price", std::to_string(price) + "€");
|
||||
|
||||
embed.set_title(str);
|
||||
|
||||
dpp::message msg(event.msg.channel_id, embed);
|
||||
event.send(msg);
|
||||
|
||||
bot.message_delete(event.msg.id, event.msg.channel_id);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on_message_reaction_add([&bot](const dpp::message_reaction_add_t& event)
|
||||
{
|
||||
dpp::channel channel = bot.channel_get_sync(event.channel_id);
|
||||
dpp::channel category = bot.channel_get_sync(channel.parent_id);
|
||||
|
||||
if (category.is_category() == false || category.name != GROCERY_LIST_CATEGORY)
|
||||
return;
|
||||
|
||||
if (event.reacting_user.id == bot.me.id)
|
||||
return;
|
||||
dpp::emoji emoji = event.reacting_emoji;
|
||||
if (emoji.name == dpp::unicode_emoji::white_check_mark)
|
||||
bot.message_delete(event.message_id, event.channel_id);
|
||||
});
|
||||
|
||||
bot.on_ready([&bot](const dpp::ready_t& event)
|
||||
{
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/unicode_emoji.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
void on_message(dpp::cluster& bot)
|
||||
{
|
||||
bot.on_message_create([&bot](const dpp::message_create_t& event)
|
||||
{
|
||||
if (event.msg.author.id == bot.me.id)
|
||||
{
|
||||
bot.message_add_reaction(event.msg, dpp::unicode_emoji::white_check_mark);
|
||||
}
|
||||
else
|
||||
{
|
||||
dpp::channel channel = bot.channel_get_sync(event.msg.channel_id);
|
||||
dpp::channel category = bot.channel_get_sync(channel.parent_id);
|
||||
|
||||
if (category.is_category() == false || category.name != GROCERY_LIST_CATEGORY)
|
||||
return;
|
||||
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sea_green)
|
||||
.set_title(event.msg.content)
|
||||
.set_author(event.msg.author.username, "", "")
|
||||
.set_footer(dpp::embed_footer().set_text("PyMenuVersion:2.0"));
|
||||
|
||||
std::string str = event.msg.content;
|
||||
|
||||
unsigned int quantity;
|
||||
float price;
|
||||
|
||||
get_article_data(str, quantity, price);
|
||||
|
||||
if (quantity != 0)
|
||||
embed.add_field("Quantity", std::to_string(quantity));
|
||||
|
||||
if (price != 0)
|
||||
embed.add_field("Price", std::to_string(price) + "€");
|
||||
|
||||
embed.set_title(str);
|
||||
|
||||
dpp::message msg(event.msg.channel_id, embed);
|
||||
event.send(msg);
|
||||
|
||||
bot.message_delete(event.msg.id, event.msg.channel_id);
|
||||
}
|
||||
});
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <dpp/cluster.h>
|
||||
|
||||
void on_react(dpp::cluster& bot);
|
||||
void on_message(dpp::cluster& bot);
|
@ -1,23 +0,0 @@
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/unicode_emoji.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void on_react(dpp::cluster& bot)
|
||||
{
|
||||
bot.on_message_reaction_add([&bot](const dpp::message_reaction_add_t& event)
|
||||
{
|
||||
dpp::channel channel = bot.channel_get_sync(event.channel_id);
|
||||
dpp::channel category = bot.channel_get_sync(channel.parent_id);
|
||||
|
||||
if (category.is_category() == false || category.name != GROCERY_LIST_CATEGORY)
|
||||
return;
|
||||
|
||||
if (event.reacting_user.id == bot.me.id)
|
||||
return;
|
||||
dpp::emoji emoji = event.reacting_emoji;
|
||||
if (emoji.name == dpp::unicode_emoji::white_check_mark)
|
||||
bot.message_delete(event.message_id, event.channel_id);
|
||||
});
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static float get_price(std::string& str)
|
||||
{
|
||||
|
||||
@ -26,7 +24,7 @@ static float get_price(std::string& str)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pain 2€ 1
|
||||
static int get_quantity(std::string& str)
|
||||
{
|
||||
unsigned int quantity = 0;
|
||||
@ -34,6 +32,7 @@ static int get_quantity(std::string& str)
|
||||
|
||||
for (i = 0; i != str.size(); i++)
|
||||
{
|
||||
std::cout << str[i] << std::endl;
|
||||
if (!std::isdigit(str[i]))
|
||||
{
|
||||
if (quantity != 0)
|
||||
@ -53,16 +52,4 @@ int get_article_data(std::string& str, unsigned int& quantity, float& price)
|
||||
quantity = get_quantity(str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string get_token(char** av, char** env)
|
||||
{
|
||||
if (av[1] != NULL)
|
||||
return av[1];
|
||||
for (size_t i = 0; env[i] != NULL; ++i)
|
||||
{
|
||||
if (std::strncmp("BOT_TOKEN", env[i], 9) == 0)
|
||||
return env[i] + 10;
|
||||
}
|
||||
return BOT_TOKEN;
|
||||
}
|
@ -2,5 +2,4 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
int get_article_data(std::string& str, unsigned int& quantity, float& price);
|
||||
std::string get_token(char** av, char** env);
|
||||
int get_article_data(std::string& str, unsigned int& quantity, float& price);
|
Loading…
Reference in New Issue
Block a user