mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
KI, reply added; code moved to chat_write()
This commit is contained in:
@@ -4,7 +4,7 @@ import sys, os, re, time, urllib
|
||||
|
||||
BUFSIZ = 8192
|
||||
delay = 0.100 # seconds
|
||||
ignore_user = 'urlbot'
|
||||
bot_user = 'urlbot'
|
||||
|
||||
basedir = '.'
|
||||
if 2 == len(sys.argv): basedir = sys.argv[1]
|
||||
@@ -41,24 +41,34 @@ def extract_title(url):
|
||||
if result:
|
||||
return result.groups()[0]
|
||||
|
||||
def chat_write(message):
|
||||
try:
|
||||
fd = open(fifo_path, 'wb')
|
||||
fd.write('/say ' + message)
|
||||
fd.close()
|
||||
except IOError:
|
||||
logger('err', "couldn't print to fifo " + fifo_path)
|
||||
|
||||
def extract_url(data):
|
||||
result = re.findall("(https?://[^\s]+)", data)
|
||||
if result:
|
||||
for r in result:
|
||||
title = extract_title(r)
|
||||
|
||||
message = '/say Title: %s: %s' % (title, e(r))
|
||||
message = 'Title: %s: %s' % (title, e(r))
|
||||
logger('info', 'printing ' + message)
|
||||
|
||||
if debug_enabled():
|
||||
print message
|
||||
else:
|
||||
try:
|
||||
fd = open(fifo_path, 'wb')
|
||||
fd.write(message)
|
||||
fd.close()
|
||||
except IOError:
|
||||
logger('err', "couldn't print to fifo " + fifo_path)
|
||||
chat_write(message)
|
||||
|
||||
def parse_commands(data):
|
||||
words = data.split(' ')
|
||||
|
||||
# reply if beginning of the text matches bot_user
|
||||
if words[1][0:len(bot_user)] == bot_user:
|
||||
chat_write(words[0][1:-1] + ''': 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 Cae.''')
|
||||
|
||||
def parse_delete(filepath):
|
||||
try:
|
||||
@@ -69,8 +79,9 @@ def parse_delete(filepath):
|
||||
|
||||
content = fd.read(BUFSIZ) # ignore more than BUFSIZ
|
||||
|
||||
if content[1:1+len(ignore_user)] != ignore_user:
|
||||
if content[1:1+len(bot_user)] != bot_user:
|
||||
extract_url(content)
|
||||
parse_commands(content)
|
||||
|
||||
fd.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user