1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

add URL blacklist; add command_show_blacklist()

This commit is contained in:
urlbot
2014-11-28 19:13:45 +01:00
parent 368469ec7d
commit 31f1e285c6
3 changed files with 37 additions and 1 deletions

View File

@@ -26,6 +26,11 @@ config['path_event_files'] = 'event_files'
config['path_cmdfifo'] = 'cmdfifo'
config['persistent_storage'] = 'urlbot.persistent'
config['url_blacklist'] = [
r'^.*heise\.de/newsticker/.*$',
r'^.*wikipedia\.org/wiki/.*$'
]
# the "dice" feature will use more efficient random data (0) for given users
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )

View File

@@ -419,6 +419,25 @@ def command_decode(args):
'msg': args['reply_user'] + ': usage: decode {single character}'
}
def command_show_blacklist(args):
if 'register' == args:
return {
'name': 'show-blacklist',
'desc': 'show the current URL blacklist',
'args': ('data', 'reply_user'),
'ratelimit_class': RATE_GLOBAL
}
if 'show-blacklist' in args['data']:
logger('plugin', 'sent URL blacklist')
return {
'msg': '\n'.join([
args['reply_user'] + ': URL blacklist: ' + b
for b in conf('url_blacklist')
])
}
#def command_dummy(args):
# if 'register' == args:
# return {
@@ -518,7 +537,7 @@ funcs['parse'] = (parse_mental_ill, parse_skynet, parse_debbug)
funcs['command'] = (
command_command, command_help, command_version, command_unicode,
command_klammer, command_source, command_dice, command_uptime, command_ping,
command_info, command_teatimer, command_decode
command_info, command_teatimer, command_decode, command_show_blacklist
)
_dir = dir()

View File

@@ -140,6 +140,18 @@ def extract_url(data):
if ratelimit_exceeded():
return False
flag = False
for b in conf('url_blacklist'):
if not None is re.match(b, url):
flag = True
message = 'url blacklist match for ' + url
logger('info', message)
chat_write(message)
if flag:
# an URL has matched the blacklist, continue to the next URL
continue
# urllib.request is broken:
# >>> '.'.encode('idna')
# ....