当前位置: 首页>>代码示例>>Python>>正文


Python UtilBot.get_current_karma方法代码示例

本文整理汇总了Python中Core.Util.UtilBot.get_current_karma方法的典型用法代码示例。如果您正苦于以下问题:Python UtilBot.get_current_karma方法的具体用法?Python UtilBot.get_current_karma怎么用?Python UtilBot.get_current_karma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Core.Util.UtilBot的用法示例。


在下文中一共展示了UtilBot.get_current_karma方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: karma

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import get_current_karma [as 别名]
def karma(bot, event, name=None, *args):
    if name:
        if name[0] == '@':
            name = name[1:]
        lower_name = name.lower()
        for u in sorted(event.conv.users, key=lambda x: x.full_name.split()[-1]):
            if lower_name not in u.full_name.lower():
                continue

            segments = [hangups.ChatMessageSegment('%s:' % u.full_name, is_bold=True),
                        hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                        hangups.ChatMessageSegment('Karma: ' + str(UtilBot.get_current_karma(u.id_[0])))]
            bot.send_message_segments(event.conv, segments)
            return
        bot.send_message(event.conv, 'No user found matching "%s".' % name)

    else:
        karma_list = []
        list_num = min(5, int(len(event.conv.users) / 2) + 1)
        for u in event.conv.users:
            karma_list.append((u.full_name, UtilBot.get_current_karma(u.id_[0])))
        karma_list.sort(key=lambda x: -x[1])
        segments = [hangups.ChatMessageSegment("Karma Stats:", is_bold=True),
                    hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK),
                    hangups.ChatMessageSegment("Top:", is_italic=True),
                    hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK)]
        if len(event.conv.users) > 10:
            for i in range(0, min(list_num, len(event.conv.users))):
                segments.append(hangups.ChatMessageSegment("{}: {}".format(karma_list[i][0], karma_list[i][1])))
                segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))

            segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))
            segments.append(hangups.ChatMessageSegment("Bottom:", is_italic=True))
            segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))

            for i in range(-1, -min(list_num, len(event.conv.users)) - 1, -1):
                segments.append(hangups.ChatMessageSegment("{}: {}".format(karma_list[i][0], karma_list[i][1])))
                segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))
        else:
            for i in range(0, len(event.conv.users)):
                segments.append(hangups.ChatMessageSegment("{}: {}".format(karma_list[i][0], karma_list[i][1])))
                segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))

        segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))
        segments.append(hangups.ChatMessageSegment("Average Karma:", is_italic=True))
        segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))
        segments.append(hangups.ChatMessageSegment('{}'.format((sum([i[1] for i in karma_list]) / len(karma_list)))))
        bot.send_message_segments(event.conv, segments)
开发者ID:busterkieton,项目名称:HangoutsBot,代码行数:50,代码来源:DefaultCommands.py


注:本文中的Core.Util.UtilBot.get_current_karma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。