Skip to content
Snippets Groups Projects
Commit f3f3e2f9 authored by auscompgeek's avatar auscompgeek Committed by Svetlana Tkachenko
Browse files

PEP8 E701,E231: multiple statements on one line (colon), missing whitespace...

PEP8 E701,E231: multiple statements on one line (colon), missing whitespace after ':'; slight logic cleanup in some places

Signed-off-by: default avatarGryllida A <Gryllida@GMAIL.com>
parent fb312da9
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,8 @@ class wikinews(object):
def handle_message(self, channel, nick, message):
matchesList = re.findall("\[\[(.*?)\]\]", message)
if matchesList == []: return
if matchesList == []:
return
urlsList = []
for match in matchesList:
url = "https://en.wikinews.org/w/api.php?action=query&prop=info&format=json&inprop=url&iwurl=1&titles=" + urllib.parse.quote(match)
......
......@@ -87,7 +87,8 @@ class PluginManager(object):
def event(self, eventName, *args):
eventName = eventName.lower()
if self.handlers.get(eventName, None) is None: return
if self.handlers.get(eventName, None) is None:
return
if eventName == "command":
handler = self.handlers[eventName].get(args[2].lower(), None)
......@@ -160,7 +161,8 @@ class PluginManager(object):
self.handlers[event] = newList
for f in destructors:
f()
if getattr(inst, "destroy", None) != None: inst.destroy()
if getattr(inst, "destroy", None) != None:
inst.destroy()
def loadAllPlugins(self):
plugins = [k for k in self.server.config["plugins"].split(",") if k != '']
......@@ -194,8 +196,10 @@ class IRC(asynchat.async_chat):
self.set_terminator(b"\r\n")
# check ipv6 flag (added in a recent version, may not exist)
if ('ipv6' in self.config) and self.config["ipv6"].lower().startswith("y"): stype = socket.AF_INET6
else: stype = socket.AF_INET
if ('ipv6' in self.config) and self.config["ipv6"].lower().startswith("y"):
stype = socket.AF_INET6
else:
stype = socket.AF_INET
# create socket
self.tup = socket.getaddrinfo(self.config["host"], int(self.config["port"]), stype)[0][4]
self.create_socket(stype, socket.SOCK_STREAM)
......@@ -355,7 +359,8 @@ class IRC(asynchat.async_chat):
def handle_connect(self):
self.config["ident"] = ident = self.config["ident"] if self.config["ident"] != "" else self.config["nickname"]
# pass, nick, user - http://tools.ietf.org/html/rfc1459#section-4.1
if self.config["srpass"] != "": self.sendLine("PASS " + self.config["srpass"])
if self.config["srpass"] != "":
self.sendLine("PASS " + self.config["srpass"])
self.sendLine("NICK " + self.config["nickname"])
self.sendLine("USER " + ident + " * * *")
......
......@@ -10,7 +10,8 @@ pList = {}
mList = collections.defaultdict(list)
class NoSuchPluginError(Exception): pass
class NoSuchPluginError(Exception):
pass
def plugin(cls):
......
......@@ -161,13 +161,16 @@ class Auth(object):
return
if cmd == "addowner":
if args[0].lower() in list(self.owners.keys()): return
if args[0].lower() in list(self.owners.keys()):
return
self.owners[args[0].lower()] = ['', True]
elif cmd == "addadmin":
if args[0].lower() in list(self.admins.keys()): return
if args[0].lower() in list(self.admins.keys()):
return
self.admins[args[0].lower()] = ['', True]
elif cmd == "addmod":
if args[0].lower() in list(self.mods.keys()): return
if args[0].lower() in list(self.mods.keys()):
return
self.mods[args[0].lower()] = ['', True]
elif cmd == "delowner":
if args[0].lower() in list(self.owners.keys()):
......
......@@ -96,5 +96,6 @@ class Blockbot(object):
def get_mps(self, user_msgs):
'''Count the number of messages sent per second'''
time_range = user_msgs[0][3] - user_msgs[-1][3]
if time_range == 0: return 1
else: return len(user_msgs) / time_range
if time_range == 0:
return 1
return len(user_msgs) / time_range
......@@ -34,16 +34,21 @@ class ctcp(object):
self.server.handle("message", self.handle_message)
def handle_message(self, channel, nick, message):
if message.find("\001") == -1: return
if message.find("\001") == -1:
return
message_array = message.replace("\001", "", 2).strip().lower().split()
ctcp_type = message_array[0]
if (len(message_array) > 1):
if len(message_array) > 1:
ctcp_args = " ".join(message_array[1:])
else:
ctcp_args = ""
self.prnt("CTCP typ: " + ctcp_type + " came in")
self.prnt("CTCP args: " + ctcp_args + " came in")
if ctcp_type == "version":self.server.doNotice(nick, "\001VERSION guppy " + self.server.config["version"] + "\001")
if ctcp_type == "source":self.server.doNotice(nick, "\001VERSION http://repo.or.cz/w/guppy.git\001")
if ctcp_type == "ping":self.server.doNotice(nick, "\001PING " + ctcp_args + "\001")
if ctcp_type == "time":self.server.doNotice(nick, "\001TIME " + time.strftime("%a %b %d %H:%M:%S %Y %z") + "\001")
if ctcp_type == "version":
self.server.doNotice(nick, "\001VERSION guppy " + self.server.config["version"] + "\001")
elif ctcp_type == "source":
self.server.doNotice(nick, "\001VERSION http://repo.or.cz/w/guppy.git\001")
elif ctcp_type == "ping":
self.server.doNotice(nick, "\001PING " + ctcp_args + "\001")
elif ctcp_type == "time":
self.server.doNotice(nick, "\001TIME " + time.strftime("%a %b %d %H:%M:%S %Y %z") + "\001")
......@@ -48,13 +48,15 @@ class Help(object):
if strings == []:
break
nextitem = strings.pop()
if reply == "": reply += nextitem
elif len((reply + nextitem)) > 60:
if reply == "":
reply += nextitem
elif len(reply + nextitem) > 60:
self.server.doMessage(user, reply)
reply = ""
else:
reply += "; " + nextitem
if reply != "": self.server.doMessage(user, reply)
if reply != "":
self.server.doMessage(user, reply)
reply = ""
self.server.doMessage(user, "Ask 'help plugin' for plugin help.")
else:
......
......@@ -75,10 +75,13 @@ class Info(object):
<bot> newbie: Ask your question, include all the details.
'''
message = message.strip()
if message == "": return # empty message
if (message[0] != self.plugin_trigger): return # message does not start with our trigger
if message == "": # empty message
return
if message[0] != self.plugin_trigger: # message does not start with our trigger
return
message = message[1:].strip() # work on the stuff after the trigger
if message == "": return # ignore empty messages
if message == "": # ignore empty messages
return
if message.find("@") == -1: # no nick handle
key = message.strip()
nick = ""
......@@ -86,8 +89,9 @@ class Info(object):
list = message.split("@")
key = list[0].strip()
nick = list[1].strip()
if key == "": return # ignore empty keys
k, v = self.getInfo(key) # actually get the factoid
if key == "": # ignore empty keys
return
k, v = self.getInfo(key) # actually get the factoid
if k is not None and v is not None:
if nick == "":
self.server.doMessage(channel, "%s is %s" % (k, v))
......
......@@ -47,5 +47,7 @@ class IsItUp(object):
print(code)
arr = json.loads(code)
arr['up'] = 'up' if arr['status_code'] == 1 else 'not up'
if arr['up'] == 'up':self.server.doMessage(channel, user + ': %(domain)s:%(port)s is %(up)s. Got HTTP status code %(response_code)03d from %(response_ip)s in %(response_time)f ms.' % arr)
else: self.server.doMessage(channel, user + ': %s is not up.' % arr['domain'])
if arr['up'] == 'up':
self.server.doMessage(channel, user + ': %(domain)s:%(port)s is %(up)s. Got HTTP status code %(response_code)03d from %(response_ip)s in %(response_time)f ms.' % arr)
else:
self.server.doMessage(channel, user + ': %s is not up.' % arr['domain'])
......@@ -43,7 +43,7 @@ class Rss(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 rss (id text, network text, channel text, url text)''')
self.connection.commit()
......@@ -66,7 +66,7 @@ class Rss(object):
def handle_command(self, channel, user, cmd, args):
connection = sqlite3.connect(self.db)
cursor = connection.cursor()
if (cmd == 'rss-add'):
if cmd == 'rss-add':
url = args[0]
cursor.execute('''SELECT url FROM rss WHERE network = ? and channel = ? and url = ?''', (self.network, channel, url))
if len(cursor.fetchall()) == 0:
......@@ -75,11 +75,11 @@ class Rss(object):
self.server.doMessage(channel, "Done. RSS item %s added to %s." % (url, channel))
else:
self.server.doMessage(channel, "Error: RSS item %s already exists at %s" % (url, channel))
elif (cmd == 'rss-list'):
elif cmd == 'rss-list':
cursor.execute('''SELECT url FROM rss WHERE network = ? and channel = ?''', (self.network, channel))
for my_url in cursor.fetchall():
self.server.doMessage(channel, "RSS item: " + my_url[0])
elif (cmd == 'rss-del'):
elif cmd == 'rss-del':
url = args[0]
cursor.execute('''SELECT url FROM rss WHERE network = ? and channel = ? and url = ?''', (self.network, channel, url))
if len(cursor.fetchall()) == 0:
......@@ -108,8 +108,9 @@ class Rss(object):
children = channel.findall('item')
for child in children:
feed_id = child.find('guid').text
if (feed_id == last_known_id): return
elif (bool_updated == 0):
if feed_id == last_known_id:
return
if bool_updated == 0:
# update the db
connection = sqlite3.connect(self.db)
cursor = connection.cursor()
......
......@@ -18,11 +18,13 @@ class Urltitle(object):
def handle_command(self, channel, user, cmd, args):
if cmd == "urltitle" and user != self.nick:
message = self._get_title(args[0])
if message == None: return
else: self.server.doMessage(channel, message)
if message == None:
return
self.server.doMessage(channel, message)
def url_okay(self, url):
if url in self.urls: return 0
if url in self.urls:
return 0
def _get_title(self, url):
try:
......@@ -36,5 +38,7 @@ class Urltitle(object):
if self.parse_url_titles_in_message and message.find('urltitle') == -1 and user != self.nick:
all_urls = [url for url in message.split() if url.startswith("http://") or url.startswith("https://")]
results = {self._get_title(url) for url in all_urls} # {}s are a set; only unique members
# pyflakes complains that the above is invalid syntax, but it isn't. -- auscompgeek
for url in results:
if url is not None: self.server.doMessage(channel, "%s" % (url))
if url is not None:
self.server.doMessage(channel, url)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment