diff --git a/src/command.c b/src/command.c index 9ae60488..26fb68c8 100644 --- a/src/command.c +++ b/src/command.c @@ -33,6 +33,7 @@ #include "util.h" #include "preferences.h" #include "prof_autocomplete.h" +#include "tinyurl.h" static gboolean _handle_command(const char * const command, const char * const inp); @@ -43,6 +44,7 @@ static gboolean _cmd_who(const char * const inp); static gboolean _cmd_ros(const char * const inp); static gboolean _cmd_connect(const char * const inp); static gboolean _cmd_msg(const char * const inp); +static gboolean _cmd_tiny(const char * const inp); static gboolean _cmd_close(const char * const inp); static gboolean _cmd_set_beep(const char * const inp); static gboolean _cmd_set_notify(const char * const inp); @@ -77,6 +79,7 @@ static struct cmd_t commands[] = { { "/help", _cmd_help }, { "/prefs", _cmd_prefs }, { "/msg", _cmd_msg }, + { "/tiny", _cmd_tiny }, { "/online", _cmd_online }, { "/quit", _cmd_quit }, { "/ros", _cmd_ros }, @@ -277,6 +280,42 @@ _cmd_msg(const char * const inp) return TRUE; } +static gboolean +_cmd_tiny(const char * const inp) +{ + char *usr = NULL; + char *msg = NULL; + + jabber_conn_status_t conn_status = jabber_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + } else { + // copy input + char inp_cpy[strlen(inp) + 1]; + strcpy(inp_cpy, inp); + + // get user + strtok(inp_cpy, " "); + usr = strtok(NULL, " "); + if ((usr != NULL) && (strlen(inp) > (6 + strlen(usr) + 1))) { + // get message + msg = strndup(inp+6+strlen(usr)+1, strlen(inp)-(6+strlen(usr)+1)); + if (msg != NULL) { + char *tinyurl = tinyurl_get(msg); + jabber_send(tinyurl, usr); + win_show_outgoing_msg("me", usr, tinyurl); + } else { + cons_show("Usage: /tiny user@host url"); + } + } else { + cons_show("Usage: /tiny user@host url"); + } + } + + return TRUE; +} + static gboolean _cmd_close(const char * const inp) { diff --git a/src/profanity.c b/src/profanity.c index 76663354..440f3b33 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -34,6 +34,7 @@ #include "command.h" #include "preferences.h" #include "contact_list.h" +#include "tinyurl.h" static void _profanity_shutdown(void); @@ -78,6 +79,7 @@ profanity_init(const int disable_tls) jabber_init(disable_tls); command_init(); contact_list_init(); + tinyurl_init(); atexit(_profanity_shutdown); } diff --git a/src/windows.c b/src/windows.c index 1d52fa64..c2d2294b 100644 --- a/src/windows.c +++ b/src/windows.c @@ -362,6 +362,7 @@ cons_help(void) cons_show("/prefs : Show current UI preferences."); cons_show("/connect user@host : Login to jabber."); cons_show("/msg user@host mesg : Send mesg to user."); + cons_show("/tiny user@host url : Send url as tinyurl"); cons_show("/close : Close a chat window."); cons_show("/who : Find out who is online."); cons_show("/ros : List all contacts."); @@ -518,10 +519,6 @@ _create_windows(void) wprintw(_cons_win, "\n"); _win_show_time(_cons_win); wprintw(_cons_win, "Type '/help' to get started.\n"); - - tinyurl_init(); - char *url = tinyurl_get("http://www.london2012.com/schedule-and-results/"); - cons_show(url); } prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);