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