Skip to content

Commit

Permalink
Check for channel operator before action
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phantium committed Jul 7, 2014
1 parent 58c6ddc commit 006f0de
Showing 1 changed file with 54 additions and 27 deletions.
81 changes: 54 additions & 27 deletions willie/modules/adminchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 006f0de

Please sign in to comment.