本文整理汇总了Python中kol.util.Report.warning方法的典型用法代码示例。如果您正苦于以下问题:Python Report.warning方法的具体用法?Python Report.warning怎么用?Python Report.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kol.util.Report
的用法示例。
在下文中一共展示了Report.warning方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whois
# 需要导入模块: from kol.util import Report [as 别名]
# 或者: from kol.util.Report import warning [as 别名]
def whois(bot, name):
Report.trace('bot', 'Whois: ' + name)
response = bot.sendChatMessage('/whois ' + name)
responsetext = ''.join(x['text'] for x in response)
match = re.search(r'<a[^>]*showplayer.php[^>]*><b[^>]*>([A-Za-z0-9_ ]+) \(#([0-9]+)\)</b></a>', responsetext)
if match:
player_name = match.group(1)
player_id = match.group(2)
Report.trace('bot', 'Whois resolved: Name: ' + str(player_name))
Report.trace('bot', 'Whois resolved: ID: ' + str(player_id))
return player_name, player_id
elif 'Unknown Player: ' in responsetext:
raise Error.Error("That player could not be found.", Error.USER_NOT_FOUND)
else:
Report.warning('bot', 'Unable to parse /whois response: ' + repr(responsetext))
raise Error.Error("Unable to parse /whois response.", Error.REQUEST_GENERIC)
示例2: botProcessChat
# 需要导入模块: from kol.util import Report [as 别名]
# 或者: from kol.util.Report import warning [as 别名]
def botProcessChat(context, **kwargs):
returnCode = FilterManager.CONTINUE
bot = kwargs['bot']
chat = kwargs['chat']
if chat['type'] in ['private']:
# Initialize variables for response formatting
user_name = str(chat['userName'])
user_id = str(chat['userId'])
current_time = time.time()
exprlist = []
exprresults = []
channel = ''
clan = alea.clan.Clan(0, '')
target_name = ''
target_id = '0'
uneffectable = alea.util.Uneffectable('')
msg = ''
try:
# Parse the abomination that our chat partner hath wrought
request = alea.parser.aleabot_parse(chat['text'])
if request[0] == 'rollrequest':
# Handle a dice rolling request
exprlist = request[1]
channel = request[2]
# Get the reply text that applies to this kind of roll request
diceless = all(expr.classify_dice() == 0 for expr in exprlist)
if channel == '':
# Private rolling
if diceless:
msg = aleabot.config.get('rolltext_diceless_private')
else:
msg = aleabot.config.get('rolltext_private')
else:
# Public rolling
if diceless:
msg = aleabot.config.get('rolltext_diceless_public')
else:
msg = aleabot.config.get('rolltext_public')
# Check if channel is allowed, and switch clan if needed
if channel != '':
if channel in aleabot.config.get('channels').split():
# Allowed public channel (e.g. /games)
pass
elif channel in aleabot.config.get('clanchannels').split():
# Allowed clan channel (e.g. /clan, /hobopolis, ...)
aleabot.clanstate.set_session(bot.session)
clan = aleabot.clanstate.player_clan(user_id)
Report.info('bot', '%s asked me to roll in clan %s' % (user_name, clan.name()))
if clan.id() == 0:
Report.warning('bot', 'A player who is not in a clan asked me to roll in ' + channel)
raise ClanlessPlayerError('clanless player')
elif not aleabot.clanstate.have_whitelist(clan):
Report.warning('bot', 'I do not have a whitelist in clan %s' % clan.name())
raise NeedWhitelistError('need whitelist')
else:
Report.info('bot', 'I have a whitelist in clan %s' % clan.name())
aleabot.clanstate.switch(clan)
# Set timer to switch back to home clan
aleabot.home_clan_timer = 0
else:
raise ChannelDisallowedError(channel)
# Apply time-based limits
aleabot.rolllimiter.check(channel, user_id, clan.id(),
current_time, aleabot.config)
# Evaluate dice expressions
exprresults = alea.expr.aleabot_eval(exprlist,
channel != '', aleabot.rng, aleabot.config)
# Update time-based roll limiter
aleabot.rolllimiter.update(channel, user_id, clan.id(),
current_time, aleabot.config)
# Record roll and result in roll verification list
state = bot.states['global']
rollverify_key = 'rollverify_' + user_id
if rollverify_key not in state:
state[rollverify_key] = []
state[rollverify_key].insert(0, (
current_time,
[str(x) for x in exprlist],
[str(x) for x in exprresults],
str(channel),
str(clan.name())))
rollverify_count = aleabot.config.get('rollverify_count')
state[rollverify_key] = state[rollverify_key][0:rollverify_count]
bot.writeState('global')
elif request[0] == 'rollverifyrequest':
# Handle a roll verification request
try:
target_name, target_id = resolve_target(bot,
user_name, user_id, request[1])
# Get config settings
#.........这里部分代码省略.........
示例3: botProcessKmail
# 需要导入模块: from kol.util import Report [as 别名]
# 或者: from kol.util.Report import warning [as 别名]
def botProcessKmail(context, **kwargs):
returnCode = FilterManager.CONTINUE
message = kwargs['kmail']
bot = kwargs['bot']
user_name = str(message['userName'])
user_id = str(message['userId'])
current_time = time.time()
cmd = BotUtils.getKmailCommand(message)
meat = message['meat']
items = message['items']
# Our response
response = ''
# Should items and meat be sent back?
return_goodies = True
# Should a candy heart be sent?
send_heart = False
# if 1 arrow was sent and the kmail is empty, interpret it as "arrow"
if cmd == "" and len(items) == 1 and items[0]['id'] == ITEM_ID_ARROW and items[0]['quantity'] == 1 and meat == 0:
cmd = 'arrow'
if cmd == 'arrow':
# Handle arrow request
if len(items) == 1 and items[0]['id'] == ITEM_ID_ARROW and items[0]['quantity'] == 1 and meat == 0:
# Everything is okay
try:
Report.info('bot', 'Firing arrow at player: ' + user_name)
arrowreq = CursePlayerRequest(bot.session, user_id, ITEM_ID_ARROW)
arrowreq.doRequest()
return_goodies = False
except Error.Error as err:
if err.code == Error.ITEM_NOT_FOUND:
response = aleabot.config.get('error_arrow_no_arrows')
elif err.code == Error.USER_NOT_FOUND:
response = aleabot.config.get('error_arrow_player_not_found')
elif err.code == Error.USER_IN_HARDCORE_RONIN:
response = aleabot.config.get('error_arrow_ronin')
elif err.code == Error.ALREADY_COMPLETED:
response = aleabot.config.get('error_arrow_already_hit')
else:
response = aleabot.config.get('error_arrow_generic')
elif len(items) == 0 and meat == 0:
Report.warning('bot', 'Arrow request without arrow from ' + user_name)
response = aleabot.config.get('kmailtext_arrow_notattached')
else:
Report.warning('bot', 'Arrow request with extra items or meat from ' + user_name)
response = aleabot.config.get('kmailtext_arrow_extraattached')
elif cmd == 'donate' or cmd == 'donation':
# Handle donation
if len(items) == 0 and meat == 0:
# Empty donation kmail?
Report.warning('bot', 'Empty donation received from ' + user_name)
response = aleabot.config.get('kmailtext_donate_empty')
else:
Report.info('bot', 'Donation received from ' + user_name)
response = aleabot.config.get('kmailtext_donate_thanks')
return_goodies = False
send_heart = True
else:
# Handle unknown command
Report.warning('bot', 'Unknown kmail command: ' + cmd)
response = aleabot.config.get('kmailtext_unknown')
# Send our response
if response != '' or (return_goodies and (len(items) != 0 or meat != 0)):
Report.info('bot', 'Responding to kmail')
response_kmail = {}
response_kmail['userId'] = message['userId']
response_kmail['text'] = format_reply(response + '\n\n' + aleabot.config.get('kmailtext_quote'), user_name=user_name, user_id=user_id, current_time=current_time) + '\n' + quote_kmail(message)
if return_goodies:
response_kmail['items'] = items
response_kmail['meat'] = meat
try:
bot.sendKmail(response_kmail)
except Error.Error as err:
if err.code == Error.USER_IN_HARDCORE_RONIN:
Report.error('bot', 'Tried to send items and meat back, but user is in Hardcore or Ronin!')
response_kmail2 = {}
response_kmail2['userId'] = message['userId']
response_kmail2['text'] = format_reply(response + '\n\n' + aleabot.config.get('kmailtext_quote_ronin'), user_name=user_name, user_id=user_id, curent_time=current_time) + '\n' + quote_kmail(message)
try:
bot.sendKmail(response_kmail2)
except Error.Error as err2:
Report.error('bot', 'Unexpected error while sending response_kmail2: ' + str(err2))
else:
Report.error('bot', 'Unexpected error while sending response_kmail: ' + str(err))
# Send a candy heart
if send_heart:
try:
Report.info('bot', 'Sending candy heart to player: ' + user_name)
heartreq = CursePlayerRequest(bot.session, user_id, ITEM_ID_CANDYHEART)
heartreq.requestData['texta'] = 'THANK'
heartreq.requestData['textb'] = 'YOU'
#.........这里部分代码省略.........