whitespace and import fixes

This commit is contained in:
Thorsten
2016-04-05 18:40:31 +02:00
parent c6baf3cf60
commit 550fa44f42
15 changed files with 43 additions and 37 deletions

View File

@@ -10,6 +10,7 @@ BUFSIZ = 8192
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) ' \ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) ' \
'Gecko/20100101 Firefox/31.0 Iceweasel/31.0' 'Gecko/20100101 Firefox/31.0 Iceweasel/31.0'
def get_version_git(): def get_version_git():
import subprocess import subprocess

View File

@@ -7,6 +7,7 @@ EVENTLOOP_DELAY = 0.100 # seconds
event_list = sched.scheduler(time.time, time.sleep) event_list = sched.scheduler(time.time, time.sleep)
def register_active_event(t, callback, args, action_runner, plugin, msg_obj): def register_active_event(t, callback, args, action_runner, plugin, msg_obj):
""" """
Execute a callback at a given time and react on the output Execute a callback at a given time and react on the output
@@ -31,9 +32,6 @@ def register_event(t, callback, args):
class EventLoop(threading.Thread): class EventLoop(threading.Thread):
#def __init__(self):
# threading.Thread.__init__(self)
def run(self): def run(self):
while 1: while 1:
event_list.run(False) event_list.run(False)

View File

@@ -1,16 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from enum import Enum from enum import Enum
import config import config
from rate_limit import RATE_GLOBAL from rate_limit import RATE_GLOBAL
class ptypes(Enum): class ptypes(Enum):
PARSE = 1 PARSE = 1
COMMAND = 2 COMMAND = 2
MUC_ONLINE = 3 MUC_ONLINE = 3
plugin_storage = {ptype: [] for ptype in ptypes} plugin_storage = {ptype: [] for ptype in ptypes}
def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled=True): def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled=True):
"""A decorator to make a plugin out of a function """A decorator to make a plugin out of a function
:param enabled: :param enabled:
@@ -55,11 +57,8 @@ def plugin_enabled_get(urlbot_plugin):
@config.config_locked @config.config_locked
def plugin_enabled_set(plugin, enabled): def plugin_enabled_set(plugin, enabled):
if plugin.plugin_name not in config.runtime_config_store['plugins']: if plugin.plugin_name not in config.runtime_config_store['plugins']:
config.runtime_config_store['plugins'][plugin.plugin_name] = {} config.runtime_config_store['plugins'][plugin.plugin_name] = {}
config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled
config.runtimeconf_persist() config.runtimeconf_persist()

View File

@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import random import random
from common import giphy
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
from rate_limit import RATE_FUN, RATE_GLOBAL from rate_limit import RATE_FUN, RATE_GLOBAL
@pluginfunction('cake', 'displays a cake ASCII art', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL) @pluginfunction('cake', 'displays a cake ASCII art', ptypes.COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
def command_cake(argv, **args): def command_cake(argv, **args):
if {'please', 'bitte'}.intersection(set(argv)): if {'please', 'bitte'}.intersection(set(argv)):

View File

@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
log = logging.getLogger(__name__)
import events import events
import json import json
@@ -13,9 +12,11 @@ import requests
from lxml import etree from lxml import etree
import config import config
from common import VERSION, giphy, get_nick_from_object from common import VERSION
from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT
from plugin_system import pluginfunction, ptypes, plugin_storage from plugin_system import pluginfunction, ptypes, plugin_storage, plugin_enabled_get, plugin_enabled_set
log = logging.getLogger(__name__)
@pluginfunction('help', 'print help for a command or all known commands', ptypes.COMMAND) @pluginfunction('help', 'print help for a command or all known commands', ptypes.COMMAND)
def command_help(argv, **args): def command_help(argv, **args):
@@ -779,6 +780,7 @@ def repeat_message(argv, **args):
'msg': args['stack'][-1]['body'] 'msg': args['stack'][-1]['body']
} }
@pluginfunction('isdown', 'check if a website is reachable', ptypes.COMMAND) @pluginfunction('isdown', 'check if a website is reachable', ptypes.COMMAND)
def isdown(argv, **args): def isdown(argv, **args):
if not argv: if not argv:
@@ -850,4 +852,3 @@ def poll(argv, **args):
@pluginfunction('vote', 'alias for poll', ptypes.COMMAND) @pluginfunction('vote', 'alias for poll', ptypes.COMMAND)
def vote(argv, **args): def vote(argv, **args):
return poll(argv, **args) return poll(argv, **args)

View File

@@ -1,17 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
log = logging.getLogger(__name__)
import time import time
import random import random
import config import config
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
log = logging.getLogger(__name__)
comment_joins_strings = [ comment_joins_strings = [
"%s: please consider to fix your internet connection" "%s: please consider to fix your internet connection"
] ]
@pluginfunction('comment_joins', 'comments frequent joins', ptypes.MUC_ONLINE) @pluginfunction('comment_joins', 'comments frequent joins', ptypes.MUC_ONLINE)
@config.config_locked @config.config_locked
def comment_joins(**args): def comment_joins(**args):
@@ -46,4 +47,3 @@ def comment_joins(**args):
user_joins.append(current_timestamp) user_joins.append(current_timestamp)
config.runtime_config_store['user_joins'][arg_user_key] = user_joins config.runtime_config_store['user_joins'][arg_user_key] = user_joins
config.runtimeconf_persist() config.runtimeconf_persist()

