當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。