當前位置: 首頁>>代碼示例>>Python>>正文


Python UtilBot.add_to_blocklist方法代碼示例

本文整理匯總了Python中Core.Util.UtilBot.add_to_blocklist方法的典型用法代碼示例。如果您正苦於以下問題:Python UtilBot.add_to_blocklist方法的具體用法?Python UtilBot.add_to_blocklist怎麽用?Python UtilBot.add_to_blocklist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Core.Util.UtilBot的用法示例。


在下文中一共展示了UtilBot.add_to_blocklist方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: block

# 需要導入模塊: from Core.Util import UtilBot [as 別名]
# 或者: from Core.Util.UtilBot import add_to_blocklist [as 別名]
def block(bot, event, username=None, *args):
    if not username:
        segments = [hangups.ChatMessageSegment("Blocked Users: ", is_bold=True),
                    hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK),
                    hangups.ChatMessageSegment("No users blocked.")]
        if len(UtilBot.get_blocked_users_in_conversations(event.conv_id)) > 0:
            segments.pop()
            for user in event.conv.users:
                if UtilBot.is_user_blocked(event.conv_id, user.id_):
                    segments.append(hangups.ChatMessageSegment(user.full_name))
                    segments.append(hangups.ChatMessageSegment("\n", segment_type=hangups.SegmentType.LINE_BREAK))
            segments.pop()
        bot.send_message_segments(event.conv, segments)
        return
    username_lower = username.strip().lower()
    for u in sorted(event.conv.users, key=lambda x: x.full_name.split()[-1]):
        if not username_lower in u.full_name.lower() or event.user.is_self:
            continue

        if u.id_ == event.user.id_:
            bot.send_message(event.conv, "Aborting block as it would block calling user. ({})".format(u.full_name))
            return

        if UtilBot.is_user_blocked(event.conv_id, u.id_):
            UtilBot.remove_from_blocklist(event.conv_id, u.id_)
            bot.send_message(event.conv, "Unblocked User: {}".format(u.full_name))
            return
        UtilBot.add_to_blocklist(event.conv_id, u.id_)
        bot.send_message(event.conv, "Blocked User: {}".format(u.full_name))
        return
開發者ID:busterkieton,項目名稱:HangoutsBot,代碼行數:32,代碼來源:DefaultCommands.py


注:本文中的Core.Util.UtilBot.add_to_blocklist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。