From 735dda4188734ae639615bfcd87a98730842c01e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 6 Jul 2021 14:13:10 -0500 Subject: [PATCH] (purple) Remove mod perms, command warnings Since moderation commands are implemented per-protocol in libpurple (with no easy way to use with the catch-all IM_ROOM_BAN_PARTICIPANT message and corresponding command), the PERM_BAN, PERM_KICK, and a couple other moderative perms aren't afforded to the user, disabling these non-functional options in the UI. The commands can still be implemented by the libpurple plugin, though. If they aren't, purple will complain with some error message. --- protocols/purple/PurpleApp.cpp | 68 +++++++++++++++++++++++++++++++--- protocols/purple/PurpleApp.h | 2 + 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index 4af064c..32e29a9 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -371,6 +371,55 @@ PurpleApp::ImMessage(BMessage* msg) serv_reject_chat(purple_account_get_connection(account), data); break; } + case IM_ROOM_KICK_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** This protocol doesn't support kicking. " + "Send them a strongly worded e-mail.\n"); + break; + } + case IM_ROOM_BAN_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** Banning won't work with this protocol. " + "Try being mean instead.\n"); + break; + } + case IM_ROOM_UNBAN_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** You can't undo what was once done… " + "at least with this protocol.\n"); + break; + } + case IM_ROOM_MUTE_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** This protocol left the duct-tape at home― " + "we have nothing to put over their mouth!\n"); + break; + } + case IM_ROOM_UNMUTE_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** This protocol can't exactly unmute a user, let alone make " + " an omlett.\n"); + break; + } + case IM_ROOM_DEAFEN_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** This protocol doesn't support deafening, but spamming the " + "chat should be a good substitute. :^)\n"); + break; + } + case IM_ROOM_UNDEAFEN_PARTICIPANT: + { + _SendSysText(_ConversationFromMessage(msg), + "** This protocol is particularly self-concious, and prefers " + "that this person not see its chats.\n"); + break; + } case PURPLE_CHAT_COMMAND: { PurpleConversation* conv = _ConversationFromMessage(msg); @@ -410,8 +459,7 @@ PurpleApp::ImMessage(BMessage* msg) } if (status != PURPLE_CMD_STATUS_OK) { errorBody.ReplaceAll("%err%", error); - errorMsg.AddString("body", errorBody); - SendMessage(purple_conversation_get_account(conv), errorMsg); + _SendSysText(conv, errorBody.String()); } break; } @@ -446,6 +494,17 @@ PurpleApp::SendMessage(PurpleAccount* account, BMessage msg) } +void +PurpleApp::_SendSysText(PurpleConversation* conv, const char* body) +{ + BMessage msg(IM_MESSAGE); + msg.AddInt32("im_what", IM_MESSAGE_RECEIVED); + msg.AddString("chat_id", purple_conversation_get_name(conv)); + msg.AddString("body", body); + ((PurpleApp*)be_app)->SendMessage(purple_conversation_get_account(conv), msg); +} + + void PurpleApp::_GetProtocolsInfo() { @@ -1120,14 +1179,13 @@ send_user_role(PurpleConversation* conv, const char* name, if (flags & PURPLE_CBFLAGS_OP) { if (role_title.IsEmpty() == true) role_title = "Operator"; - role_perms |= PERM_KICK | PERM_BAN | PERM_MUTE | PERM_DEAFEN - | PERM_ROLECHANGE | PERM_ROOM_SUBJECT | PERM_ROOM_NAME; + role_perms |= PERM_ROOM_SUBJECT | PERM_ROOM_NAME; role_priority = 2; } if (flags & PURPLE_CBFLAGS_HALFOP) { if (role_title.IsEmpty() == true) role_title = "Moderator"; - role_perms |= PERM_KICK | PERM_MUTE | PERM_DEAFEN | PERM_ROOM_SUBJECT; + role_perms |= PERM_ROOM_SUBJECT | PERM_ROOM_NAME; role_priority = 3; } diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index 5a79e94..6e0a192 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -84,6 +84,8 @@ public: GHashList fInviteList; private: + void _SendSysText(PurpleConversation* conv, const char* text); + void _GetProtocolsInfo(); void _SaveProtocolInfo(PurplePlugin* plugin);