Compare commits

...

2 Commits

Author SHA1 Message Date
6b0f99d5ad add: quantity and price 2023-10-11 17:34:20 +00:00
493c3ef47d add: pragma once to config.h 2023-10-11 15:24:29 +00:00
5 changed files with 81 additions and 5 deletions

View File

@ -5,16 +5,15 @@ PyMenu is a discord bot to create grocery list
- Add items to your list by sending a message to a channel within the `GROCERY_LIST` category. - Add items to your list by sending a message to a channel within the `GROCERY_LIST` category.
- Support for multiple lists, one for each channel. - Support for multiple lists, one for each channel.
- Easily remove items from your list by clicking on the check mark reaction. - Easily remove items from your list by clicking on the check mark reaction.
- Set prices for items.
- Specify quantities for items.
## Screenshots ## Screenshots
![](https://media.discordapp.net/attachments/501841539161522176/1161285342914170970/image.png?ex=6537be41&is=65254941&hm=3ace3096fd0a5d66cb8bfc8c744dbd79dcba84fc02cbaf7a02b01ffbcc7ed58d&=) ![](https://media.discordapp.net/attachments/501841539161522176/1161285342914170970/image.png?ex=6537be41&is=65254941&hm=3ace3096fd0a5d66cb8bfc8c744dbd79dcba84fc02cbaf7a02b01ffbcc7ed58d&=)
## Planned feature ## Planned feature
- Set prices for items.
- Specify quantities for items.
- Customize the category name. - Customize the category name.
- Add images. - Add images.
- Complete the Dockerfile for easy deployment
- Implement statistics for nerd - Implement statistics for nerd
## Requirements ## Requirements

View File

@ -1,3 +1,4 @@
#pragma once
#include <string> #include <string>
const std::string BOT_TOKEN = "token"; const std::string BOT_TOKEN = "token";

View File

@ -3,6 +3,7 @@
#include <dpp/channel.h> #include <dpp/channel.h>
#include <dpp/unicode_emoji.h> #include <dpp/unicode_emoji.h>
#include "utils.hpp"
#include "config.h" #include "config.h"
int main(int ac, char **av) int main(int ac, char **av)
@ -29,11 +30,24 @@ int main(int ac, char **av)
dpp::embed embed = dpp::embed() dpp::embed embed = dpp::embed()
.set_color(dpp::colors::sea_green) .set_color(dpp::colors::sea_green)
.set_title(event.msg.content) .set_title(event.msg.content)
//.add_field("Quantite", "1", true)
//.add_field("Prix", "3.29")
.set_author(event.msg.author.username, "", "") .set_author(event.msg.author.username, "", "")
.set_footer(dpp::embed_footer().set_text("PyMenuVersion:2.0")); .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); dpp::message msg(event.msg.channel_id, embed);
event.send(msg); event.send(msg);

57
src/utils.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <cctype>
#include <cstddef>
#include <cstring>
#include <string>
#include <iostream>
static float get_price(std::string& str)
{
float price = 0;
const char* str_c = str.c_str();
char* next;
for (size_t i = 0; i != str.size(); i++)
{
price = std::strtof(str_c + i, &next);
if (next == NULL)
break;
if (std::strncmp(next, "", 3) == 0)
{
str.erase(i, next - (str_c + i) + 3);
return price;
}
}
return 0;
}
// pain 2€ 1
static int get_quantity(std::string& str)
{
unsigned int quantity = 0;
size_t len = 0, i;
for (i = 0; i != str.size(); i++)
{
std::cout << str[i] << std::endl;
if (!std::isdigit(str[i]))
{
if (quantity != 0)
break;
continue;
}
quantity = quantity * 10 + str[i] - '0';
len++;
}
std::cout << str << std::endl;
str.erase(i - len, len);
return quantity;
}
int get_article_data(std::string& str, unsigned int& quantity, float& price)
{
price = get_price(str);
std::cout << str << std::endl;
quantity = get_quantity(str);
return 0;
}

5
src/utils.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <string>
int get_article_data(std::string& str, unsigned int& quantity, float& price);