mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
send_reply accepts message lists now
This commit is contained in:
22
plugins.py
22
plugins.py
@@ -594,19 +594,11 @@ def data_parse_commands(msg_obj):
|
|||||||
|
|
||||||
if None != ret:
|
if None != ret:
|
||||||
if 'msg' in list(ret.keys()):
|
if 'msg' in list(ret.keys()):
|
||||||
if str == type(ret['msg']): # FIXME 2to3
|
ratelimit_touch(RATE_CHAT)
|
||||||
ratelimit_touch(RATE_CHAT)
|
if ratelimit_exceeded(RATE_CHAT):
|
||||||
if ratelimit_exceeded(RATE_CHAT):
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
send_reply(ret['msg'], msg_obj)
|
send_reply(ret['msg'], msg_obj)
|
||||||
else:
|
|
||||||
for line in ret['msg']:
|
|
||||||
ratelimit_touch(RATE_CHAT)
|
|
||||||
if ratelimit_exceeded(RATE_CHAT):
|
|
||||||
return False
|
|
||||||
|
|
||||||
send_reply(line, msg_obj)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -616,11 +608,7 @@ def data_parse_commands(msg_obj):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if 'msg' in list(ret.keys()):
|
if 'msg' in list(ret.keys()):
|
||||||
if list is type(ret['msg']):
|
send_reply(ret['msg'], msg_obj)
|
||||||
for m in ret['msg']:
|
|
||||||
send_reply(m, msg_obj)
|
|
||||||
else:
|
|
||||||
send_reply(ret['msg'], msg_obj)
|
|
||||||
|
|
||||||
funcs = {}
|
funcs = {}
|
||||||
funcs['parse'] = (parse_mental_ill, parse_skynet, parse_debbug, parse_cve)
|
funcs['parse'] = (parse_mental_ill, parse_skynet, parse_debbug, parse_cve)
|
||||||
|
|||||||
95
urlbot.py
95
urlbot.py
@@ -105,10 +105,8 @@ def extract_title(url):
|
|||||||
def send_reply(message, msg_obj):
|
def send_reply(message, msg_obj):
|
||||||
set_conf('request_counter', conf('request_counter') + 1)
|
set_conf('request_counter', conf('request_counter') + 1)
|
||||||
|
|
||||||
for m in message:
|
if str is not type(message):
|
||||||
if 0x20 > ord(m):
|
message = '\n'.join(message)
|
||||||
logger('warn', 'strange char 0x%02x in send_reply(message), skipping' % ord(m))
|
|
||||||
return False
|
|
||||||
|
|
||||||
if debug_enabled():
|
if debug_enabled():
|
||||||
print(message)
|
print(message)
|
||||||
@@ -145,23 +143,25 @@ def ratelimit_exceeded(ignored=None): # FIXME: separate counters
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def extract_url(data, msg_obj):
|
def extract_url(data, msg_obj):
|
||||||
ret = None
|
|
||||||
result = re.findall("(https?://[^\s>]+)", data)
|
result = re.findall("(https?://[^\s>]+)", data)
|
||||||
if result:
|
if not result:
|
||||||
for url in result:
|
return
|
||||||
ratelimit_touch()
|
|
||||||
if ratelimit_exceeded(msg_obj):
|
|
||||||
return False
|
|
||||||
|
|
||||||
flag = False
|
ret = None
|
||||||
for b in conf('url_blacklist'):
|
for url in result:
|
||||||
if not None is re.match(b, url):
|
ratelimit_touch()
|
||||||
flag = True
|
if ratelimit_exceeded(msg_obj):
|
||||||
logger('info', 'url blacklist match for ' + url)
|
return False
|
||||||
|
|
||||||
if flag:
|
flag = False
|
||||||
# an URL has matched the blacklist, continue to the next URL
|
for b in conf('url_blacklist'):
|
||||||
continue
|
if not None is re.match(b, url):
|
||||||
|
flag = True
|
||||||
|
logger('info', 'url blacklist match for ' + url)
|
||||||
|
|
||||||
|
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')
|
||||||
@@ -173,40 +173,41 @@ def extract_url(data, msg_obj):
|
|||||||
# >>> 'a.a.'.encode('idna')
|
# >>> 'a.a.'.encode('idna')
|
||||||
# b'a.a.'
|
# b'a.a.'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(status, title) = extract_title(url)
|
(status, title) = extract_title(url)
|
||||||
except UnicodeError as e:
|
except UnicodeError as e:
|
||||||
(status, title) = (4, str(e))
|
(status, title) = (4, str(e))
|
||||||
|
|
||||||
if 0 == status:
|
if 0 == status:
|
||||||
title = title.strip()
|
title = title.strip()
|
||||||
|
|
||||||
message = 'Title: %s: %s' %(title, url)
|
message = 'Title: %s: %s' %(title, url)
|
||||||
elif 1 == status:
|
elif 1 == status:
|
||||||
if conf('image_preview'):
|
if conf('image_preview'):
|
||||||
# of course it's fake, but it looks interesting at least
|
# of course it's fake, but it looks interesting at least
|
||||||
char = """,._-+=\|/*`~"'"""
|
char = """,._-+=\|/*`~"'"""
|
||||||
message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' %(
|
message = 'No text but %s, 1-bit ASCII art preview: [%c] %s' %(
|
||||||
title, random.choice(char), url
|
title, random.choice(char), url
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
logger('info', 'no message sent for non-text %s (%s)' %(url, title))
|
|
||||||
continue
|
|
||||||
elif 2 == status:
|
|
||||||
message = 'No title: %s' % url
|
|
||||||
elif 3 == status:
|
|
||||||
message = title
|
|
||||||
elif 4 == status:
|
|
||||||
message = 'Bug triggered (%s), invalid URL/domain part: %s' % (title, url)
|
|
||||||
logger('warn', message)
|
|
||||||
else:
|
else:
|
||||||
message = 'some error occurred when fetching %s' % url
|
logger('info', 'no message sent for non-text %s (%s)' %(url, title))
|
||||||
|
continue
|
||||||
|
elif 2 == status:
|
||||||
|
message = 'No title: %s' % url
|
||||||
|
elif 3 == status:
|
||||||
|
message = title
|
||||||
|
elif 4 == status:
|
||||||
|
message = 'Bug triggered (%s), invalid URL/domain part: %s' % (title, url)
|
||||||
|
logger('warn', message)
|
||||||
|
else:
|
||||||
|
message = 'some error occurred when fetching %s' % url
|
||||||
|
|
||||||
message = message.replace('\n', '\\n')
|
message = message.replace('\n', '\\n')
|
||||||
|
|
||||||
|
logger('info', 'printing ' + message)
|
||||||
|
send_reply(message, msg_obj)
|
||||||
|
ret = True
|
||||||
|
|
||||||
logger('info', 'printing ' + message)
|
|
||||||
send_reply(message, msg_obj)
|
|
||||||
ret = True
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def handle_msg(msg_obj):
|
def handle_msg(msg_obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user