comparison mcabber/src/commands.c @ 572:afc2bd38b15c

Implement affiliations handling, add "/room whois"
author Mikael Berthe <mikael@lilotux.net>
date Sat, 03 Dec 2005 23:40:40 +0100
parents d63e6cbdc297
children 1b8e024c3a10
comparison
equal deleted inserted replaced
571:d63e6cbdc297 572:afc2bd38b15c
165 compl_add_category_word(COMPL_ROOM, "nick"); 165 compl_add_category_word(COMPL_ROOM, "nick");
166 compl_add_category_word(COMPL_ROOM, "privmsg"); 166 compl_add_category_word(COMPL_ROOM, "privmsg");
167 compl_add_category_word(COMPL_ROOM, "remove"); 167 compl_add_category_word(COMPL_ROOM, "remove");
168 compl_add_category_word(COMPL_ROOM, "topic"); 168 compl_add_category_word(COMPL_ROOM, "topic");
169 compl_add_category_word(COMPL_ROOM, "unlock"); 169 compl_add_category_word(COMPL_ROOM, "unlock");
170 compl_add_category_word(COMPL_ROOM, "whois");
170 } 171 }
171 172
172 // expandalias(line) 173 // expandalias(line)
173 // If there is one, expand the alias in line and returns a new allocated line 174 // If there is one, expand the alias in line and returns a new allocated line
174 // If no alias is found, returns line 175 // If no alias is found, returns line
1260 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (Jabber id)"); 1261 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (Jabber id)");
1261 free_arg_lst(paramlst); 1262 free_arg_lst(paramlst);
1262 return; 1263 return;
1263 } 1264 }
1264 1265
1265 jb_room_kickban(roomid, jid, NULL, 2, arg); 1266 jb_room_setaffil(roomid, jid, NULL, affil_outcast, arg);
1266 1267
1267 free_arg_lst(paramlst); 1268 free_arg_lst(paramlst);
1268 } 1269 }
1269 1270
1270 // The expected argument is a nickname 1271 // The expected argument is a nickname
1282 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)"); 1283 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)");
1283 free_arg_lst(paramlst); 1284 free_arg_lst(paramlst);
1284 return; 1285 return;
1285 } 1286 }
1286 1287
1287 jb_room_kickban(roomid, NULL, nick, 1, arg); 1288 jb_room_setaffil(roomid, NULL, nick, affil_none, arg);
1288 1289
1289 free_arg_lst(paramlst); 1290 free_arg_lst(paramlst);
1290 } 1291 }
1291 1292
1292 static void room_leave(gpointer bud, char *arg) 1293 static void room_leave(gpointer bud, char *arg)
1385 scr_LogPrint(LPRINT_NORMAL, "Unknown parameter"); 1386 scr_LogPrint(LPRINT_NORMAL, "Unknown parameter");
1386 return; 1387 return;
1387 } 1388 }
1388 1389
1389 jb_room_unlock(buddy_getjid(bud)); 1390 jb_room_unlock(buddy_getjid(bud));
1391 }
1392
1393 static void room_whois(gpointer bud, char *arg)
1394 {
1395 char **paramlst;
1396 gchar *nick, *buffer;
1397 const char *jid, *realjid;
1398 const char *rst_msg;
1399 enum imstatus rstatus;
1400 enum imrole role;
1401 enum imaffiliation affil;
1402
1403 char *strroles[] = { "none", "moderator", "participant", "visitor" };
1404 char *straffil[] = { "none", "owner", "admin", "member", "outcast" };
1405
1406 paramlst = split_arg(arg, 1, 0); // nickname
1407 nick = *paramlst;
1408
1409 if (!nick || !*nick) {
1410 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)");
1411 free_arg_lst(paramlst);
1412 return;
1413 }
1414
1415 jid = buddy_getjid(bud);
1416 rstatus = buddy_getstatus(bud, nick);
1417
1418 if (rstatus == offline) {
1419 scr_LogPrint(LPRINT_NORMAL, "No such member: %s", nick);
1420 free_arg_lst(paramlst);
1421 return;
1422 }
1423
1424 rst_msg = buddy_getstatusmsg(bud, nick);
1425 if (!rst_msg) rst_msg = "";
1426
1427 role = buddy_getrole(bud, nick);
1428 affil = buddy_getaffil(bud, nick);
1429 realjid = buddy_getrjid(bud, nick);
1430
1431 buffer = g_new(char, 128);
1432
1433 snprintf(buffer, 127, "Whois [%s]", nick);
1434 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
1435 snprintf(buffer, 127, "Status: [%c] %s", imstatus2char[rstatus],
1436 rst_msg);
1437 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
1438
1439 if (realjid) {
1440 snprintf(buffer, 127, "Real jid: <%s>", realjid);
1441 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
1442 }
1443
1444 snprintf(buffer, 127, "Role: %s", strroles[role]);
1445 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
1446 snprintf(buffer, 127, "Affiliation: %s", straffil[affil]);
1447 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
1448
1449 g_free(buffer);
1450 free_arg_lst(paramlst);
1390 } 1451 }
1391 1452
1392 static void do_room(char *arg) 1453 static void do_room(char *arg)
1393 { 1454 {
1394 char **paramlst; 1455 char **paramlst;
1444 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) 1505 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
1445 room_unlock(bud, arg); 1506 room_unlock(bud, arg);
1446 } else if (!strcasecmp(subcmd, "topic")) { 1507 } else if (!strcasecmp(subcmd, "topic")) {
1447 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) 1508 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
1448 room_topic(bud, arg); 1509 room_topic(bud, arg);
1510 } else if (!strcasecmp(subcmd, "whois")) {
1511 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
1512 room_whois(bud, arg);
1449 } else { 1513 } else {
1450 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 1514 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
1451 } 1515 }
1452 1516
1453 free_arg_lst(paramlst); 1517 free_arg_lst(paramlst);