Permalink
Browse files

PEP8

  • Loading branch information...
1 parent 0aa1ee8 commit 20da12ca965c8f0339ed8dd3fadda8b040d1497e @mythmon committed Oct 30, 2012
View
@@ -89,7 +89,7 @@ def privmsg(self, raw_user, channel, raw_message):
try:
user, mask = raw_user.split('!', 1)
- except:
+ except ValueError:
user = raw_user
mask = ''
@@ -146,7 +146,9 @@ def dispatch(self, category, func, *args):
stop = getattr(plugin, func)(self, *args)
if stop:
break
- except:
+ except Exception:
+ # A plugin should not be able to crasht the bot.
+ # Catch and log all errors.
traceback.print_exc()
def removePlugin(self, plugin):
View
@@ -4,8 +4,6 @@
from zope.interface.exceptions import DoesNotImplement
from zope.interface.declarations import implementedBy
-from bravo.plugin import verify_plugin
-
class IPlugin(Interface):
"""Interface for a plugin.."""
@@ -155,6 +153,7 @@ def left(self, bot, channel):
def signedOn(self, bot):
pass
+
class IPopulationPlugin(IPlugin):
"""A plugin that recieves events about the population of channels."""
View
@@ -1,9 +1,7 @@
import re
import random
-from zope.interface import implements, Interface, Attribute
-
-from hamper.interfaces import *
+from hamper.interfaces import Command, ChatCommandPlugin
class Quit(ChatCommandPlugin):
@@ -22,7 +20,6 @@ def command(self, bot, comm, groups):
bot.leave(comm['channel'])
return True
-
class QuitCommand(Command):
regex = 'quit'
@@ -78,6 +75,7 @@ def command(self, bot, comm, groups):
bot.reply(comm, "Sorry, I couldn't match /{0}/."
.format(usr_regex.pattern))
+
class LetMeGoogleThatForYou(ChatCommandPlugin):
"""Link to the sarcastic letmegooglethatforyou.com."""
@@ -99,7 +97,7 @@ def roll(num, sides, add):
"""Rolls a die of sides sides, num times, sums them, and adds add"""
rolls = []
for i in range(num):
- rolls.append(random.randint(1,sides))
+ rolls.append(random.randint(1, sides))
rolls.append(add)
return rolls
@@ -125,17 +123,16 @@ def command(self, bot, com, groups):
if not sides:
sides = 6
else:
- sides = int (sides)
+ sides = int(sides)
if not add:
add = 0
else:
add = int(add)
- result = roll(num,sides,add)
- output = ""
- output += "%s: You rolled %sd%s+%s and got " %(com['user']
- , num, sides, add)
+ result = roll(num, sides, add)
+ output = '%s: You rolled %sd%s+%s and got ' % (com['user'], num,
+ sides, add)
if len(result) < 11:
# the last one is the constant to add
for die in result[:-1]:
@@ -2,8 +2,6 @@
import re
from datetime import datetime
-from zope.interface import implements
-
from hamper.interfaces import ChatPlugin
@@ -33,7 +31,7 @@ class OmgPonies(ChatPlugin):
name = 'ponies'
priority = 3
- cooldown = 30 #seconds
+ cooldown = 30 # Seconds
def setup(self, factory):
self.last_pony_time = datetime.now()
@@ -42,7 +40,7 @@ def message(self, bot, comm):
if re.match(r'.*pon(y|ies).*', comm['message'], re.I):
now = datetime.now()
since_last = now - self.last_pony_time
- since_last = since_last.seconds + 24*3600*since_last.days
+ since_last = since_last.seconds + 24 * 60 * 60 * since_last.days
if since_last >= self.cooldown:
bot.reply(comm, 'OMG!!! PONIES!!!')
@@ -1,6 +1,3 @@
-import re
-
-from zope.interface import implements
from bravo import plugin
from hamper.interfaces import Command, ChatCommandPlugin, IPlugin
@@ -22,6 +19,7 @@ def command(self, bot, comm, groups):
class ReloadPlugins(Command):
regex = r'^plugins? reload (.*)$'
+
def command(self, bot, comm, groups):
"""Reload a named plugin."""
name = groups[0]
@@ -45,6 +43,7 @@ def command(self, bot, comm, groups):
class LoadPlugin(Command):
regex = r'^plugins? load (.*)$'
+
def command(self, bot, comm, groups):
"""Load a named plugin."""
name = groups[0]
@@ -64,6 +63,7 @@ def command(self, bot, comm, groups):
class UnloadPlugin(Command):
regex = r'^plugins? unload (.*)$'
+
def command(self, bot, comm, groups):
"""Unload a named plugin."""
name = groups[0]
@@ -35,7 +35,7 @@ def setup(self, *args):
evens.append((resp, 1))
else:
div = int(sp[1])
- evens.append((resp, 1.0/div))
+ evens.append((resp, 1.0 / div))
else:
real_resp.append((resp, prob))
@@ -45,7 +45,7 @@ def setup(self, *args):
# probability of a "eq/2" probability.
share = (1 - total_prob) / sum(div for _, div in evens)
for resp, divisor in evens:
- real_resp.append((resp, share*divisor))
+ real_resp.append((resp, share * divisor))
self.responses = real_resp
View
@@ -1,15 +1,9 @@
from datetime import datetime
import random
-from zope.interface import implements
from sqlalchemy import Integer, String, Date, Column
from sqlalchemy.ext.declarative import declarative_base
-try:
- import sqlalchemy
-except RuntimeWarning:
- pass
-
from hamper.interfaces import Command, ChatCommandPlugin
@@ -28,6 +22,7 @@ def setup(self, factory):
class DeliverQuote(Command):
"""Deliver a quote."""
regex = r'^quotes?$'
+
def command(self, bot, comm, groups):
index = random.randrange(0, bot.db.query(Quote).count() + 1)
quote = bot.factory.db.query(Quote)[index]
@@ -38,6 +33,7 @@ def command(self, bot, comm, groups):
class AddQuote(Command):
"""Add a quote."""
regex = r'^quotes? --add (.*)$'
+
def command(self, bot, comm, groups):
text = groups[0]
quote = Quote(text, comm['user'])
@@ -47,6 +43,7 @@ def command(self, bot, comm, groups):
class CountQuotes(Command):
"""Count how many quotes the bot knows."""
regex = r'^quotes? --count$'
+
def command(self, bot, comm, groups):
count = bot.db.query(Quote).count()
bot.reply(comm, 'I know {0} quotes.'.format(count))
View
@@ -1,6 +1,6 @@
-from zope.interface import implements, Interface, Attribute
+from hamper.interfaces import (ChatCommandPlugin, PresencePlugin,
+ PopulationPlugin)
-from hamper.interfaces import *
class Test(ChatCommandPlugin, PresencePlugin, PopulationPlugin):
name = "test"
View
@@ -1,7 +1,4 @@
-#!/usr/bin/env python2
-
-import sys
-import yaml
+#!/usr/bin/env python
from hamper.commander import main

0 comments on commit 20da12c

Please sign in to comment.