strip : from user in record {user}

This commit is contained in:
Thorsten
2016-01-28 20:18:26 +01:00
parent 6b20f89581
commit 5af93c6d7a
3 changed files with 21 additions and 10 deletions

View File

@@ -205,6 +205,14 @@ def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled
return decorate return decorate
def get_nick_from_object(message_obj):
"""
not quite correct yet, also the private property access isn't nice.
"""
nick = message_obj['mucnick'] or message_obj['from']._jid[2]
return nick
ptypes_PARSE = 'parser' ptypes_PARSE = 'parser'
ptypes_COMMAND = 'command' ptypes_COMMAND = 'command'
ptypes = [ptypes_PARSE, ptypes_COMMAND] ptypes = [ptypes_PARSE, ptypes_COMMAND]

View File

@@ -15,7 +15,9 @@ from common import (
VERSION, RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_LIMIT, VERSION, RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_LIMIT,
giphy, pluginfunction, giphy, pluginfunction,
ptypes_COMMAND, ptypes_COMMAND,
RATE_NO_SILENCE) RATE_NO_SILENCE,
get_nick_from_object
)
from string_constants import cakes, excuses, moin_strings_hi, moin_strings_bye, languages from string_constants import cakes, excuses, moin_strings_hi, moin_strings_bye, languages
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -485,11 +487,11 @@ def command_record(argv, **args):
'msg': '%s: usage: record {user} {some message}' % args['reply_user'] 'msg': '%s: usage: record {user} {some message}' % args['reply_user']
} }
target_user = argv[0].lower() target_user = argv[0].lower().strip(':')
message = '{} ({}): '.format(args['reply_user'], time.strftime('%Y-%m-%d %H:%M')) message = '{} ({}): '.format(args['reply_user'], time.strftime('%Y-%m-%d %H:%M'))
if argv[1] == "previous": if argv[1] == "previous":
prev_message_obj = args['stack'][-1] prev_message_obj = args['stack'][-1]
message += '[{}]: '.format(prev_message_obj['mucnick'] or prev_message_obj['from']._jid[2]) message += '[{}]: '.format(get_nick_from_object(prev_message_obj))
message += prev_message_obj['body'] message += prev_message_obj['body']
else: else:
message += ' '.join(argv[1:]) message += ' '.join(argv[1:])

View File

@@ -17,7 +17,7 @@ from common import (
RATE_CHAT, RATE_CHAT,
RATE_EVENT, RATE_EVENT,
rate_limit, rate_limit,
) get_nick_from_object)
from config import runtimeconf_set from config import runtimeconf_set
from idlebot import IdleBot, start from idlebot import IdleBot, start
from plugins import ( from plugins import (
@@ -174,9 +174,10 @@ class UrlBot(IdleBot):
msg_obj['type'] = 'chat' msg_obj['type'] = 'chat'
self.send_reply("You're flagged as bot, please write {}: remove-from-botlist " self.send_reply("You're flagged as bot, please write {}: remove-from-botlist "
"{} if you're not a bot.".format( "{} if you're not a bot.".format(
config.conf_get('bot_nickname'), msg_obj['from']._jid[2] config.conf_get('bot_nickname'),
get_nick_from_object(msg_obj)
), msg_obj) ), msg_obj)
self.logger.debug("not talking to the other bot named {}".format(msg_obj['from']._jid[2])) self.logger.debug("not talking to the other bot named {}".format(get_nick_from_object(msg_obj)))
return False return False
self.send_message( self.send_message(
mto=msg_obj['from'].bare, mto=msg_obj['from'].bare,
@@ -233,7 +234,7 @@ class UrlBot(IdleBot):
if (msg_obj['body'].startswith(config.conf_get('bot_nickname')) and not any( if (msg_obj['body'].startswith(config.conf_get('bot_nickname')) and not any(
[reacted_on_command, reacted_on_parse]) and rate_limit(RATE_GLOBAL)): [reacted_on_command, reacted_on_parse]) and rate_limit(RATE_GLOBAL)):
ret = else_command({'reply_user': msg_obj['from']._jid[2]}) ret = else_command({'reply_user': get_nick_from_object(msg_obj)})
if ret: if ret:
if 'msg' in ret: if 'msg' in ret:
self.send_reply(ret['msg'], msg_obj) self.send_reply(ret['msg'], msg_obj)
@@ -273,7 +274,7 @@ class UrlBot(IdleBot):
self.hangup() self.hangup()
sys.exit(1) sys.exit(1)
reply_user = msg_obj['mucnick'] or msg_obj['from']._jid[2] reply_user = get_nick_from_object(msg_obj)
# TODO: check how several commands/plugins # TODO: check how several commands/plugins
# in a single message behave (also with rate limiting) # in a single message behave (also with rate limiting)
@@ -306,7 +307,7 @@ class UrlBot(IdleBot):
:return: :return:
""" """
data = msg_obj['body'] data = msg_obj['body']
reply_user = msg_obj['mucnick'] or msg_obj['from']._jid[2] reply_user = get_nick_from_object(msg_obj)
reacted = False reacted = False
for plugin in plugin_storage[ptypes_PARSE]: for plugin in plugin_storage[ptypes_PARSE]: