diff --git a/src/bot/handlers.c b/src/bot/handlers.c index f566e77..14e2a1e 100644 --- a/src/bot/handlers.c +++ b/src/bot/handlers.c @@ -49,6 +49,7 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + unsigned int lastId; xmpp_stanza_t *reply, *body, *text; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; GString *intext; @@ -71,11 +72,14 @@ body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); - replytext = g_string_new(strdup(intext->str)); // compatible with glib versions < 2.86, g_string_copy undefined + replytext = g_string_new(NULL); + + /* parse and store the message */ if(grammar_parse_string(intext) == 0) { - g_string_append(replytext, " -> Parse OK!\n"); + lastId = (bot_get_last_expense())->id; + g_string_printf(replytext, "OK! Ho salvato l'ultima spesa, id: %u\n", lastId); } else { - g_string_append(replytext, " -> Parse ERROR :(\n"); + g_string_printf(replytext, "Stavo rosicchiando una ghianda e non ho capito. Che vuol dire \"%s\"?\n%s\n", intext->str, HELPTEXT); } text = xmpp_stanza_new(ctx); diff --git a/src/bot/handlers.h b/src/bot/handlers.h index 8675f8a..b19438d 100644 --- a/src/bot/handlers.h +++ b/src/bot/handlers.h @@ -9,6 +9,15 @@ #include #include "../../build/expenses/expenses.tab.h" +#define HELPTEXT "---\n\ +Comandi:\n\ +Per registrare una spesa:\n<-|out|spesa> \"\"\n\ +Per registrare un ricavo:\n<+|in|ricavo> \"\"\n\ +\n\ +Esempi:\n\ ++10000.99 ele \"Sono ricca!\"\n\ +out 5000 ele \"Oh no le tasse\"" + /* respond to version queries */ int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata);