Commit de7c3314 authored by aLaserShark's avatar aLaserShark Committed by Svetlana Tkachenko
Browse files

removing redundant parentheses and ''' into """

parent 554c79b1
......@@ -6,3 +6,4 @@ conf
*.cfg
*.db
venv
.idea
\ No newline at end of file
......@@ -72,7 +72,7 @@ optional arguments:
if "-c" in sys.argv[1:] or "--makeconf" in sys.argv[1:]:
self.makeconf()
if os.path.isfile(self.configpath) == False:
if not os.path.isfile(self.configpath):
print("No configuration file found, running makeconf")
self.makeconf()
......@@ -82,16 +82,13 @@ optional arguments:
def start(self):
self.clients = []
for section in self.config.sections():
server_config = {}
server_config["network"] = section
server_config["version"] = self.version
server_config["confdir"] = self.directory
server_config = {"network": section, "version": self.version, "confdir": self.directory}
for item, value in self.config.items(section):
server_config[item] = value
print("%s [%s] Connecting..." % (time.strftime("%Y-%m-%d %H:%M:%S"), server_config["network"]))
self.clients.append(irc.IRC(server_config))
while(1):
while 1:
try:
asyncore.loop()
except:
......
......@@ -161,7 +161,7 @@ class PluginManager(object):
self.handlers[event] = newList
for f in destructors:
f()
if getattr(inst, "destroy", None) != None:
if getattr(inst, "destroy", None) is not None:
inst.destroy()
def loadAllPlugins(self):
......@@ -177,7 +177,7 @@ class PluginManager(object):
class IRC(asynchat.async_chat):
def handle_error(self):
'''Print a traceback when an error happens'''
"""Print a traceback when an error happens"""
traceback.print_exc()
def __init__(self, config):
......@@ -244,7 +244,7 @@ class IRC(asynchat.async_chat):
if words[1] == "433":
#There was a nick collision
self.config["nickname"] = self.config["nickname"] + "_"
self.config["nickname"] += "_"
self.sendLine("NICK " + self.config["nickname"])
elif words[1] == "422" or words[1] == "376":
......
......@@ -51,11 +51,11 @@ class Blockbot(object):
#self.lastnot = ('BBot', time.time(), 'sdkljfls')
def handle_message(self, channel, nick, message):
""" Called when a message is sent. """
# if the user is an owner, do nothing
if self.server.getPlugin('auth').isOwner(nick):
return
""" Called when a message is received """
self.msglist.insert(0, (nick, channel, message,
time.time()))
......@@ -74,7 +74,7 @@ class Blockbot(object):
# Check for flooding
if self.get_mps(user_msgs) > self.mps_limit:
if ((nick == self.nick) and (self.kick_myself == 0)):
if nick == self.nick and self.kick_myself == 0:
1
else:
self.server.doKick(channel, nick, 'flood')
......@@ -89,7 +89,7 @@ class Blockbot(object):
else:
repeats += 1
if repeats > self.repeat_limit - 1:
if ((nick == self.nick) and (self.kick_myself == 0)):
if nick == self.nick and self.kick_myself == 0:
1
else:
self.server.doKick(channel, nick, 'flood/repetition')
......@@ -102,7 +102,7 @@ class Blockbot(object):
self.msglist.remove(msg)
def get_mps(self, user_msgs):
'''Count the number of messages sent per second'''
"""Count the number of messages sent per second"""
time_range = user_msgs[0][3] - user_msgs[-1][3]
if time_range == 0:
return 1
......
......@@ -23,7 +23,7 @@
@plugin
class Help(object):
'''`help` to list commands, `help <command/plugin>` for plugin or command help.'''
"""`help` to list commands, `help <command/plugin>` for plugin or command help."""
def __init__(self, server):
self.server = server
self.commands = ["help"]
......@@ -33,19 +33,19 @@ class Help(object):
def handle_command(self, channel, user, cmd, args):
if cmd == "help":
print(args) # ['FIRST', 'SECOND']
if args == []:
if not args:
self.server.doMessage(user, "All commands can be sent in a private message to the bot, or a channel message beginning with "
+ self.server.config["comchar"] + " or " + self.server.config["nickname"] + ":")
# get command lists strings for each plugin
strings = []
for pluginName in self.server.plugins:
if self.server.plugins[pluginName].commands == []:
if not self.server.plugins[pluginName].commands:
strings.append(pluginName + ": (none)")
else:
strings.append(pluginName + ": " + ", ".join(self.server.plugins[pluginName].commands))
reply = ""
while True:
if strings == []:
if not strings:
break
nextitem = strings.pop()
if reply == "":
......@@ -66,7 +66,7 @@ class Help(object):
reply = "Error: plugin " + args[0] + " not found."
except TypeError:
reply = "Plugin " + args[0] + " has no help."
if self.server.plugins[args[0]].commands != []:
if self.server.plugins[args[0]].commands:
reply += " Commands: " + ", ".join(self.server.plugins[args[0]].commands) + "."
else:
reply += " Commands: (none)."
......
......@@ -68,12 +68,13 @@ class Info(object):
return [None, None]
def handle_message(self, channel, nick, message):
'''Handle messages not prefixed by comchar: react to things like
"""
Handle messages not prefixed by comchar: react to things like
<bob> !ask
<bot> Ask your question, include all the details.
<bot> !ask @ newbit
<bot> newbie: Ask your question, include all the details.
'''
"""
message = message.strip()
if message == "": # empty message
return
......@@ -145,7 +146,7 @@ class Info(object):
args[i] = self.badchars.sub("", args[i])
key = " ".join(args).strip(" ").lower()
if (key in self.infodb):
if key in self.infodb:
del self.infodb[key]
self.server.doMessage(channel, "Ok, I forgot what " + key + " is.")
else:
......
......@@ -49,7 +49,7 @@ class Ping_server(object):
server.handle("data", self.handle_data)
def pingServer(self):
if (self.ponged == False):
if self.ponged == False:
self.server.doQuit()
irc.IRC(self.server.config)
......
......@@ -44,15 +44,15 @@ class rpn(object):
try:
a = float(self.stack.pop()) # last
b = float(self.stack.pop()) # pre-last
if(char == "+"):
if char == "+":
self.stack.append(a + b)
elif(char == "-"):
elif char == "-":
self.stack.append(b - a)
elif(char == "^"):
elif char == "^":
self.stack.append(pow(b, a))
elif(char == "*"):
elif char == "*":
self.stack.append(a * b)
elif(char == "/"):
elif char == "/":
self.stack.append(b / a)
except Exception as e:
self.conn.reply(str(e))
......@@ -60,4 +60,5 @@ class rpn(object):
try:
self.server.doMessage(channel, user + ": " + str(self.stack[0]))
except Exception as e:
print(e)
return
......@@ -122,7 +122,7 @@ class Rss(object):
url = child.find('link').text
url = urllib.request.urlopen("http://tinyurl.com/api-create.php?url=" + url).readline().decode('utf8')
msg = url + " "
if (child.find('category') is not None):
if child.find('category') is not None:
msg += "[" + child.find('category').text + "]" + " "
msg += title
self.server.doMessage(row[2], msg)
......
......@@ -41,7 +41,7 @@ class Seen(object):
self.db_exists = os.path.isfile(self.db)
self.connection = sqlite3.connect(self.db)
self.cursor = self.connection.cursor()
if (not self.db_exists):
if not self.db_exists:
# create the db
self.cursor.execute('CREATE TABLE seen (nick text, timestamp text, network text, channel text, message text, UNIQUE ( nick, network ))')
print("[DEBUG] Database created for the first time")
......@@ -69,7 +69,7 @@ class Seen(object):
nick = args[0]
self.cursor.execute('SELECT * FROM seen WHERE nick = ? and network = ?', (nick, self.network))
info = self.cursor.fetchone()
if (info):
if info:
# ('gry', '2013-01-31 14:50:02.419198', 'gnu', '#guppy', '-seen gry')
t = time.time() - float(info[1])
......@@ -79,7 +79,7 @@ class Seen(object):
days = int(t // 86400)
time_msg = "{0} days, {1} hours, {2} minutes and {3} seconds ago".format(days, hours, minutes, seconds)
if (info[3][0] == '#'):
if info[3][0] == '#':
self.server.doMessage(channel, "%s said '%s' in %s (%s)" % (info[0], info[4], info[3], time_msg))
else:
self.server.doMessage(channel, "%s talked to me %s" % (info[0], time_msg))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment