1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-15 03:03:01 +01:00

add mod and unmod commands

This commit is contained in:
Jfreegman 2015-05-29 02:00:18 -04:00
parent 526bd02189
commit 9cd8afe90a
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
7 changed files with 130 additions and 33 deletions

View File

@ -88,12 +88,14 @@ static struct cmd_func group_commands[] = {
{ "/chatid", cmd_chatid }, { "/chatid", cmd_chatid },
{ "/ignore", cmd_ignore }, { "/ignore", cmd_ignore },
{ "/kick", cmd_kick }, { "/kick", cmd_kick },
{ "/mod", cmd_mod },
{ "/passwd", cmd_set_passwd }, { "/passwd", cmd_set_passwd },
{ "/peerlimit", cmd_set_peerlimit }, { "/peerlimit", cmd_set_peerlimit },
{ "/privacy", cmd_set_privacy }, { "/privacy", cmd_set_privacy },
{ "/rejoin", cmd_rejoin }, { "/rejoin", cmd_rejoin },
{ "/topic", cmd_set_topic }, { "/topic", cmd_set_topic },
{ "/unignore", cmd_unignore }, { "/unignore", cmd_unignore },
{ "/unmod", cmd_unmod },
#ifdef AUDIO #ifdef AUDIO
{ "/mute", cmd_mute }, { "/mute", cmd_mute },
{ "/sense", cmd_sense }, { "/sense", cmd_sense },
@ -101,17 +103,19 @@ static struct cmd_func group_commands[] = {
{ NULL, NULL }, { NULL, NULL },
}; };
#define NUM_SPECIAL_COMMANDS 9 #define NUM_SPECIAL_COMMANDS 11
static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = { static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
"/gaccept", "/gaccept",
"/group", "/group",
"/ignore", "/ignore",
"/kick", "/kick",
"/mod",
"/nick", "/nick",
"/note", "/note",
"/passwd", "/passwd",
"/topic", "/topic",
"/unignore" "/unignore",
"/unmod",
}; };
/* return true if input command is in the special_commands array. False otherwise.*/ /* return true if input command is in the special_commands array. False otherwise.*/

View File

@ -96,7 +96,7 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
switch (ret) { switch (ret) {
case 0: { case 0: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You have kicked %s from the group.", nick); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, RED, "You have kicked %s from the group.", nick);
return; return;
} }
case -1: { case -1: {
@ -110,6 +110,72 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
} }
} }
void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return;
}
const char *nick = argv[1];
int peernumber = group_get_nick_peernumber(self->num, nick);
if (peernumber == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name.");
return;
}
int ret = tox_group_set_peer_role(m, self->num, peernumber, TOX_GR_MODERATOR);
switch (ret) {
case 0: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, "You have promoted %s to moderator.", nick);
return;
}
case -1: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to promote peer to moderator");
return;
}
case -2: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to promote moderators.");
return;
}
}
}
void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return;
}
const char *nick = argv[1];
int peernumber = group_get_nick_peernumber(self->num, nick);
if (peernumber == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name.");
return;
}
int ret = tox_group_set_peer_role(m, self->num, peernumber, TOX_GR_USER);
switch (ret) {
case 0: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, "You have revoked moderator powers from %s.", nick);
return;
}
case -1: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to revoke moderator powers from %s.", nick);
return;
}
case -2: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Nice try.");
return;
}
}
}
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *passwd = NULL; const char *passwd = NULL;
@ -234,8 +300,10 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (tox_group_reconnect(m, self->num) == -1) if (tox_group_reconnect(m, self->num) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to rejoin group.");
return; return;
}
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group..."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group...");
} }

View File

@ -29,11 +29,13 @@
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
#endif /* GROUP_COMMANDS_H */ #endif /* GROUP_COMMANDS_H */

View File

@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
extern struct Winthread Winthread; extern struct Winthread Winthread;
#ifdef AUDIO #ifdef AUDIO
#define AC_NUM_GROUP_COMMANDS 32 #define AC_NUM_GROUP_COMMANDS 34
#else #else
#define AC_NUM_GROUP_COMMANDS 28 #define AC_NUM_GROUP_COMMANDS 30
#endif /* AUDIO */ #endif /* AUDIO */
/* groupchat command names used for tab completion. */ /* groupchat command names used for tab completion. */
@ -92,6 +92,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/join" }, { "/join" },
{ "/kick" }, { "/kick" },
{ "/log" }, { "/log" },
{ "/mod" },
{ "/myid" }, { "/myid" },
{ "/nick" }, { "/nick" },
{ "/note" }, { "/note" },
@ -104,6 +105,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/status" }, { "/status" },
{ "/topic" }, { "/topic" },
{ "/unignore" }, { "/unignore" },
{ "/unmod" },
{ "/whisper" }, { "/whisper" },
#ifdef AUDIO #ifdef AUDIO
@ -573,7 +575,7 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uin
} }
static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, int groupnum, uint32_t src_peernum, static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, int groupnum, uint32_t src_peernum,
uint32_t tgt_peernum, TOX_GROUP_MOD_TYPE type) uint32_t tgt_peernum, TOX_GROUP_MOD_EVENT type)
{ {
if (groupnum != self->num) if (groupnum != self->num)
return; return;
@ -587,26 +589,28 @@ static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, int groupnum, u
if (get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum) == -1) if (get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum) == -1)
return; return;
const char *eventstr = NULL; char timefrmt[TIME_STR_SIZE];
int colour = RED; get_time_str(timefrmt, sizeof(timefrmt));
switch (type) { switch (type) {
case TOX_MOD_KICK: case TOX_GROUP_MOD_EVENT_KICK:
eventstr = "kicked"; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been kicked by %s", tgt_name, src_name);
break; break;
case TOX_MOD_BAN: case TOX_GROUP_MOD_EVENT_BAN:
eventstr = "banned"; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been banned by %s", tgt_name, src_name);
break; break;
case TOX_MOD_SILENCE: case TOX_GROUP_MOD_EVENT_OBSERVER:
eventstr = "silenced"; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has been silenced by %s", tgt_name, src_name);
break;
case TOX_GROUP_MOD_EVENT_USER:
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has been user'd by %s", tgt_name, src_name);
break;
case TOX_GROUP_MOD_EVENT_MODERATOR:
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has been promoted to moderator by %s", tgt_name, src_name);
break; break;
default: default:
return; return;
} }
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, colour, "-!- %s has been %s by %s", tgt_name, eventstr, src_name);
} }
static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum, static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
@ -867,29 +871,48 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
wmove(ctx->sidebar, i + 2, 1); wmove(ctx->sidebar, i + 2, 1);
int peer = i + groupchats[self->num].side_pos; int peer = i + groupchats[self->num].side_pos;
/* TODO: Make this not poll */
pthread_mutex_lock(&Winthread.lock);
uint8_t status = tox_group_get_status(m, self->num, i);
TOX_GROUP_ROLE role = tox_group_get_role(m, self->num, i);
pthread_mutex_unlock(&Winthread.lock);
int maxlen_offset = role == TOX_GR_USER ? 2 : 3;
/* truncate nick to fit in side panel without modifying list */ /* truncate nick to fit in side panel without modifying list */
char tmpnck[TOX_MAX_NAME_LENGTH]; char tmpnck[TOX_MAX_NAME_LENGTH];
int maxlen = SIDEBAR_WIDTH - 2; int maxlen = SIDEBAR_WIDTH - maxlen_offset;
pthread_mutex_lock(&Winthread.lock); pthread_mutex_lock(&Winthread.lock);
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * TOX_MAX_NAME_LENGTH], maxlen); memcpy(tmpnck, &groupchats[self->num].peer_names[peer * TOX_MAX_NAME_LENGTH], maxlen);
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
tmpnck[maxlen] = '\0'; tmpnck[maxlen] = '\0';
/* TODO: Make this not poll */ int namecolour = WHITE;
pthread_mutex_lock(&Winthread.lock);
uint8_t status = tox_group_get_status(m, self->num, i);
pthread_mutex_unlock(&Winthread.lock);
int colour = WHITE;
if (status == TOX_GS_AWAY) if (status == TOX_GS_AWAY)
colour = YELLOW; namecolour = YELLOW;
else if (status == TOX_GS_BUSY) else if (status == TOX_GS_BUSY)
colour = RED; namecolour = RED;
wattron(ctx->sidebar, COLOR_PAIR(colour)); /* Signify roles (e.g. founder, moderator) */
const char *rolesig = "";
int rolecolour = WHITE;
if (role == TOX_GR_FOUNDER) {
rolesig = "&";
rolecolour = BLUE;
} else if (role == TOX_GR_MODERATOR) {
rolesig = "+";
rolecolour = GREEN;
}
wattron(ctx->sidebar, COLOR_PAIR(rolecolour) | A_BOLD);
wprintw(ctx->sidebar, "%s", rolesig);
wattroff(ctx->sidebar, COLOR_PAIR(rolecolour) | A_BOLD);
wattron(ctx->sidebar, COLOR_PAIR(namecolour));
wprintw(ctx->sidebar, "%s\n", tmpnck); wprintw(ctx->sidebar, "%s\n", tmpnck);
wattroff(ctx->sidebar, COLOR_PAIR(colour)); wattroff(ctx->sidebar, COLOR_PAIR(namecolour));
} }
} }

View File

@ -128,6 +128,6 @@ void on_group_nick_change(Tox *m, int groupnumber, uint32_t peernumber, const ui
void on_group_self_join(Tox *m, int groupnumber, void *userdata); void on_group_self_join(Tox *m, int groupnumber, void *userdata);
void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata); void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata);
void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum, void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum,
TOX_GROUP_MOD_TYPE type, void *userdata); TOX_GROUP_MOD_EVENT type, void *userdata);
#endif /* #define TOXIC_H */ #endif /* #define TOXIC_H */

View File

@ -293,7 +293,7 @@ void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata)
} }
void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum, void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum,
TOX_GROUP_MOD_TYPE type, void *userdata) TOX_GROUP_MOD_EVENT type, void *userdata)
{ {
size_t i; size_t i;

View File

@ -137,7 +137,7 @@ struct ToxWindow {
void(*onGroupTopicChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t); void(*onGroupTopicChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupSelfJoin)(ToxWindow *, Tox *, int); void(*onGroupSelfJoin)(ToxWindow *, Tox *, int);
void(*onGroupRejected)(ToxWindow *, Tox *, int, uint8_t); void(*onGroupRejected)(ToxWindow *, Tox *, int, uint8_t);
void(*onGroupModeration)(ToxWindow *, Tox *, int, uint32_t, uint32_t, TOX_GROUP_MOD_TYPE); void(*onGroupModeration)(ToxWindow *, Tox *, int, uint32_t, uint32_t, TOX_GROUP_MOD_EVENT);
#ifdef AUDIO #ifdef AUDIO