]> jfr.im git - erebus.git/commitdiff
change to use str.startswith
authorzonidjan <redacted>
Sun, 1 Oct 2017 21:29:57 +0000 (16:29 -0500)
committerzonidjan <redacted>
Sun, 1 Oct 2017 21:29:57 +0000 (16:29 -0500)
bot.py
modules/chanops.py
modules/help.py
modules/msg.py
modules/trivia.py
modules/userinfo.py

diff --git a/bot.py b/bot.py
index bdf3afcd940f936f84eb5c7d8e01e63b7fefba10..acbeba6febb2beac5e92d70699cb7b8ea6afeec8 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -146,9 +146,9 @@ class Bot(object):
                names[0] = names[0][1:] #remove colon
                for n in names:
                        user = self.parent.user(n.lstrip('@+'))
-                       if n[0] == '@':
+                       if n.startswith('@'):
                                chan.userjoin(user, 'op')
-                       elif n[0] == '+':
+                       elif n.startswith('+'):
                                chan.userjoin(user, 'voice')
                        else:
                                chan.userjoin(user)
@@ -260,25 +260,25 @@ class Bot(object):
                if len(msg) == 0:
                        return
 
-               triggerused = msg[0] == self.parent.trigger
-               if triggerused: msg = msg[1:]
+               triggerused = msg.startswith(self.parent.trigger)
+               if triggerused: msg = msg[len(self.parent.trigger):]
                pieces = msg.split()
 
                if target == self.nick:
-                       if msg[0] == "\001": #ctcp
+                       if msg.startswith("\001"): #ctcp
                                msg = msg.strip("\001")
                                if msg == "VERSION":
                                        self.msg(user, "\001VERSION Erebus v%d.%d - http://github.com/zonidjan/erebus" % (self.parent.APIVERSION, self.parent.RELEASE))
                                return
                if len(pieces) > 1:
                        chanword = pieces[1]
-                       if chanword[0] == '#':
+                       if chanword.startswith('#'):
                                chanparam = self.parent.channel(chanword)
 
                if target != self.nick: # message was sent to a channel
                        chan = self.parent.channel(target)
                        try:
-                               if msg[0] == '*': # message may be addressed to bot by "*BOTNICK" trigger?
+                               if msg.startswith('*'): # message may be addressed to bot by "*BOTNICK" trigger?
                                        if pieces[0][1:].lower() == self.nick.lower():
                                                pieces.pop(0) # command actually starts with next word
                                                msg = ' '.join(pieces) # command actually starts with next word
@@ -359,7 +359,7 @@ class Bot(object):
 
                target = str(target)
 
-               if target[0] == '#': command = "PRIVMSG %s :%s" % (target, msg)
+               if target.startswith('#'): command = "PRIVMSG %s :%s" % (target, msg)
                else: command = "NOTICE %s :%s" % (target, msg)
 
                return command
index 2e7c586a1b50a18ecdc0356614ddfd7380803a27..7d8f40ceb840b1bd9fc4dcef50f4756075d386e1 100644 (file)
@@ -27,7 +27,7 @@ def module(name):
 
 def _kick(bot, user, chan, realtarget, *args):
        people = []
-       if args[0][0] == "#":
+       if args[0].startswith("#"):
                people = bot.parent.getuserbyauth(args[0][1:])
        else:
                people = [args[0]]
index e835bc0ace7b0663fadfd880ee83b889d630f7da..770a0fb469e5f6057adeb60f53f5a009092d499a 100644 (file)
@@ -99,9 +99,9 @@ def _genhelp(bot, user, chan, realtarget, *args):
        maxlevel = 100
        filepath = bot.parent.cfg.get('help', 'path', default='./help/%d.txt')
        for arg in args:
-               if arg[0] == "@":
+               if arg.startswith("@"):
                        module = arg[1:]
-               elif arg[0] == "#" and user.glevel >= lib.OWNER:
+               elif arg.startswith("#") and user.glevel >= lib.ADMIN:
                        minlevel = maxlevel = int(arg[1:])
                else:
                        filepath = arg
@@ -182,7 +182,7 @@ def help(bot, user, chan, realtarget, *args):
                for line in sorted(lines):
                        bot.slowmsg(user, str(line))
                bot.slowmsg(user, "End of command listing.")
-       elif args[0][0] == "@":
+       elif args[0].startswith("@"):
                lines = []
                mod = args[0][1:].lower()
                for func in helps.itervalues():
index 59082468d74a3f5a612c7f0001953d5f6ea4426f..08299ae7339dce0252f94afb46edc9489564d7f6 100644 (file)
@@ -26,7 +26,7 @@ def cmsg(bot, user, chan, realtarget, *args):
 
 def _getbot(bot, user, chan, realtarget, *args):
        target = None
-       if args[0][0] == "#":
+       if args[0].startswith("#"):
                target = bot.parent.channel(args[0])
                print "target = %s" % (target)
        if target is not None:
index cb77be77d990a2388e03415ed6b0b1b1e74f8379..c03799035d2e384450195d9c3d2960710441944d 100644 (file)
@@ -294,7 +294,7 @@ class TriviaState(object):
                        nextqid = random.randrange(0, len(self.questions))
                        nextq = self.questions[nextqid]
 
-               if nextq[0][0] == "!":
+               if nextq[0].startswith("!"):
                        nextqid = None
                        nextq = specialQuestion(nextq)
 
@@ -658,7 +658,7 @@ def questionpause(bot, user, chan, realtarget, *args):
 @lib.help("<full question>", "finds a qid given a complete question")
 def findq(bot, user, chan, realtarget, *args):
        args = list(args)
-       if args[0][0] == "@":
+       if args[0].startswith("@"):
                cat = args.pop(0)[1:].lower()
                questions = state.db['questions'][cat]
        else:
@@ -681,7 +681,7 @@ def findq(bot, user, chan, realtarget, *args):
 @lib.help("[@<category>] <regex>", "finds a qid given a regex or partial question")
 def findqre(bot, user, chan, realtarget, *args):
        args = list(args)
-       if args[0][0] == "@":
+       if args[0].startswith("@"):
                cat = args.pop(0)[1:].lower()
                questions = state.db['questions'][cat]
        else:
@@ -706,7 +706,7 @@ def findqre(bot, user, chan, realtarget, *args):
 @lib.help("[@<category>] <qid>", "displays the q*a for a qid", "category defaults to current")
 def showq(bot, user, chan, realtarget, *args):
        args = list(args)
-       if args[0][0] == "@":
+       if args[0].startswith("@"):
                cat = args.pop(0)[1:].lower()
                questions = state.db['questions'][cat]
        else:
@@ -728,7 +728,7 @@ def showq(bot, user, chan, realtarget, *args):
 @lib.help("[@<category>] <qid>", "removes a question from the database")
 def delq(bot, user, chan, realtarget, *args):
        args = list(args)
-       if args[0][0] == "@":
+       if args[0].startswith("@"):
                cat = args.pop(0)[1:].lower()
                questions = state.db['questions'][cat]
        else:
@@ -745,7 +745,7 @@ def delq(bot, user, chan, realtarget, *args):
 @lib.help("[@<category>] <q>*<a>", "adds a question")
 def addq(bot, user, chan, realtarget, *args):
        args = list(args)
-       if args[0][0] == "@":
+       if args[0].startswith("@"):
                cat = args.pop(0)[1:].lower()
                questions = state.db['questions'][cat]
        else:
index be6e33be11b2b0810f97d626084c82f86752bf2c..bd150539bc023daf496ee413d7ae87abdb6cda81 100644 (file)
@@ -44,7 +44,7 @@ def getauth(thing):
                if thing.auth is not None:
                        return "#"+thing.auth
        elif isinstance(thing, basestring):
-               if thing[0] == "#":
+               if thing.startswith("#"):
                        return thing
                else:
                        if parent.user(thing).auth is not None: