本文整理匯總了Python中Core.Util.UtilBot.define方法的典型用法代碼示例。如果您正苦於以下問題:Python UtilBot.define方法的具體用法?Python UtilBot.define怎麽用?Python UtilBot.define使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Core.Util.UtilBot
的用法示例。
在下文中一共展示了UtilBot.define方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: define
# 需要導入模塊: from Core.Util import UtilBot [as 別名]
# 或者: from Core.Util.UtilBot import define [as 別名]
def define(bot, event, *args):
"""
**Define:**
Usage: /define <word to search for> <optional: definition number [defaults to 1] OR * to show all definitions>
Usage: /define <word to search for> <start index and end index in form of int:int (e.g., /define test 1:3)>
Purpose: Show definitions for a word.
"""
if args[-1].isdigit():
definition, length = UtilBot.define(' '.join(args[0:-1]), num=int(args[-1]))
segments = [hangups.ChatMessageSegment(' '.join(args[0:-1]).title(), is_bold=True),
hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
hangups.ChatMessageSegment(
definition.replace('\n', ''))]
bot.send_message_segments(event.conv, segments)
elif args[-1] == '*':
args = list(args)
args[-1] = '1:*'
if ':' in args[-1]:
start, end = re.split(':', args[-1])
try:
start = int(start)
except ValueError:
start = 1
display_all = False
if end == '*':
end = 100
display_all = True
else:
try:
end = int(end)
except ValueError:
end = 3
if start < 1:
start = 1
if start > end:
end, start = start, end
if start == end:
end += 1
if len(args) <= 1:
bot.send_message(event.conv, "Invalid usage for /define.")
return
query = ' '.join(args[:-1])
definition_segments = [hangups.ChatMessageSegment(query.title(), is_bold=True),
hangups.ChatMessageSegment('', segment_type=hangups.SegmentType.LINE_BREAK)]
if start < end:
x = start
while x <= end:
definition, length = UtilBot.define(query, num=x)
definition_segments.append(hangups.ChatMessageSegment(definition))
if x != end:
definition_segments.append(
hangups.ChatMessageSegment('', segment_type=hangups.SegmentType.LINE_BREAK))
definition_segments.append(
hangups.ChatMessageSegment('', segment_type=hangups.SegmentType.LINE_BREAK))
if end > length:
end = length
if display_all:
end = length
display_all = False
x += 1
bot.send_message_segments(event.conv, definition_segments)
return
else:
args = list(args)
args.append("1:3")
define(bot, event, *args)
return