View File

@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
log = logging.getLogger(__name__)
import random import random
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
log = logging.getLogger(__name__)
@pluginfunction('excuse', 'prints BOFH style excuses', ptypes.COMMAND) @pluginfunction('excuse', 'prints BOFH style excuses', ptypes.COMMAND)
def command_excuse(argv, **args): def command_excuse(argv, **args):

View File

@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
log = logging.getLogger(__name__)
import re
import random
import config import config
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
log = logging.getLogger(__name__)
moin_strings_hi = [ moin_strings_hi = [
'Hi', 'Hi',
@@ -19,6 +22,7 @@ moin_strings_bye = [
'bye', 'bye',
] ]
@pluginfunction('moin', 'parse hi/bye', ptypes.PARSE, enabled=False) @pluginfunction('moin', 'parse hi/bye', ptypes.PARSE, enabled=False)
def parse_moin(**args): def parse_moin(**args):
for direction in [moin_strings_hi, moin_strings_bye]: for direction in [moin_strings_hi, moin_strings_bye]:
@@ -73,5 +77,3 @@ def command_show_moinlist(argv, **args):
]) ])
) )
} }

View File

@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
log = logging.getLogger(__name__)
import random import random
import re import re
@@ -11,6 +10,8 @@ from common import extract_title
from rate_limit import RATE_NO_SILENCE, RATE_GLOBAL, RATE_FUN, RATE_URL from rate_limit import RATE_NO_SILENCE, RATE_GLOBAL, RATE_FUN, RATE_URL
from config import runtimeconf_get from config import runtimeconf_get
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
log = logging.getLogger(__name__)
@pluginfunction('mental_ill', 'parse mental illness', ptypes.PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL) @pluginfunction('mental_ill', 'parse mental illness', ptypes.PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL)
def parse_mental_ill(**args): def parse_mental_ill(**args):

View File

@@ -9,6 +9,7 @@ import time
import config import config
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
@pluginfunction('quiz', 'play quiz', ptypes.COMMAND) @pluginfunction('quiz', 'play quiz', ptypes.COMMAND)
def quiz_control(argv, **args): def quiz_control(argv, **args):
usage = """quiz mode usage: "quiz start [secs interval:default 30]", "quiz stop", "quiz rules; usage = """quiz mode usage: "quiz start [secs interval:default 30]", "quiz stop", "quiz rules;

View File

@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import time
import config
from common import get_nick_from_object
from plugin_system import pluginfunction, ptypes
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
import time
import config
from plugin_system import pluginfunction, ptypes
@pluginfunction('send_record', 'delivers previously saved message to user', ptypes.MUC_ONLINE) @pluginfunction('send_record', 'delivers previously saved message to user', ptypes.MUC_ONLINE)
@config.config_locked @config.config_locked
@@ -35,6 +35,7 @@ def send_record(**args):
return response return response
@pluginfunction( @pluginfunction(
'record', 'record a message for a now offline user (usage: record {user} {some message};' 'record', 'record a message for a now offline user (usage: record {user} {some message};'
' {some message} == "previous" to use the last channel message)', ptypes.COMMAND) ' {some message} == "previous" to use the last channel message)', ptypes.COMMAND)
@@ -85,4 +86,3 @@ def command_show_recordlist(argv, **args):
) )
) )
} }

View File

@@ -2,12 +2,12 @@
import re import re
import shlex import shlex
import json
import requests import requests
import config import config
from plugin_system import pluginfunction, ptypes from plugin_system import pluginfunction, ptypes
@pluginfunction('translate', 'translate text fragments, use "translate show" to get a list of languages' @pluginfunction('translate', 'translate text fragments, use "translate show" to get a list of languages'
'or "translate that" to get the last message translated (to german)', ptypes.COMMAND) 'or "translate that" to get the last message translated (to german)', ptypes.COMMAND)
def translate(argv, **args): def translate(argv, **args):

View File

@@ -33,6 +33,7 @@ buckets = {
rate_limit_classes = buckets.keys() rate_limit_classes = buckets.keys()
def rate_limit(rate_class=RATE_GLOBAL): def rate_limit(rate_class=RATE_GLOBAL):
""" """
Remember N timestamps, Remember N timestamps,

View File

@@ -8,7 +8,7 @@ import time
import unittest import unittest
from collections import namedtuple from collections import namedtuple
from common import buckets, rate_limit, RATE_GLOBAL from rate_limit import RATE_GLOBAL, rate_limit, buckets
class TestEventlooper(unittest.TestCase): class TestEventlooper(unittest.TestCase):