Vulpes - XMPP Bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

102 lines
3.3 KiB

/*
* vim: expandtab:ts=2:sts=2:sw=2
*
* Copyright (C) 2021 DebXWoody <stefan@devlug.de>
*
* This file is part of vulpes.
*
* vulpes is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vulpes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with buteo. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mod_org.h"
#define MOD_NAME "mod_org"
#define MOD_VERSION "0.0.0-dev"
#define LOG_DOMAIN "vulpes-mod-org"
#define MOD_HELP_PREFIX "!help"
#define MOD_COMMAND_PREFIX "!org"
#define HELP_TXT "Module " MOD_NAME " - " MOD_VERSION "\n\
!org date - Zeig das aktuelle Datum\n \
!org termine - Zeit die Termine - alles nicht implementiert \n"
static void _show_help(vulpes_ctx_t *vulpes_ctx, const lutjanus_xmpp_adr_t* from, const char *const message);
static GString *_getDateAndTime();
vulpes_err_code_t module_load(vulpes_ctx_t *vulpes_ctx) {
g_log(LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Loading %s (%s)...", MOD_NAME, MOD_VERSION );
mod_api_backend_create("mod_org", "ID INTEGER PRIMARY KEY ASC, JID TEXT, TASK TEXT, DUE DATE");
return VULPES_SUCCESS;
}
vulpes_err_code_t module_unload(vulpes_ctx_t *vulpes_ctx) {
g_log(LOG_DOMAIN, G_LOG_LEVEL_INFO, "module_unload");
return VULPES_SUCCESS;
}
vulpes_err_code_t chat(vulpes_ctx_t *vulpes_ctx, const lutjanus_xmpp_adr_t* from, const char *const message) {
g_log(LOG_DOMAIN, G_LOG_LEVEL_INFO, "Incoming messsage from %s: %s", from, message);
if ( g_str_has_prefix (message, MOD_HELP_PREFIX ) ) {
_show_help(vulpes_ctx, from,message);
return VULPES_SUCCESS;
}
if ( !g_str_has_prefix (message, MOD_COMMAND_PREFIX ) ) {
return VULPES_SUCCESS;
}
gchar** tokens = g_strsplit (message," ", 5);
if (tokens[0] && tokens[1]) {
if( g_strcmp0(tokens[1], "date") == 0 ) {
GString* d = _getDateAndTime();
mod_api_send_chat_message(vulpes_ctx, from, d->str);
} else if( g_strcmp0(tokens[1], "add") == 0 ) {
g_log(LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Adding task");
if (tokens[2]) {
char* c[2];
c[0] = "JID";
c[1] = "TASK";
char* v[2];
v[0] = g_strdup_printf("\"%s\"",lutjanus_xmpp_adr_get_bare(from)->str);
v[1] = g_strdup_printf("\"%s\"", tokens[2]);
mod_api_backend_insert("mod_org", c,v, 2);
}
}
}
}
vulpes_err_code_t org_group_command_execute(vulpes_ctx_t *vulpes_ctx,
const char *const command) {
g_log(LOG_DOMAIN, G_LOG_LEVEL_INFO, "Executing org group command...");
return VULPES_SUCCESS;
}
static void _show_help(vulpes_ctx_t *vulpes_ctx, const lutjanus_xmpp_adr_t* from, const char *const message) {
mod_api_send_chat_message(vulpes_ctx, from, HELP_TXT);
}
GString *_getDateAndTime() {
GDateTime *now = g_date_time_new_now_local();
char *date = g_date_time_format(now, "%A, %d. %B %Y %R");
GString *result = g_string_new(date);
g_log(LOG_DOMAIN, G_LOG_LEVEL_INFO, "Now: %s ", result->str);
return result;
}