2014-09-28 18:03:08 +02:00
#!/usr/bin/python3
2014-09-27 03:40:27 +02:00
# -*- coding: utf-8 -*-
if ' __main__ ' == __name__ :
2014-09-28 18:03:08 +02:00
print ( ''' this is a plugin file, which is not meant to be executed ''' )
2014-09-27 03:40:27 +02:00
exit ( - 1 )
2014-10-13 18:23:51 +02:00
import time , random , unicodedata
2014-09-27 09:19:46 +02:00
from local_config import conf
from common import *
2014-09-27 03:40:27 +02:00
2014-09-29 19:15:00 +02:00
joblist = [ ]
2014-09-27 05:32:35 +02:00
plugins = { }
plugins [ ' parse ' ] = [ ]
plugins [ ' command ' ] = [ ]
2014-10-29 13:01:32 +01:00
def get_reply_data ( data , field = 0 ) :
2014-09-27 03:40:27 +02:00
# FIXME: we can't determine if a user named 'foo> ' just wrote ' > bar'
# or a user 'foo' just wrote '> > bar'
2014-10-29 13:01:32 +01:00
f = data . split ( ' ' )
if 0 == field :
return f [ 0 ] . strip ( ' <> ' )
else :
if field > len ( f ) :
return None
return f [ field ]
2014-09-27 03:40:27 +02:00
2014-09-29 19:15:00 +02:00
def register_event ( t , callback , args ) :
joblist . append ( ( t , callback , args ) )
2014-09-27 03:40:27 +02:00
def parse_mental_ill ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
' name ' : ' parse mental illness ' ,
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_NO_SILENCE | RATE_GLOBAL
}
2014-09-27 03:40:27 +02:00
min_ill = 3
c = 0
flag = False
# return True for min_ill '!' in a row
for d in args [ ' data ' ] :
if ' ! ' == d or ' ? ' == d :
c + = 1
else :
c = 0
if ( min_ill < = c ) :
flag = True
break
if True == flag :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent mental illness reply ' )
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:32:35 +02:00
' msg ' : ''' Multiple exclamation/question marks are a sure sign of mental disease, with %s as a living example. ''' % args [ ' reply_user ' ]
2014-09-27 03:40:27 +02:00
}
def parse_skynet ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:32:35 +02:00
' name ' : ' parse skynet ' ,
' args ' : ( ' data ' , ) ,
2014-09-27 03:40:27 +02:00
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 05:32:35 +02:00
if ' skynet ' in args [ ' data ' ] . lower ( ) :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent skynet reply ' )
2014-09-27 05:32:35 +02:00
return {
' msg ' : ''' I ' m an independent bot and have nothing to do with other artificial intelligence systems! '''
}
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
def data_parse_other ( data ) :
2014-10-29 13:01:32 +01:00
reply_user = get_reply_data ( data )
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
for p in plugins [ ' parse ' ] :
if ratelimit_exceeded ( p [ ' ratelimit_class ' ] ) :
continue
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
args = { }
2014-09-27 03:40:27 +02:00
2014-09-28 18:03:08 +02:00
if ' args ' in list ( p . keys ( ) ) :
2014-09-27 05:32:35 +02:00
for a in p [ ' args ' ] :
if None == a : continue
if ' data ' == a :
args [ ' data ' ] = data
elif ' reply_user ' == a :
args [ ' reply_user ' ] = reply_user
else :
2014-10-20 07:46:05 +02:00
logger ( ' warn ' , ' unknown required arg for %s : %s ' % ( p [ ' name ' ] , a ) )
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
ret = p [ ' func ' ] ( args )
if None != ret :
2014-09-28 18:03:08 +02:00
if ' msg ' in list ( ret . keys ( ) ) :
2014-09-27 05:51:18 +02:00
ratelimit_touch ( RATE_CHAT )
2014-09-27 03:40:27 +02:00
chat_write ( ret [ ' msg ' ] )
2014-09-27 16:06:26 +02:00
def command_command ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
2014-09-27 03:40:27 +02:00
return {
2014-09-27 16:06:26 +02:00
' name ' : ' command ' ,
' desc ' : ' lists commands ' ,
' args ' : ( ' data ' , ' reply_user ' , ' cmd_list ' ) ,
2014-09-27 03:40:27 +02:00
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 05:32:35 +02:00
if ' command ' in args [ ' data ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent command list ' )
2014-09-27 05:32:35 +02:00
return {
2014-09-27 16:06:26 +02:00
' msg ' : args [ ' reply_user ' ] + ' : known commands: ' + str ( args [ ' cmd_list ' ] ) . strip ( ' [] ' )
}
def command_help ( args ) :
if ' register ' == args :
return {
' name ' : ' help ' ,
' desc ' : ' print help for a command ' ,
' args ' : ( ' data ' , ' reply_user ' , ' cmd_list ' ) ,
' ratelimit_class ' : RATE_GLOBAL
}
cmd = None
flag = False
for word in args [ ' data ' ] . split ( ) :
if True == flag :
cmd = word
break
if ' help ' == word :
flag = True
2014-09-27 16:15:01 +02:00
if False == flag : # no match on 'help'
return None
2014-09-27 16:06:26 +02:00
if None == cmd :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' empty help request ' )
2014-09-27 16:06:26 +02:00
return {
' msg ' : args [ ' reply_user ' ] + ' : no command given '
}
if not cmd in [ p [ ' name ' ] for p in plugins [ ' command ' ] ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' no help found for %s ' % cmd )
2014-09-27 16:06:26 +02:00
return {
' msg ' : args [ ' reply_user ' ] + ' : no such command: %s ' % cmd
2014-09-27 05:32:35 +02:00
}
2014-09-27 16:06:26 +02:00
for p in plugins [ ' command ' ] :
if cmd == p [ ' name ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent help for %s ' % cmd )
2014-09-27 16:06:26 +02:00
return {
' msg ' : args [ ' reply_user ' ] + ' : help for %s : %s ' % ( cmd , p [ ' desc ' ] )
}
2014-09-27 03:40:27 +02:00
def command_version ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
2014-09-27 03:40:27 +02:00
return {
2014-09-27 16:06:26 +02:00
' name ' : ' version ' ,
' desc ' : ' prints version ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
2014-09-27 03:40:27 +02:00
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 05:32:35 +02:00
if ' version ' in args [ ' data ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent version string ' )
2014-09-27 05:32:35 +02:00
return {
2014-09-27 09:41:29 +02:00
' msg ' : args [ ' reply_user ' ] + ( ''' : I ' m running ''' + VERSION )
2014-09-27 05:32:35 +02:00
}
2014-09-27 03:40:27 +02:00
def command_unicode ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
2014-09-27 16:06:26 +02:00
' name ' : ' unikot ' ,
' desc ' : ' prints an unicode string ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 03:40:27 +02:00
if ' unikot ' in args [ ' data ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent some unicode ' )
2014-09-27 03:40:27 +02:00
return {
' msg ' :
2014-09-27 16:20:34 +02:00
(
2014-09-28 18:03:08 +02:00
args [ ' reply_user ' ] + ''' : ┌────────┐ ''' ,
args [ ' reply_user ' ] + ''' : │Unicode!│ ''' ,
args [ ' reply_user ' ] + ''' : └────────┘ '''
2014-09-27 16:20:34 +02:00
)
2014-09-27 03:40:27 +02:00
}
def command_source ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
2014-09-27 03:40:27 +02:00
return {
2014-09-27 16:06:26 +02:00
' name ' : ' source ' ,
' desc ' : ' prints git URL ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
2014-09-27 03:40:27 +02:00
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 05:32:35 +02:00
if ' source ' in args [ ' data ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent source URL ' )
2014-09-27 05:32:35 +02:00
return {
' msg ' : ' My source code can be found at %s ' % conf ( ' src-url ' )
}
2014-09-27 03:40:27 +02:00
def command_dice ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
2014-09-27 16:06:26 +02:00
' name ' : ' dice ' ,
' desc ' : ' rolls a dice ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_INTERACTIVE
}
2014-09-27 03:40:27 +02:00
if ' dice ' in args [ ' data ' ] :
if args [ ' reply_user ' ] in conf ( ' enhanced-random-user ' ) :
rnd = 0 # this might confuse users. good.
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent random (enhanced) ' )
2014-09-27 03:40:27 +02:00
else :
rnd = random . randint ( 1 , 6 )
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent random ' )
2014-09-27 03:40:27 +02:00
2014-09-28 18:03:08 +02:00
dice_char = [ ' ◇ ' , ' ⚀ ' , ' ⚁ ' , ' ⚂ ' , ' ⚃ ' , ' ⚄ ' , ' ⚅ ' ]
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:32:35 +02:00
' msg ' : ' rolling a dice for %s : %s ( %d ) ' % ( args [ ' reply_user ' ] , dice_char [ rnd ] , rnd )
2014-09-27 03:40:27 +02:00
}
def command_uptime ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
2014-09-27 16:06:26 +02:00
' name ' : ' uptime ' ,
' desc ' : ' prints uptime ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 03:40:27 +02:00
if ' uptime ' in args [ ' data ' ] :
2014-09-27 05:59:35 +02:00
u = int ( conf ( ' uptime ' ) + time . time ( ) )
2014-09-27 03:40:27 +02:00
plural_uptime = ' s '
plural_request = ' s '
if 1 == u : plural_uptime = ' '
2014-09-27 06:07:44 +02:00
if 1 == conf ( ' request_counter ' ) : plural_request = ' '
2014-09-27 03:40:27 +02:00
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent statistics ' )
2014-09-27 03:40:27 +02:00
return {
2014-09-27 06:07:44 +02:00
' msg ' : args [ ' reply_user ' ] + ( ''' : happily serving for %d second %s , %d request %s so far. ''' % ( u , plural_uptime , conf ( ' request_counter ' ) , plural_request ) )
2014-09-27 03:40:27 +02:00
}
def command_ping ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
2014-09-27 16:06:26 +02:00
' name ' : ' ping ' ,
' desc ' : ' sends pong ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_INTERACTIVE
}
2014-09-27 03:40:27 +02:00
if ' ping ' in args [ ' data ' ] :
rnd = random . randint ( 0 , 3 ) # 1:4
if 0 == rnd :
msg = args [ ' reply_user ' ] + ''' : peng (You ' re dead now.) '''
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent pong (variant) ' )
2014-09-27 03:40:27 +02:00
elif 1 == rnd :
msg = args [ ' reply_user ' ] + ''' : I don ' t like you, leave me alone. '''
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent pong (dontlike) ' )
2014-09-27 03:40:27 +02:00
else :
msg = args [ ' reply_user ' ] + ''' : pong '''
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent pong ' )
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:32:35 +02:00
' msg ' : msg
2014-09-27 03:40:27 +02:00
}
def command_info ( args ) :
2014-09-27 05:32:35 +02:00
if ' register ' == args :
return {
2014-09-27 16:06:26 +02:00
' name ' : ' info ' ,
' desc ' : ' prints info message ' ,
2014-09-27 05:32:35 +02:00
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_GLOBAL
}
2014-09-27 03:40:27 +02:00
if ' info ' in args [ ' data ' ] :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent long info ' )
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:56:39 +02:00
' msg ' : args [ ' reply_user ' ] + ( ''' : I ' m a bot, my job is to extract <title> tags from posted URLs. In case I ' m annoying or for further questions, please talk to my master %s . I ' m rate limited and shouldn ' t post more than %d messages per %d seconds. To make me exit immediately, highlight me with ' hangup ' in the message (emergency only, please). For other commands, highlight me with ' command ' . ''' % ( conf ( ' bot_owner ' ) , conf ( ' hist_max_count ' ) , conf ( ' hist_max_time ' ) ) )
2014-09-27 03:40:27 +02:00
}
2014-09-29 19:15:00 +02:00
def command_teatimer ( args ) :
if ' register ' == args :
return {
' name ' : ' teatimer ' ,
2014-10-29 13:01:32 +01:00
' desc ' : ' sets a tea timer to $1 or currently %d seconds ' % conf ( ' tea_steep_time ' ) ,
2014-10-29 13:05:23 +01:00
' args ' : ( ' reply_user ' , ' argv0 ' , ' argv1 ' ) ,
2014-09-29 19:15:00 +02:00
' ratelimit_class ' : RATE_GLOBAL
}
2014-10-29 13:05:23 +01:00
if ' teatimer ' == args [ ' argv0 ' ] :
2014-10-29 13:01:32 +01:00
steep = conf ( ' tea_steep_time ' )
if None != args [ ' argv1 ' ] :
try :
steep = int ( args [ ' argv1 ' ] )
except Exception as e :
return {
' msg ' : args [ ' reply_user ' ] + ' : error when parsing int( %s ): %s ' % (
args [ ' argv1 ' ] , str ( e )
)
}
ready = time . time ( ) + steep
2014-09-29 19:15:00 +02:00
logger ( ' plugin ' , ' tea timer set to %s ' % time . strftime ( ' %F . % T ' , time . localtime ( ready ) ) )
register_event ( ready , chat_write , args [ ' reply_user ' ] + ' : Your tea is ready! ' )
return {
' msg ' : args [ ' reply_user ' ] + ' : Tea timer set to %s ' % time . strftime (
' %F . % T ' , time . localtime ( ready )
)
}
2014-10-13 18:23:51 +02:00
def command_decode ( args ) :
if ' register ' == args :
return {
' name ' : ' decode ' ,
' desc ' : ' prints the long description of an unicode character ' ,
' args ' : ( ' data ' , ' reply_user ' ) ,
' ratelimit_class ' : RATE_GLOBAL
}
if not ' decode ' in args [ ' data ' ] :
return
d = args [ ' data ' ] . split ( )
if 4 == len ( d ) :
char = d [ 3 ] [ 0 ]
2014-10-14 16:38:12 +02:00
char_esc = str ( char . encode ( ' unicode_escape ' ) ) [ 3 : - 1 ]
2014-10-13 18:23:51 +02:00
logger ( ' plugin ' , ' decode called for %s ' % char )
try :
uni_name = unicodedata . name ( char )
2014-10-20 07:46:05 +02:00
except Exception as e :
2014-10-13 18:23:51 +02:00
logger ( ' plugin ' , ' decode( %s ) failed: %s ' % ( char , str ( e ) ) )
return {
2014-10-14 16:38:12 +02:00
' msg ' : args [ ' reply_user ' ] + " : can ' t decode %s ( %s ): %s " % ( char , char_esc , str ( e ) )
2014-10-13 18:23:51 +02:00
}
return {
2014-10-14 16:38:12 +02:00
' msg ' : args [ ' reply_user ' ] + ' : %s ( %s ) is called " %s " ' % ( char , char_esc , uni_name )
2014-10-13 18:23:51 +02:00
}
else :
return {
' msg ' : args [ ' reply_user ' ] + ' : usage: decode { single character} '
}
#def command_dummy(args):
# if 'register' == args:
# return {
# 'name': 'dummy',
# 'desc': 'dummy description',
# 'args': ('data', 'reply_user'),
# 'ratelimit_class': RATE_GLOBAL
# }
#
# if 'dummy' in args['data']:
# logger('plugin', 'dummy plugin called')
#
# return {
# 'msg': args['reply_user'] + ': dummy plugin called'
# }
2014-09-27 03:40:27 +02:00
def command_else ( args ) :
2014-09-28 22:44:42 +02:00
logger ( ' plugin ' , ' sent short info ' )
2014-09-27 03:40:27 +02:00
return {
2014-09-27 05:32:35 +02:00
' msg ' : args [ ' reply_user ' ] + ''' : I ' m a bot (highlight me with ' info ' for more information). '''
2014-09-27 03:40:27 +02:00
}
2014-09-27 05:32:35 +02:00
def data_parse_commands ( data ) :
2014-09-27 03:40:27 +02:00
words = data . split ( ' ' )
if 2 > len ( words ) : # need at least two words
return None
# don't reply if beginning of the text matches bot_user
2014-09-27 05:51:18 +02:00
if not words [ 1 ] . startswith ( conf ( ' bot_user ' ) ) :
2014-09-27 03:40:27 +02:00
return None
if ' hangup ' in data :
chat_write ( ' ' , prefix = ' /quit ' )
logger ( ' warn ' , ' received hangup: ' + data )
return None
2014-10-29 13:01:32 +01:00
reply_user = get_reply_data ( data )
2014-10-29 13:05:23 +01:00
argv0 = get_reply_data ( data , field = 2 )
argv1 = get_reply_data ( data , field = 3 )
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
for p in plugins [ ' command ' ] :
if ratelimit_exceeded ( p [ ' ratelimit_class ' ] ) :
continue
args = { }
2014-09-28 18:03:08 +02:00
if ' args ' in list ( p . keys ( ) ) :
2014-09-27 05:32:35 +02:00
for a in p [ ' args ' ] :
if None == a : continue
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
if ' data ' == a :
args [ ' data ' ] = data
2014-09-27 16:06:26 +02:00
elif ' cmd_list ' == a :
cmds = [ c [ ' name ' ] for c in plugins [ ' command ' ] ]
cmds . sort ( )
args [ ' cmd_list ' ] = cmds
2014-09-27 05:32:35 +02:00
elif ' reply_user ' == a :
args [ ' reply_user ' ] = reply_user
2014-10-29 13:05:23 +01:00
elif ' argv0 ' == a :
args [ ' argv0 ' ] = argv0
2014-10-29 13:01:32 +01:00
elif ' argv1 ' == a :
args [ ' argv1 ' ] = argv1
2014-09-27 05:32:35 +02:00
else :
2014-10-20 07:46:05 +02:00
logger ( ' warn ' , ' unknown required arg for %s : %s ' % ( p [ ' name ' ] , a ) )
2014-09-27 03:40:27 +02:00
2014-09-27 05:32:35 +02:00
ret = p [ ' func ' ] ( args )
if None != ret :
2014-09-28 18:03:08 +02:00
if ' msg ' in list ( ret . keys ( ) ) :
if str == type ( ret [ ' msg ' ] ) : # FIXME 2to3
2014-09-27 16:20:34 +02:00
ratelimit_touch ( RATE_CHAT )
2014-09-28 18:03:08 +02:00
if ratelimit_exceeded ( RATE_CHAT ) :
return False
2014-09-27 16:20:34 +02:00
chat_write ( ret [ ' msg ' ] )
else :
for line in ret [ ' msg ' ] :
ratelimit_touch ( RATE_CHAT )
2014-09-28 18:03:08 +02:00
if ratelimit_exceeded ( RATE_CHAT ) :
return False
2014-09-27 16:20:34 +02:00
chat_write ( line )
2014-09-27 16:06:26 +02:00
return None
2014-09-27 03:40:27 +02:00
ret = command_else ( { ' reply_user ' : reply_user } )
if None != ret :
if ratelimit_exceeded ( RATE_GLOBAL ) :
return False
2014-09-28 18:03:08 +02:00
if ' msg ' in list ( ret . keys ( ) ) :
2014-09-27 03:40:27 +02:00
chat_write ( ret [ ' msg ' ] )
2014-09-27 05:32:35 +02:00
funcs = { }
funcs [ ' parse ' ] = ( parse_mental_ill , parse_skynet )
funcs [ ' command ' ] = (
2014-09-27 16:06:26 +02:00
command_command , command_help , command_version , command_unicode ,
2014-09-29 19:15:00 +02:00
command_source , command_dice , command_uptime , command_ping , command_info ,
2014-10-13 18:23:51 +02:00
command_teatimer , command_decode
2014-09-27 05:32:35 +02:00
)
_dir = dir ( )
2014-09-27 09:19:46 +02:00
if debug_enabled ( ) :
2014-09-27 16:06:26 +02:00
def _chat_write ( a ) : logger ( ' chat_write ' , a )
2014-09-27 05:32:35 +02:00
def _conf ( a ) : return ' bot '
def _ratelimit_exceeded ( ignored = None ) : return False
2014-09-27 05:51:18 +02:00
def _ratelimit_touch ( ignored = None ) : return True
2014-09-27 05:32:35 +02:00
try : chat_write
except NameError : chat_write = _chat_write
try : conf
except NameError : conf = _conf
try : ratelimit_exceeded
except NameError : ratelimit_exceeded = _ratelimit_exceeded
2014-09-27 05:51:18 +02:00
try : ratelimit_touch
except NameError : ratelimit_touch = _ratelimit_touch
2014-09-27 05:32:35 +02:00
2014-09-27 16:06:26 +02:00
logger ( ' info ' , ' debugging enabled ' )
2014-09-27 05:32:35 +02:00
def register ( func_type , auto = False ) :
plugins [ func_type ] = [ ]
if auto :
# FIXME: this is broken. dir() returns str, but not
# the addr of the functions which we'd need here.
for f in _dir :
2014-09-28 18:03:08 +02:00
print ( ' testing( %s ) ' % f )
2014-09-27 05:32:35 +02:00
if not f . startswith ( func_type + ' _ ' ) :
continue
try :
ret = f ( ' register ' )
ret [ ' func ' ] = f
plugins [ func_type ] . append ( ret )
except Exception as e :
logger ( ' warn ' , ' auto-registering %s failed: %s ' % ( f , e ) )
else :
for f in funcs [ func_type ] :
ret = f ( ' register ' )
ret [ ' func ' ] = f
plugins [ func_type ] . append ( ret )
def register_all ( ) :
register ( ' parse ' )
register ( ' command ' )
2014-09-29 19:15:00 +02:00
def event_trigger ( ) :
if 0 == len ( joblist ) :
return
now = time . time ( )
i = 0
for ( t , callback , args ) in joblist :
if t < now :
callback ( args )
del ( joblist [ i ] )
i + = 1