From 6bf2598db6ca51b79bdf5d1ea297bda7a1b2734e Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Wed, 25 Nov 2020 16:01:28 +0100 Subject: [PATCH] Create functions for is_voiced and is_oper checks In order to be able to easily mock voice and oper checks, create specific functions that implement those checks. Change-Id: I6250c0d181085ff39d6ff0dae95c700dbeb931a3 --- ptgbot/bot.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ptgbot/bot.py b/ptgbot/bot.py index 760e158..605c3a3 100644 --- a/ptgbot/bot.py +++ b/ptgbot/bot.py @@ -264,6 +264,13 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): "Cancelled subscription %s" % existing_re ) + def is_chanop(self, nick, chan): + return self.channels[chan].is_oper(nick) + + def is_voiced(self, nick, chan): + return (self.channels[chan].is_voiced(nick) or + self.channels[chan].is_oper(nick)) + @make_safe def on_pubmsg(self, c, e): if not self.identify_msg_cap: @@ -295,9 +302,8 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): self.unsubscribe(chan, nick) return - if (self.data.is_voice_required() and not - (self.channels[chan].is_voiced(nick) or - self.channels[chan].is_oper(nick))): + if (self.data.is_voice_required() and + not self.is_voiced(nick, chan)): self.send(chan, "%s: Need voice to issue commands" % (nick,)) return @@ -367,7 +373,7 @@ class PTGBot(SASL, SSL, irc.bot.SingleServerIRCBot): "scheduled today." % (nick, track)) if msg.startswith('~'): - if not self.channels[chan].is_oper(nick): + if not self.is_chanop(nick, chan): self.send(chan, "%s: Need op for admin commands" % (nick,)) return words = msg.split()