moved common stuff to common.py; import adjustments
This commit is contained in:
44
common.py
Normal file
44
common.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
if '__main__' == __name__:
|
||||||
|
print '''this is a library file, which is not meant to be executed'''
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
import sys, os, time
|
||||||
|
|
||||||
|
RATE_GLOBAL = 0x01
|
||||||
|
RATE_NO_SILENCE = 0x02
|
||||||
|
RATE_INTERACTIVE = 0x04
|
||||||
|
RATE_CHAT = 0x08
|
||||||
|
RATE_URL = 0x10
|
||||||
|
|
||||||
|
BUFSIZ = 8192
|
||||||
|
delay = 0.100 # seconds
|
||||||
|
|
||||||
|
basedir = '.'
|
||||||
|
if 2 == len(sys.argv): basedir = sys.argv[1]
|
||||||
|
|
||||||
|
event_files_dir = os.path.join(basedir, 'event_files')
|
||||||
|
fifo_path = os.path.join(basedir, 'cmdfifo')
|
||||||
|
|
||||||
|
def debug_enabled():
|
||||||
|
# return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def e(data):
|
||||||
|
if data:
|
||||||
|
if unicode == type(data):
|
||||||
|
return data.encode('utf8')
|
||||||
|
elif str == type(data):
|
||||||
|
return data.encode('string-escape')
|
||||||
|
else:
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
return "''"
|
||||||
|
|
||||||
|
def logger(severity, message):
|
||||||
|
# sev = ( 'err', 'warn', 'info' )
|
||||||
|
# if severity in sev:
|
||||||
|
args = (sys.argv[0], time.strftime('%Y-%m-%d.%H:%M:%S'), severity, message)
|
||||||
|
sys.stderr.write(e('%s %s %s: %s' % args) + '\n')
|
||||||
16
plugins.py
16
plugins.py
@@ -5,11 +5,9 @@ if '__main__' == __name__:
|
|||||||
print '''this is a plugin file, which is not meant to be executed'''
|
print '''this is a plugin file, which is not meant to be executed'''
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
RATE_GLOBAL = 0x01
|
import time, random
|
||||||
RATE_NO_SILENCE = 0x02
|
from local_config import conf
|
||||||
RATE_INTERACTIVE = 0x04
|
from common import *
|
||||||
RATE_CHAT = 0x08
|
|
||||||
RATE_URL = 0x10
|
|
||||||
|
|
||||||
plugins = {}
|
plugins = {}
|
||||||
plugins['parse'] = []
|
plugins['parse'] = []
|
||||||
@@ -290,11 +288,9 @@ funcs['command'] = (
|
|||||||
|
|
||||||
_dir = dir()
|
_dir = dir()
|
||||||
|
|
||||||
debug = False
|
if debug_enabled():
|
||||||
if debug:
|
|
||||||
def _chat_write(a): _logger('chat_write', a)
|
def _chat_write(a): _logger('chat_write', a)
|
||||||
def _conf(a): return 'bot'
|
def _conf(a): return 'bot'
|
||||||
def _logger(a, b): print 'logger: %s::%s' %(a, b)
|
|
||||||
def _ratelimit_exceeded(ignored=None): return False
|
def _ratelimit_exceeded(ignored=None): return False
|
||||||
def _ratelimit_touch(ignored=None): return True
|
def _ratelimit_touch(ignored=None): return True
|
||||||
|
|
||||||
@@ -302,14 +298,10 @@ if debug:
|
|||||||
except NameError: chat_write = _chat_write
|
except NameError: chat_write = _chat_write
|
||||||
try: conf
|
try: conf
|
||||||
except NameError: conf = _conf
|
except NameError: conf = _conf
|
||||||
try: logger
|
|
||||||
except NameError: logger = _logger
|
|
||||||
try: ratelimit_exceeded
|
try: ratelimit_exceeded
|
||||||
except NameError: ratelimit_exceeded = _ratelimit_exceeded
|
except NameError: ratelimit_exceeded = _ratelimit_exceeded
|
||||||
try: ratelimit_touch
|
try: ratelimit_touch
|
||||||
except NameError: ratelimit_touch = _ratelimit_touch
|
except NameError: ratelimit_touch = _ratelimit_touch
|
||||||
try: random
|
|
||||||
except NameError: import random
|
|
||||||
|
|
||||||
def register(func_type, auto=False):
|
def register(func_type, auto=False):
|
||||||
plugins[func_type] = []
|
plugins[func_type] = []
|
||||||
|
|||||||
38
urlbot.py
38
urlbot.py
@@ -1,17 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys, os, re, time, urllib, pickle, random, HTMLParser, stat
|
import sys, os, re, time, urllib, pickle, HTMLParser, stat
|
||||||
from local_config import conf, set_conf
|
from local_config import conf, set_conf
|
||||||
|
from common import *
|
||||||
BUFSIZ = 8192
|
|
||||||
delay = 0.100 # seconds
|
|
||||||
|
|
||||||
basedir = '.'
|
|
||||||
if 2 == len(sys.argv): basedir = sys.argv[1]
|
|
||||||
|
|
||||||
event_files_dir = os.path.join(basedir, 'event_files')
|
|
||||||
fifo_path = os.path.join(basedir, 'cmdfifo')
|
|
||||||
|
|
||||||
# rate limiting to 5 messages per 10 minutes
|
# rate limiting to 5 messages per 10 minutes
|
||||||
hist_ts = []
|
hist_ts = []
|
||||||
@@ -19,27 +11,6 @@ hist_flag = True
|
|||||||
|
|
||||||
parser = None
|
parser = None
|
||||||
|
|
||||||
def debug_enabled():
|
|
||||||
# return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def e(data):
|
|
||||||
if data:
|
|
||||||
if unicode == type(data):
|
|
||||||
return data.encode('utf8')
|
|
||||||
elif str == type(data):
|
|
||||||
return data.encode('string-escape')
|
|
||||||
else:
|
|
||||||
return data
|
|
||||||
else:
|
|
||||||
return "''"
|
|
||||||
|
|
||||||
def logger(severity, message):
|
|
||||||
# sev = ( 'err', 'warn', 'info' )
|
|
||||||
# if severity in sev:
|
|
||||||
args = (sys.argv[0], time.strftime('%Y-%m-%d.%H:%M:%S'), severity, message)
|
|
||||||
sys.stderr.write(e('%s %s %s: %s' % args) + '\n')
|
|
||||||
|
|
||||||
class urllib_user_agent_wrapper(urllib.FancyURLopener):
|
class urllib_user_agent_wrapper(urllib.FancyURLopener):
|
||||||
version = '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0'''
|
version = '''Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0'''
|
||||||
|
|
||||||
@@ -232,14 +203,9 @@ def get_version_git():
|
|||||||
import plugins
|
import plugins
|
||||||
|
|
||||||
plugins.chat_write = chat_write
|
plugins.chat_write = chat_write
|
||||||
plugins.conf = conf
|
|
||||||
plugins.logger = logger
|
|
||||||
plugins.ratelimit_exceeded = ratelimit_exceeded
|
plugins.ratelimit_exceeded = ratelimit_exceeded
|
||||||
plugins.ratelimit_touch = ratelimit_touch
|
plugins.ratelimit_touch = ratelimit_touch
|
||||||
|
|
||||||
plugins.random = random
|
|
||||||
plugins.time = time
|
|
||||||
|
|
||||||
plugins.register_all()
|
plugins.register_all()
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
|
|||||||
Reference in New Issue
Block a user