Compare commits
6 Commits
75fbd17761
...
main
Author | SHA1 | Date | |
---|---|---|---|
a355447dc6 | |||
a7e87335b1 | |||
5cf17d64f9 | |||
575979c497 | |||
9bf46c857c | |||
2f1089976c |
@ -10,7 +10,6 @@ RUN yes y | apt install g++
|
||||
|
||||
# install the dpp lib
|
||||
RUN yes y | apt install cmake
|
||||
RUN yes y | apt install wget
|
||||
RUN yes y | apt install libsodium23
|
||||
RUN yes y | apt install libopus0
|
||||
RUN wget -O dpp.deb https://dl.dpp.dev/
|
||||
@ -18,12 +17,10 @@ RUN dpkg -i dpp.deb
|
||||
|
||||
RUN mkdir /app
|
||||
|
||||
COPY . /app
|
||||
RUN git clone https://git.chauvet.pro/starnakin/PyMenuBOT /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN make
|
||||
|
||||
COPY src/config.h src/config.h
|
||||
|
||||
ENTRYPOINT ["./PyMenu", "$BOT_TOKEN"]
|
||||
ENTRYPOINT ["./PyMenu"]
|
@ -2,6 +2,8 @@
|
||||
#include <dpp/unicode_emoji.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
@ -29,16 +31,15 @@ void on_message(dpp::cluster& bot)
|
||||
|
||||
std::string str = event.msg.content;
|
||||
|
||||
unsigned int quantity;
|
||||
float price;
|
||||
std::string quantity, price;
|
||||
|
||||
get_article_data(str, quantity, price);
|
||||
|
||||
if (quantity != 0)
|
||||
embed.add_field("Quantity", std::to_string(quantity));
|
||||
if (!quantity.empty())
|
||||
embed.add_field("Quantity", quantity);
|
||||
|
||||
if (price != 0)
|
||||
embed.add_field("Price", std::to_string(price) + "€");
|
||||
if (!price.empty())
|
||||
embed.add_field("Price", price);
|
||||
|
||||
embed.set_title(str);
|
||||
|
||||
@ -49,3 +50,21 @@ void on_message(dpp::cluster& bot)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
@ -6,48 +6,50 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static float get_price(std::string& str)
|
||||
static std::string get_price(std::string& str)
|
||||
{
|
||||
std::string price;
|
||||
size_t i;
|
||||
|
||||
float price = 0;
|
||||
const char* str_c = str.c_str();
|
||||
char* next;
|
||||
|
||||
for (size_t i = 0; i != str.size(); i++)
|
||||
for (i = 0; i != str.size(); i++)
|
||||
{
|
||||
price = std::strtof(str_c + i, &next);
|
||||
if (next == NULL)
|
||||
break;
|
||||
if (std::strncmp(next, "€", 3) == 0)
|
||||
if (std::strcmp(str.substr(i, 3).c_str(), "€") == 0)
|
||||
{
|
||||
str.erase(i, next - (str_c + i) + 3);
|
||||
if (price.empty())
|
||||
{
|
||||
price = "";
|
||||
continue;
|
||||
}
|
||||
price += "€";
|
||||
str.erase(i - (price.size() - 3), price.size());
|
||||
return price;
|
||||
}
|
||||
else if (std::isdigit(str[i]) || str[i] == '.')
|
||||
price += str[i];
|
||||
}
|
||||
return 0;
|
||||
return "";
|
||||
}
|
||||
|
||||
static int get_quantity(std::string& str)
|
||||
static std::string get_quantity(std::string& str)
|
||||
{
|
||||
unsigned int quantity = 0;
|
||||
size_t len = 0, i;
|
||||
size_t i;
|
||||
std::string quantity;
|
||||
|
||||
for (i = 0; i != str.size(); i++)
|
||||
{
|
||||
if (!std::isdigit(str[i]))
|
||||
{
|
||||
if (quantity != 0)
|
||||
break;
|
||||
continue;
|
||||
if (quantity.empty())
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
quantity = quantity * 10 + str[i] - '0';
|
||||
len++;
|
||||
quantity += str[i];
|
||||
}
|
||||
str.erase(i - len, len);
|
||||
str.erase(i - quantity.size(), quantity.size());
|
||||
return quantity;
|
||||
}
|
||||
|
||||
int get_article_data(std::string& str, unsigned int& quantity, float& price)
|
||||
int get_article_data(std::string& str, std::string& quantity, std::string& price)
|
||||
{
|
||||
price = get_price(str);
|
||||
quantity = get_quantity(str);
|
||||
|
@ -2,5 +2,5 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
int get_article_data(std::string& str, unsigned int& quantity, float& price);
|
||||
int get_article_data(std::string& str, std::string& quantity, std::string& price);
|
||||
std::string get_token(char** av, char** env);
|
Reference in New Issue
Block a user