Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #80 from Bytespeicher/fix-pep8-styles
Browse files Browse the repository at this point in the history
Fix pep8 styles
  • Loading branch information
mkzero committed Nov 5, 2015
2 parents 6462c17 + a86f0e0 commit 6ccf16c
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 104 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cache: bundler

python:
- "2.7"
- "3.2"

before_install:
- git submodule update --init --recursive
Expand Down
72 changes: 35 additions & 37 deletions bytebot.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import sys
import re
import inspect
import json
import resource
import ssl

try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen

from bytebot_config import *
from bytebotpluginloader import ByteBotPluginLoader
from time import time
from bytebot_log import *

from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, ssl, task
from twisted.python import logfile, log
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, ssl, task
from twisted.python import logfile, log

from bytebot_config import BYTEBOT_NICK, BYTEBOT_PASSWORD, BYTEBOT_CHANNEL, \
BYTEBOT_SSL, BYTEBOT_PORT, BYTEBOT_SERVER, BYTEBOT_PLUGINS, \
BYTEBOT_LOGPATH, BYTEBOT_LOGLEVEL
from bytebotpluginloader import ByteBotPluginLoader
from bytebot_log import BytebotLogObserver, LOG_ERROR, LOG_INFO, LOG_WARN, \
LOG_DEBUG


class ByteBot(irc.IRCClient):

Expand All @@ -37,11 +28,10 @@ def registerCommand(self, name, description=''):

def connectionMade(self):
irc.IRCClient.connectionMade(self)
self.factory.plugins.run('registerCommand',
{
'irc': self
}
)
self.factory.plugins.run(
'registerCommand',
{'irc': self}
)

def connectionLost(self, reason):
irc.IRCClient.connectionLost(self, reason)
Expand Down Expand Up @@ -72,7 +62,10 @@ def privmsg(self, user, channel, msg):

if channel == self.nickname:
""" User whispering to the bot"""
self.msg(user, "I don't usually whisper back. But when I do, it's to you.")
self.msg(
user,
"I don't usually whisper back. But when I do, it's to you."
)
return

if msg.startswith(self.nickname + ":"):
Expand Down Expand Up @@ -112,10 +105,6 @@ def noticed(self, user, channel, message):
def action(self, user, channel, msg):
user = user.split("!", 1)[0]

def irc_NICK(self, prefix, params):
old_nick = prefix.split("!")[0]
new_nick = params[0]

def irc_RPL_TOPIC(self, prefix, params):
self.current_topic = params

Expand Down Expand Up @@ -151,6 +140,7 @@ def runPerDay():
self.dayCron = task.LoopingCall(runPerDay)
self.dayCron.start(86400.0)


class ByteBotFactory(protocol.ClientFactory):

def __init__(self, nickname, password, channel):
Expand Down Expand Up @@ -181,18 +171,26 @@ def clientConnectionFailed(self, connector, reason):
log_info = logfile.LogFile("bytebot.log", BYTEBOT_LOGPATH,
rotateLength=10000000, maxRotatedFiles=100)

logger_error = BytebotLogObserver(log_error,
(BYTEBOT_LOGLEVEL & ~LOG_INFO & ~LOG_DEBUG & ~LOG_WARN))
logger_info = BytebotLogObserver(log_info,
(BYTEBOT_LOGLEVEL & ~LOG_ERROR))
logger_error = BytebotLogObserver(
log_error,
(BYTEBOT_LOGLEVEL & ~LOG_INFO & ~LOG_DEBUG & ~LOG_WARN)
)
logger_info = BytebotLogObserver(
log_info,
(BYTEBOT_LOGLEVEL & ~LOG_ERROR)
)

log.addObserver(logger_error.emit)
log.addObserver(logger_info.emit)

f = ByteBotFactory(BYTEBOT_NICK, BYTEBOT_PASSWORD, BYTEBOT_CHANNEL)
if BYTEBOT_SSL == True:
reactor.connectSSL(BYTEBOT_SERVER, int(BYTEBOT_PORT), f, ssl.ClientContextFactory())
if BYTEBOT_SSL is True:
reactor.connectSSL(
BYTEBOT_SERVER,
int(BYTEBOT_PORT),
f,
ssl.ClientContextFactory()
)
else:
reactor.connectTCP(BYTEBOT_SERVER, int(BYTEBOT_PORT), f)
reactor.run()

3 changes: 2 additions & 1 deletion bytebot_log.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from twisted.python import log

