mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
port urlbot: remove mcabber specific output stuff
This commit is contained in:
3
bot.py
3
bot.py
@@ -47,6 +47,9 @@ class bot(ClientXMPP):
|
||||
def muc_message(self, msg):
|
||||
print(msg['mucnick'])
|
||||
print(msg['body'])
|
||||
print((msg['from'], msg['from'].bare))
|
||||
|
||||
print(conf('room') == msg['from'].bare)
|
||||
|
||||
# don't talk to yourself
|
||||
if msg['mucnick'] == self.nick:
|
||||
|
||||
@@ -20,8 +20,6 @@ delay = 0.100 # seconds
|
||||
basedir = '.'
|
||||
if 2 == len(sys.argv): basedir = sys.argv[1]
|
||||
|
||||
fifo_path = os.path.join(basedir, conf('path_cmdfifo'))
|
||||
|
||||
def debug_enabled():
|
||||
# return True
|
||||
return False
|
||||
|
||||
@@ -5,7 +5,7 @@ if '__main__' == __name__:
|
||||
print('''this is a plugin file, which is not meant to be executed''')
|
||||
exit(-1)
|
||||
|
||||
import time, random, unicodedata, re
|
||||
import time, random, unicodedata, re, sys
|
||||
from local_config import conf
|
||||
from common import *
|
||||
from urlbot import extract_title
|
||||
@@ -488,8 +488,8 @@ def data_parse_commands(data):
|
||||
return None
|
||||
|
||||
if 'hangup' in data:
|
||||
chat_write('', prefix='/quit')
|
||||
logger('warn', 'received hangup: ' + data)
|
||||
sys.exit(1)
|
||||
return None
|
||||
|
||||
reply_user = get_reply_data(data)
|
||||
|
||||
35
urlbot.py
35
urlbot.py
@@ -32,6 +32,7 @@ hist_ts = []
|
||||
hist_flag = True
|
||||
|
||||
parser = None
|
||||
xmpp = None
|
||||
|
||||
def fetch_page(url):
|
||||
logger('info', 'fetching page ' + url)
|
||||
@@ -100,7 +101,7 @@ def extract_title(url):
|
||||
|
||||
return (-1, 'error')
|
||||
|
||||
def chat_write(message, prefix='/say '):
|
||||
def chat_write(message):
|
||||
set_conf('request_counter', conf('request_counter') + 1)
|
||||
|
||||
for m in message:
|
||||
@@ -111,22 +112,20 @@ def chat_write(message, prefix='/say '):
|
||||
if debug_enabled():
|
||||
print(message)
|
||||
else:
|
||||
try:
|
||||
fd = open(fifo_path, 'wb')
|
||||
# FIXME 2to3
|
||||
# FIXME: somehow, unicode chars can end up inside a <str> message,
|
||||
# which seems to make both unicode() and ''.encode('utf8') fail.
|
||||
try:
|
||||
msg = str(prefix) + str(message) + '\n'
|
||||
msg = str(message)
|
||||
msg = msg.encode('utf8')
|
||||
except UnicodeDecodeError as e:
|
||||
logger('warn', 'encoding msg failed: ' + str(e))
|
||||
msg = prefix + message + '\n'
|
||||
msg = message
|
||||
|
||||
fd.write(msg)
|
||||
fd.close()
|
||||
except IOError as e:
|
||||
logger('err', "couldn't print to fifo %s: %s" % (fifo_path, str(e)))
|
||||
xmpp.send_message(
|
||||
mto=conf('room'),
|
||||
mbody=msg,
|
||||
mtype='groupchat'
|
||||
)
|
||||
|
||||
def ratelimit_touch(ignored=None): # FIXME: separate counters
|
||||
hist_ts.append(time.time())
|
||||
@@ -229,6 +228,7 @@ def extract_url(data):
|
||||
return ret
|
||||
|
||||
def parse_pn(data):
|
||||
# FIXME: changed
|
||||
## reply_user = data.split(' ')[0].strip('<>')
|
||||
# since we can't determine if a user named 'foo> ' just wrote ' > bar'
|
||||
# or a user 'foo' just wrote '> > bar', we can't safely answer here
|
||||
@@ -283,12 +283,6 @@ class bot(ClientXMPP):
|
||||
if msg['mucnick'] == self.nick:
|
||||
return
|
||||
|
||||
# self.send_message(
|
||||
# mto=msg['from'].bare,
|
||||
# mbody='got[%s]' % msg['body'],
|
||||
# mtype='groupchat'
|
||||
# )
|
||||
|
||||
return handle_msg(msg)
|
||||
|
||||
if '__main__' == __name__:
|
||||
@@ -318,15 +312,6 @@ if '__main__' == __name__:
|
||||
xmpp.register_plugin('xep_0045')
|
||||
xmpp.process(threaded=False)
|
||||
|
||||
|
||||
if not os.path.exists(fifo_path):
|
||||
logger('error', 'fifo_path "%s" does not exist, exiting' % fifo_path)
|
||||
exit(1)
|
||||
|
||||
if not stat.S_ISFIFO(os.stat(fifo_path).st_mode):
|
||||
logger('error', 'fifo_path "%s" is not a FIFO, exiting' % fifo_path)
|
||||
exit(1)
|
||||
|
||||
while 1:
|
||||
try:
|
||||
plugins.event_trigger()
|
||||
|
||||
Reference in New Issue
Block a user