From 006f0de67d44e2f67448aed2849d8af14df6a2f0 Mon Sep 17 00:00:00 2001 From: phantium Date: Mon, 7 Jul 2014 19:41:51 +0200 Subject: [PATCH] Check for channel operator before action Willie now checks if it has channel operator before executing any actions requiring it. If it does not have channel operator he will say: I'm not a channel operator! This check has been placed second so that it first checks if the person executing has permission to do so, had to rewrite some code for this to work. --- willie/modules/adminchannel.py | 81 ++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/willie/modules/adminchannel.py b/willie/modules/adminchannel.py index 02e192850d..d6bfe06760 100644 --- a/willie/modules/adminchannel.py +++ b/willie/modules/adminchannel.py @@ -27,12 +27,15 @@ def op(bot, trigger): Command to op users in a room. If no nick is given, willie will op the nick who sent the command """ - if bot.privileges[trigger.sender][trigger.nick] >= OP: - nick = trigger.group(2) - channel = trigger.sender - if not nick: - nick = trigger.nick - bot.write(['MODE', channel, "+o", nick]) + if bot.privileges[trigger.sender][trigger.nick] < OP: + return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") + nick = trigger.group(2) + channel = trigger.sender + if not nick: + nick = trigger.nick + bot.write(['MODE', channel, "+o", nick]) @commands('deop') @@ -41,12 +44,15 @@ def deop(bot, trigger): Command to deop users in a room. If no nick is given, willie will deop the nick who sent the command """ - if bot.privileges[trigger.sender][trigger.nick] >= OP: - nick = trigger.group(2) - channel = trigger.sender - if not nick: - nick = trigger.nick - bot.write(['MODE', channel, "-o", nick]) + if bot.privileges[trigger.sender][trigger.nick] < OP: + return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") + nick = trigger.group(2) + channel = trigger.sender + if not nick: + nick = trigger.nick + bot.write(['MODE', channel, "-o", nick]) @commands('voice') @@ -55,12 +61,15 @@ def voice(bot, trigger): Command to voice users in a room. If no nick is given, willie will voice the nick who sent the command """ - if bot.privileges[trigger.sender][trigger.nick] >= OP: - nick = trigger.group(2) - channel = trigger.sender - if not nick: - nick = trigger.nick - bot.write(['MODE', channel, "+v", nick]) + if bot.privileges[trigger.sender][trigger.nick] < OP: + return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") + nick = trigger.group(2) + channel = trigger.sender + if not nick: + nick = trigger.nick + bot.write(['MODE', channel, "+v", nick]) @commands('devoice') @@ -69,12 +78,15 @@ def devoice(bot, trigger): Command to devoice users in a room. If no nick is given, willie will devoice the nick who sent the command """ - if bot.privileges[trigger.sender][trigger.nick] >= OP: - nick = trigger.group(2) - channel = trigger.sender - if not nick: - nick = trigger.nick - bot.write(['MODE', channel, "-v", nick]) + if bot.privileges[trigger.sender][trigger.nick] < OP: + return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") + nick = trigger.group(2) + channel = trigger.sender + if not nick: + nick = trigger.nick + bot.write(['MODE', channel, "-v", nick]) @commands('kick') @@ -85,6 +97,8 @@ def kick(bot, trigger): """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 2: @@ -135,6 +149,8 @@ def ban(bot, trigger): """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 2: @@ -161,6 +177,8 @@ def unban(bot, trigger): """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 2: @@ -183,10 +201,12 @@ def unban(bot, trigger): def quiet(bot, trigger): """ This gives admins the ability to quiet a user. - The bot must be a Channel Operator for this command to work + The bot must be a Channel Operator for this command to work. """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 2: @@ -209,10 +229,12 @@ def quiet(bot, trigger): def unquiet(bot, trigger): """ This gives admins the ability to unquiet a user. - The bot must be a Channel Operator for this command to work + The bot must be a Channel Operator for this command to work. """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 2: @@ -236,11 +258,13 @@ def unquiet(bot, trigger): def kickban(bot, trigger): """ This gives admins the ability to kickban a user. - The bot must be a Channel Operator for this command to work + The bot must be a Channel Operator for this command to work. .kickban [#chan] user1 user!*@* get out of here """ if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group().split() argc = len(text) if argc < 4: @@ -268,10 +292,13 @@ def kickban(bot, trigger): def topic(bot, trigger): """ This gives ops the ability to change the topic. + The bot must be a Channel Operator for this command to work. """ purple, green, bold = '\x0306', '\x0310', '\x02' if bot.privileges[trigger.sender][trigger.nick] < OP: return + if bot.privileges[trigger.sender][bot.nick] < OP: + return bot.reply("I'm not a channel operator!") text = trigger.group(2) if text == '': return