LOG_DEBUG = 0b0001
LOG_INFO = 0b0010
LOG_WARN = 0b0100
LOG_ERROR = 0b1000

from twisted.python import log

class BytebotLogObserver(log.FileLogObserver):
def __init__(self, f, level=LOG_ERROR):
Expand Down
17 changes: 10 additions & 7 deletions bytebotpluginloader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from sys import exit
from twisted.internet import reactor
from bytebot_log import *
from twisted.python import log
from sys import exit
from twisted.internet import reactor
from bytebot_log import LOG_DEBUG, LOG_WARN, LOG_ERROR
from twisted.python import log


class ByteBotPluginLoader(object):
"""This class enables automatic loading and method calling for plugin
Expand Down Expand Up @@ -62,7 +63,9 @@ def run(self, fn, args={}, threaded=True):
level=LOG_DEBUG)
reactor.callInThread(method, **args)
except Exception as e:
log.msg("WARNING: An error occured while executing %s in %s with %s" %
(fn, plugin, args),
level=LOG_WARN)
log.msg(
"WARNING: An error occured while executing %s in %s " +
"with %s" % (fn, plugin, args),
level=LOG_WARN
)
log.msg("WARNING: %s" % e, level=LOG_DEBUG)
51 changes: 37 additions & 14 deletions plugins/autoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,57 @@
from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG
from twisted.python import log
from bytebot_log import LOG_INFO, LOG_WARN
from bytebot_log import LOG_INFO, LOG_WARN


class autoop(Plugin):
def onIrc_JOIN(self, irc, prefix, params):
channel = params[0]
user = prefix.split('!')[0]
if 'autoop' in BYTEBOT_PLUGIN_CONFIG.keys():
if 'hostmask' in BYTEBOT_PLUGIN_CONFIG['autoop'].keys():
if channel in BYTEBOT_PLUGIN_CONFIG['autoop']['hostmask'].keys():
if prefix in BYTEBOT_PLUGIN_CONFIG['autoop']['hostmask'][channel]:
if channel in BYTEBOT_PLUGIN_CONFIG['autoop'][
'hostmask'].keys():
if prefix in BYTEBOT_PLUGIN_CONFIG['autoop']['hostmask'][
channel]:
log.msg("Giving user %s +o on channel %s" %
(prefix, channel), level=LOG_INFO)
irc.mode(channel, True, 'o', user=user)
irc.msg(channel, "Hey, %s, it seems like you're a nice guy. Let me op you hard" % user)
if user in BYTEBOT_PLUGIN_CONFIG['autoop']['name'][channel]:
irc.msg(
channel,
"Hey, %s, it seems like you're a nice guy. Let " +
"me op you hard" % user
)
if user in BYTEBOT_PLUGIN_CONFIG['autoop']['name'][
channel]:
log.msg("Giving user %s +o on channel %s" %
(user, channel), level=LOG_INFO)
irc.mode(channel, True, 'o', user=user)
irc.msg(channel, "Hey, %s, it seems like you're a nice guy. Let me op you hard" % user)
irc.msg(
channel,
"Hey, %s, it seems like you're a nice guy. Let " +
"me op you hard" % user
)
else:
log.msg("User %s not in autoop list %s" %
(prefix, channel), level=LOG_INFO)
log.msg(
"User %s not in autoop list %s" % (
prefix, channel),
level=LOG_INFO
)
else:
log.msg("Channel name %s not in bytebot_config.py" %
channel, level=LOG_WARN)
log.msg(
"Channel name %s not in bytebot_config.py" % channel,
level=LOG_WARN
)
else:
log.msg("BYTEBOT_PLUGIN_CONFIG in bytebot_config.py has no 'hostmask' section",
level=LOG_WARN)
log.msg(
"BYTEBOT_PLUGIN_CONFIG in bytebot_config.py has no " +
"'hostmask' section",
level=LOG_WARN
)
else:
log.msg("BYTEBOT_PLUGIN_CONFIG in bytebot_config.py has no 'autoop' section",
level=LOG_WARN)
log.msg(
"BYTEBOT_PLUGIN_CONFIG in bytebot_config.py has no 'autoop' " +
"section",
level=LOG_WARN
)
14 changes: 9 additions & 5 deletions plugins/autotopic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import json
import re
from urllib import urlopen

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_STATUS_URL, BYTEBOT_TOPIC, BYTEBOT_CHANNEL
from urllib import urlopen

import json
import re

class autotopic(Plugin):

Expand All @@ -18,7 +19,7 @@ def minuteCron(self, irc):
topic = BYTEBOT_TOPIC
response = urlopen(BYTEBOT_STATUS_URL)
data = json.loads(response.read())
if data['state']['open'] == True:
if data['state']['open'] is True:
topic += u' | Space is open'
status = 'open'
else:
Expand All @@ -32,7 +33,10 @@ def minuteCron(self, irc):
old_status = "closed"

if old_status != status:
irc.topic(BYTEBOT_CHANNEL, unicode(topic).encode('utf-8', errors='replace'))
irc.topic(
BYTEBOT_CHANNEL,
unicode(topic).encode('utf-8', errors='replace')
)
irc.topic(BYTEBOT_CHANNEL)
except Exception as e:
print(e)
Expand Down
11 changes: 6 additions & 5 deletions plugins/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# -*- coding: utf-8 -*-

import time
from datetime import datetime, timedelta

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG
from icalendar import Calendar
from icalendar.prop import vDDDTypes
from datetime import date, datetime, timedelta
from pytz import utc, timezone
from urllib import urlopen
from dateutil.rrule import *
from dateutil.parser import *
from dateutil.rrule import rruleset, rrulestr
from dateutil.parser import parse

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG


class dates(Plugin):
Expand Down
8 changes: 6 additions & 2 deletions plugins/ircquestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bytebot_config import BYTEBOT_PLUGIN_CONFIG
from plugins.plugin import Plugin


class ircquestions(Plugin):
def __init__(self):
pass
Expand Down Expand Up @@ -34,8 +35,11 @@ def onPrivmsg(self, irc, msg, channel, user):

try:
question = msg.split(' ')[1]
except IndexError as e:
irc.msg(channel, "Sorry, das habe ich nicht verstanden. Versuch doch mal !help")
except IndexError:
irc.msg(
channel,
"Sorry, das habe ich nicht verstanden. Versuch doch mal !help"
)
return

if question in BYTEBOT_PLUGIN_CONFIG['ircquestions']:
Expand Down
2 changes: 1 addition & 1 deletion plugins/mensa.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def onPrivmsg(self, irc, msg, channel, user):

try:
last_mensa = irc.last_mensa
except Exception as e:
except Exception:
last_mensa = 0

if last_mensa < (time() - 60):
Expand Down
6 changes: 3 additions & 3 deletions plugins/messagelogger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import time

from plugins.plugin import Plugin
from bytebot_config import BYTEBOT_PLUGIN_CONFIG

import time

class messagelogger(Plugin):
def __init__(self):
Expand Down Expand Up @@ -36,6 +37,5 @@ def onPrivmsg(self, irc, user, channel, msg):
def onAction(self, irc, user, channel, msg):
self.log("%s: * %s %s" % (channel, user, msg))

def onIrc_Nick(self, irc):
def onIrc_Nick(self, irc, old_nick, new_nick):
self.log("%s is now know as %s" % (old_nick, new_nick))

6 changes: 4 additions & 2 deletions plugins/muschi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from plugins.plugin import Plugin
from time import time

from plugins.plugin import Plugin


class muschi(Plugin):
def __init__(self):
pass
Expand All @@ -20,7 +22,7 @@ def onPrivmsg(self, irc, msg, channel, user):

try:
last_muschi = irc.last_muschi
except Exception as e:
except Exception:
last_muschi = 0

if last_muschi < (time() - 300):
Expand Down
5 changes: 3 additions & 2 deletions plugins/parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _get_parking_status(self):
url = BYTEBOT_PLUGIN_CONFIG['parking']['url']

data = urllib2.urlopen(url, timeout=BYTEBOT_HTTP_TIMEOUT).read(
BYTEBOT_HTTP_MAXSIZE)
BYTEBOT_HTTP_MAXSIZE)

data = unicode(data, errors='ignore')

Expand Down Expand Up @@ -51,7 +51,8 @@ def onPrivmsg(self, irc, msg, channel, user):
for x in range(1, len(data)):

name = data[x][u'name'].encode('ascii', 'ignore')
occupied = int(data[x][u'belegt'].encode('ascii', 'ignore'))
occupied = int(data[x][u'belegt'].encode('ascii',
'ignore'))
spaces = int(data[x][u'maximal'].encode('ascii', 'ignore'))

if(occupied < 0):
Expand Down
Loading

0 comments on commit 6ccf16c

Please sign in to comment.