add URL blacklist; add command_show_blacklist()
This commit is contained in:
@@ -26,6 +26,11 @@ config['path_event_files'] = 'event_files'
|
|||||||
config['path_cmdfifo'] = 'cmdfifo'
|
config['path_cmdfifo'] = 'cmdfifo'
|
||||||
config['persistent_storage'] = 'urlbot.persistent'
|
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
|
# the "dice" feature will use more efficient random data (0) for given users
|
||||||
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
||||||
|
|
||||||
|
|||||||
21
plugins.py
21
plugins.py
@@ -419,6 +419,25 @@ def command_decode(args):
|
|||||||
'msg': args['reply_user'] + ': usage: decode {single character}'
|
'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):
|
#def command_dummy(args):
|
||||||
# if 'register' == args:
|
# if 'register' == args:
|
||||||
# return {
|
# return {
|
||||||
@@ -518,7 +537,7 @@ funcs['parse'] = (parse_mental_ill, parse_skynet, parse_debbug)
|
|||||||
funcs['command'] = (
|
funcs['command'] = (
|
||||||
command_command, command_help, command_version, command_unicode,
|
command_command, command_help, command_version, command_unicode,
|
||||||
command_klammer, command_source, command_dice, command_uptime, command_ping,
|
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()
|
_dir = dir()
|
||||||
|
|||||||
12
urlbot.py
12
urlbot.py
@@ -140,6 +140,18 @@ def extract_url(data):
|
|||||||
if ratelimit_exceeded():
|
if ratelimit_exceeded():
|
||||||
return False
|
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:
|
# urllib.request is broken:
|
||||||
# >>> '.'.encode('idna')
|
# >>> '.'.encode('idna')
|
||||||
# ....
|
# ....
|
||||||
|
|||||||
Reference in New Issue
Block a user