comparison mcabber/src/commands.c @ 444:5927c3bfba13

Add /status_to command
author Mikael Berthe <mikael@lilotux.net>
date Sun, 25 Sep 2005 00:33:56 +0200
parents 63562fd409a1
children 9f4e9e9aaf08
comparison
equal deleted inserted replaced
443:d8ddb26b9c14 444:5927c3bfba13
32 #include "settings.h" 32 #include "settings.h"
33 33
34 // Commands callbacks 34 // Commands callbacks
35 static void do_roster(char *arg); 35 static void do_roster(char *arg);
36 static void do_status(char *arg); 36 static void do_status(char *arg);
37 static void do_status_to(char *arg);
37 static void do_add(char *arg); 38 static void do_add(char *arg);
38 static void do_del(char *arg); 39 static void do_del(char *arg);
39 static void do_group(char *arg); 40 static void do_group(char *arg);
40 static void do_say(char *arg); 41 static void do_say(char *arg);
41 static void do_msay(char *arg); 42 static void do_msay(char *arg);
101 cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say); 102 cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say);
102 //cmd_add("search"); 103 //cmd_add("search");
103 //cmd_add("send_auth"); 104 //cmd_add("send_auth");
104 cmd_add("set", "Set/query an option value", 0, 0, &do_set); 105 cmd_add("set", "Set/query an option value", 0, 0, &do_set);
105 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status); 106 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
107 cmd_add("status_to", "Show or set your status for one recipient",
108 COMPL_JID, COMPL_STATUS, &do_status_to);
106 109
107 // Status category 110 // Status category
108 compl_add_category_word(COMPL_STATUS, "online"); 111 compl_add_category_word(COMPL_STATUS, "online");
109 compl_add_category_word(COMPL_STATUS, "avail"); 112 compl_add_category_word(COMPL_STATUS, "avail");
110 compl_add_category_word(COMPL_STATUS, "invisible"); 113 compl_add_category_word(COMPL_STATUS, "invisible");
375 scr_RosterDown(); 378 scr_RosterDown();
376 } else 379 } else
377 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 380 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
378 } 381 }
379 382
380 static void do_status(char *arg) 383 // setstatus(recipient, arg)
384 // Set your Jabber status.
385 // - if recipient is not NULL, the status is sent to this contact only
386 // - arg must be "status message" (message is optional)
387 static void setstatus(const char *recipient, const char *arg)
381 { 388 {
382 enum imstatus st; 389 enum imstatus st;
383 int len; 390 int len;
384 char *msg; 391 char *msg;
385
386 if (!arg || (*arg == 0)) {
387 scr_LogPrint(LPRINT_NORMAL, "Your status is: %c",
388 imstatus2char[jb_getstatus()]);
389 return;
390 }
391 392
392 msg = strchr(arg, ' '); 393 msg = strchr(arg, ' ');
393 if (!msg) 394 if (!msg)
394 len = strlen(arg); 395 len = strlen(arg);
395 else 396 else
402 else if (!strncasecmp(arg, "invisible", len)) st = invisible; 403 else if (!strncasecmp(arg, "invisible", len)) st = invisible;
403 else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb; 404 else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb;
404 else if (!strncasecmp(arg, "notavail", len)) st = notavail; 405 else if (!strncasecmp(arg, "notavail", len)) st = notavail;
405 else if (!strncasecmp(arg, "free", len)) st = freeforchat; 406 else if (!strncasecmp(arg, "free", len)) st = freeforchat;
406 else { 407 else {
407 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 408 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
408 return; 409 return;
409 } 410 }
410 411
411 if (msg && st != invisible) { 412 if (msg && st != invisible) {
412 for (msg++ ; *msg && *msg == ' ' ; msg++) ; 413 for (msg++ ; *msg && *msg == ' ' ; msg++) ;
413 if (!*msg) msg = NULL; 414 if (!*msg) msg = NULL;
414 } else 415 } else
415 msg = NULL; 416 msg = NULL;
416 417
417 jb_setstatus(st, msg); 418 jb_setstatus(st, recipient, msg);
419 }
420
421 static void do_status(char *arg)
422 {
423 if (!arg || (!*arg)) {
424 scr_LogPrint(LPRINT_NORMAL, "Your status is: %c",
425 imstatus2char[jb_getstatus()]);
426 return;
427 }
428 setstatus(NULL, arg);
429 }
430
431 static void do_status_to(char *arg)
432 {
433 char *id, *st;
434 if (!arg || (*arg == 0)) {
435 scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
436 return;
437 }
438
439 // Split recipient jid, status
440 id = g_strdup(arg);
441 st = strchr(id, ' ');
442 if (!st) {
443 scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
444 g_free(id);
445 return;
446 }
447
448 *st++ = 0;
449 while (*st && *st == ' ')
450 st++;
451
452 // FIXME check id =~ jabber id
453 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", id, st);
454 setstatus(id, st);
418 } 455 }
419 456
420 static void do_add(char *arg) 457 static void do_add(char *arg)
421 { 458 {
422 char *id, *nick; 459 char *id, *nick;