本文整理汇总了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