mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
don't talk to other bots, added (not activated) presence command
This commit is contained in:
20
idlebot.py
20
idlebot.py
@@ -5,7 +5,7 @@ import time
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from common import VERSION, EVENTLOOP_DELAY
|
from common import VERSION, EVENTLOOP_DELAY, conf_load
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from local_config import conf, set_conf
|
from local_config import conf, set_conf
|
||||||
@@ -59,19 +59,20 @@ class IdleBot(ClientXMPP):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# don't talk to yourself
|
# don't talk to yourself
|
||||||
if msg_obj['mucnick'] == self.nick:
|
if msg_obj['mucnick'] == self.nick or 'groupchat' != msg_obj['type']:
|
||||||
return
|
return False
|
||||||
|
elif msg_obj['body'].startswith(conf('bot_user')) and 'hangup' in msg_obj['body']:
|
||||||
if 'groupchat' != msg_obj['type']:
|
|
||||||
return
|
|
||||||
|
|
||||||
if msg_obj['body'].startswith(conf('bot_user')) and 'hangup' in msg_obj['body']:
|
|
||||||
self.logger.warn("got 'hangup' from '%s': '%s'" % (
|
self.logger.warn("got 'hangup' from '%s': '%s'" % (
|
||||||
msg_obj['mucnick'], msg_obj['body']
|
msg_obj['mucnick'], msg_obj['body']
|
||||||
))
|
))
|
||||||
global got_hangup
|
global got_hangup
|
||||||
got_hangup = True
|
got_hangup = True
|
||||||
return
|
return False
|
||||||
|
elif msg_obj['mucnick'] in conf_load().get("other_bots", ()):
|
||||||
|
# not talking to the other bot.
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def start(botclass, active=False):
|
def start(botclass, active=False):
|
||||||
@@ -103,6 +104,7 @@ def start(botclass, active=False):
|
|||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
# print("hangup: %s" % got_hangup)
|
||||||
if got_hangup or not plugins.event_trigger():
|
if got_hangup or not plugins.event_trigger():
|
||||||
bot.disconnect()
|
bot.disconnect()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
90
plugins.py
90
plugins.py
@@ -9,7 +9,6 @@ import types
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
# from common import *
|
# from common import *
|
||||||
|
|
||||||
from common import conf_load, conf_save, RATE_GLOBAL, RATE_NO_SILENCE, VERSION, RATE_INTERACTIVE, BUFSIZ, \
|
from common import conf_load, conf_save, RATE_GLOBAL, RATE_NO_SILENCE, VERSION, RATE_INTERACTIVE, BUFSIZ, \
|
||||||
@@ -17,7 +16,6 @@ from common import conf_load, conf_save, RATE_GLOBAL, RATE_NO_SILENCE, VERSION,
|
|||||||
from local_config import set_conf, conf
|
from local_config import set_conf, conf
|
||||||
from string_constants import excuses, moin_strings_hi, moin_strings_bye, cakes
|
from string_constants import excuses, moin_strings_hi, moin_strings_bye, cakes
|
||||||
|
|
||||||
|
|
||||||
ptypes_PARSE = 'parser'
|
ptypes_PARSE = 'parser'
|
||||||
ptypes_COMMAND = 'command'
|
ptypes_COMMAND = 'command'
|
||||||
ptypes = [ptypes_PARSE, ptypes_COMMAND]
|
ptypes = [ptypes_PARSE, ptypes_COMMAND]
|
||||||
@@ -166,9 +164,8 @@ def parse_dsa(**args):
|
|||||||
@pluginfunction('skynet', 'parse skynet', ptypes_PARSE, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
@pluginfunction('skynet', 'parse skynet', ptypes_PARSE, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||||
def parse_skynet(**args):
|
def parse_skynet(**args):
|
||||||
if 'skynet' in args['data'].lower():
|
if 'skynet' in args['data'].lower():
|
||||||
log.info('sent skynet reply')
|
|
||||||
return {
|
return {
|
||||||
'msg': '''I'm an independent bot and have nothing to do with other artificial intelligence systems!'''
|
'msg': 'I\'ll be back.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +282,8 @@ def command_version(argv, **args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pluginfunction('klammer', 'prints an anoying paper clip aka. Karl Klammer', ptypes_COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
@pluginfunction('klammer', 'prints an anoying paper clip aka. Karl Klammer', ptypes_COMMAND,
|
||||||
|
ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||||
def command_klammer(argv, **args):
|
def command_klammer(argv, **args):
|
||||||
if 'klammer' != argv[0]:
|
if 'klammer' != argv[0]:
|
||||||
return
|
return
|
||||||
@@ -487,7 +485,8 @@ def command_teatimer(argv, **args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pluginfunction('decode', 'prints the long description of an unicode character', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
@pluginfunction('decode', 'prints the long description of an unicode character', ptypes_COMMAND,
|
||||||
|
ratelimit_class=RATE_INTERACTIVE)
|
||||||
def command_decode(argv, **args):
|
def command_decode(argv, **args):
|
||||||
if 'decode' != argv[0]:
|
if 'decode' != argv[0]:
|
||||||
return
|
return
|
||||||
@@ -542,12 +541,12 @@ def command_show_blacklist(argv, **args):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'msg': [
|
'msg': [
|
||||||
args['reply_user'] + ': URL blacklist%s: ' % (
|
args['reply_user'] + ': URL blacklist%s: ' % (
|
||||||
'' if not argv1 else ' (limited to %s)' % argv1
|
'' if not argv1 else ' (limited to %s)' % argv1
|
||||||
)
|
)
|
||||||
] + [
|
] + [
|
||||||
b for b in conf('url_blacklist') if not argv1 or argv1 in b
|
b for b in conf('url_blacklist') if not argv1 or argv1 in b
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -763,9 +762,9 @@ def command_show_moinlist(argv, **args):
|
|||||||
args['reply_user'],
|
args['reply_user'],
|
||||||
'' if not argv1 else ' (limited to %s)' % argv1,
|
'' if not argv1 else ' (limited to %s)' % argv1,
|
||||||
', '.join([
|
', '.join([
|
||||||
b for b in moin_strings_hi + moin_strings_bye
|
b for b in moin_strings_hi + moin_strings_bye
|
||||||
if not argv1 or argv1.lower() in b.lower()
|
if not argv1 or argv1.lower() in b.lower()
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,14 +862,15 @@ def command_show_recordlist(argv, **args):
|
|||||||
args['reply_user'],
|
args['reply_user'],
|
||||||
'' if not argv1 else ' (limited to %s)' % argv1,
|
'' if not argv1 else ' (limited to %s)' % argv1,
|
||||||
', '.join([
|
', '.join([
|
||||||
'%s (%d)' % (key, len(val)) for key, val in conf_load().get('user_records').items()
|
'%s (%d)' % (key, len(val)) for key, val in conf_load().get('user_records').items()
|
||||||
if not argv1 or argv1.lower() in key.lower()
|
if not argv1 or argv1.lower() in key.lower()
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pluginfunction('dsa-watcher', 'automatically crawls for newly published Debian Security Announces', ptypes_COMMAND, ratelimit_class=RATE_NO_SILENCE)
|
@pluginfunction('dsa-watcher', 'automatically crawls for newly published Debian Security Announces', ptypes_COMMAND,
|
||||||
|
ratelimit_class=RATE_NO_SILENCE)
|
||||||
def command_dsa_watcher(argv, **_):
|
def command_dsa_watcher(argv, **_):
|
||||||
"""
|
"""
|
||||||
TODO: rewrite so that a last_dsa_date is used instead, then all DSAs since then printed and the date set to now()
|
TODO: rewrite so that a last_dsa_date is used instead, then all DSAs since then printed and the date set to now()
|
||||||
@@ -910,7 +910,8 @@ def command_dsa_watcher(argv, **_):
|
|||||||
if result:
|
if result:
|
||||||
package = result.groups()[0]
|
package = result.groups()[0]
|
||||||
|
|
||||||
out.append('new Debian Security Announce found (%s): %s' % (str(package).replace(' - security update', ''), url))
|
out.append(
|
||||||
|
'new Debian Security Announce found (%s): %s' % (str(package).replace(' - security update', ''), url))
|
||||||
|
|
||||||
if conf('persistent_locked'):
|
if conf('persistent_locked'):
|
||||||
msg = "couldn't get exclusive lock"
|
msg = "couldn't get exclusive lock"
|
||||||
@@ -955,6 +956,53 @@ def command_dsa_watcher(argv, **_):
|
|||||||
return {'msg': msg}
|
return {'msg': msg}
|
||||||
|
|
||||||
|
|
||||||
|
@pluginfunction("provoke_bots", "search for other bots", ptypes_COMMAND)
|
||||||
|
def provoke_bots(argv, **args):
|
||||||
|
if 'provoke_bots' == argv[0]:
|
||||||
|
return {
|
||||||
|
'msg': 'Searching for other less intelligent lifeforms... skynet? You here?'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pluginfunction("recognize_bots", "got ya", ptypes_PARSE)
|
||||||
|
def recognize_bots(**args):
|
||||||
|
if 'independent bot and have nothing to do with other artificial intelligence systems' in args['data']:
|
||||||
|
|
||||||
|
blob = conf_load()
|
||||||
|
|
||||||
|
if 'other_bots' not in blob:
|
||||||
|
blob['other_bots'] = []
|
||||||
|
if args['reply_user'] not in blob['other_bots']:
|
||||||
|
blob['other_bots'].append(args['reply_user'])
|
||||||
|
conf_save(blob)
|
||||||
|
return {
|
||||||
|
'event': {
|
||||||
|
'time': time.time() + 3,
|
||||||
|
'msg': 'Making notes...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pluginfunction("set_status", "", ptypes_COMMAND)
|
||||||
|
def set_status(argv, **args):
|
||||||
|
if 'set_status' != argv[0]:
|
||||||
|
return
|
||||||
|
if argv[1] == 'mute' and args['reply_user'] == conf('bot_owner'):
|
||||||
|
return {
|
||||||
|
'presence': {
|
||||||
|
'status': 'AWAY',
|
||||||
|
'message': 'I\'m muted now. You can unmute me with "%s: set_status unmute"' % conf("bot_user")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif argv[1] == 'unmute' and args['reply_user'] == conf('bot_owner'):
|
||||||
|
return {
|
||||||
|
'presence': {
|
||||||
|
'status': 'ONLINE',
|
||||||
|
'message': ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def else_command(args):
|
def else_command(args):
|
||||||
log.info('sent short info')
|
log.info('sent short info')
|
||||||
return {
|
return {
|
||||||
@@ -976,7 +1024,7 @@ def register(func_type):
|
|||||||
f.__dict__.get('is_plugin', False),
|
f.__dict__.get('is_plugin', False),
|
||||||
getattr(f, 'plugin_type', None) == func_type
|
getattr(f, 'plugin_type', None) == func_type
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|
||||||
log.info('auto-reg %s: %s' % (func_type, ', '.join(
|
log.info('auto-reg %s: %s' % (func_type, ', '.join(
|
||||||
f.plugin_name for f in functions
|
f.plugin_name for f in functions
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ class UrlBot(IdleBot):
|
|||||||
self.add_event_handler('muc::%s::got_online' % r, self.muc_online)
|
self.add_event_handler('muc::%s::got_online' % r, self.muc_online)
|
||||||
|
|
||||||
def muc_message(self, msg_obj):
|
def muc_message(self, msg_obj):
|
||||||
super(UrlBot, self).muc_message(msg_obj)
|
return super(UrlBot, self).muc_message(msg_obj) and self.handle_msg(msg_obj)
|
||||||
return self.handle_msg(msg_obj)
|
|
||||||
|
|
||||||
def message(self, msg_obj):
|
def message(self, msg_obj):
|
||||||
if 'groupchat' == msg_obj['type']:
|
if 'groupchat' == msg_obj['type']:
|
||||||
@@ -328,7 +327,7 @@ class UrlBot(IdleBot):
|
|||||||
if 'event' in plugin_action:
|
if 'event' in plugin_action:
|
||||||
event = plugin_action["event"]
|
event = plugin_action["event"]
|
||||||
if 'msg' in event:
|
if 'msg' in event:
|
||||||
register_event(event["time"], self.send_reply, event['msg'])
|
register_event(event["time"], self.send_reply, [event['msg']])
|
||||||
elif 'command' in event:
|
elif 'command' in event:
|
||||||
command = event["command"]
|
command = event["command"]
|
||||||
if rate_limit(RATE_EVENT):
|
if rate_limit(RATE_EVENT):
|
||||||
|
|||||||
Reference in New Issue
Block a user