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


Python API.remove_user方法代码示例

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


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

示例1: __init__

# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import remove_user [as 别名]

#.........这里部分代码省略.........
        logging.info("Loading plugins")

        self.plugins.load()

        commands = {
            "PING": self.ping,
            "PRIVMSG": self.privmsg,
            "JOIN": self.join,
            "KICK": self.kick,
            "PART": self.part,
            "MODE": self.mode,
            "QUIT": self.quit
        }

        logging.info("Starting main-loop")
        self.API.send_command("PONG :127.0.0.1")
        self.running = True
        while self.running:
            rlist, wlist, xlist = select([self.socket], [], [], sleep_time)
            if rlist:
                try:
                    msg = self.socket.recv(1024).decode()
                except Exception as ex:
                    logging.exception(ex)
                else:
                    for line in msg.splitlines():
                        logging.info(line)
                        args = line.split(" ")
                        if len(args) >= 1 and args[0] in commands:
                            commands[args[0]](args)

                        elif len(args) >= 2 and args[1] in commands:
                            commands[args[1]](args)

                        else:
                            pass

            self.plugins.loop()

        self.socket.close()

    def ping(self, args: list) -> None:
        # PING :127.0.0.1
        if len(args) >= 2:
            self.API.send_command("PONG " + args[1])

    def privmsg(self, args: list) -> None:
        if len(args) >= 4:
            # :[email protected] PRIVMSG #Dev :plop
            #  ^^^^^^^^^^^                                                  ^^^^
            sender = args[0][1:args[0].find("!")]  # Julien00859
            channel = args[2]  # #Dev
            if channel in self.API.get_channels():
                self.plugins.public_message(channel, sender, " ".join(args[3:len(args)])[1:])

            elif channel == self.API.get_bot_nick():
                self.plugins.private_message(sender, " ".join(args[3:len(args)])[1:])

    def join(self, args: list) -> None:
        if len(args) >= 3:
            # :[email protected] JOIN :#Dev
            #  ^^^^^^^^^^^                                                ^^^^
            sender = args[0][1:args[0].find("!")]  # Julien00859
            channel = args[2][1:]  # #Dev
            self.API.add_update_user(channel, sender)
            self.plugins.join(channel, sender)

    def kick(self, args: list) -> None:
        # :[email protected] KICK #Dev Julien00859 :You have been kicked
        #  ^^^^^^^^^                                               ^^^^ ^^^^^^^^^^^
        if len(args) >= 4:
            sender = args[0][1:args[0].find("!")]  # Julien008
            self.API.remove_user(args[2], args[3])
            self.plugins.kick(sender, args[2], args[3])

    def part(self, args: list) -> None:
        if len(args) >= 3:
            # :[email protected] PART #Dev :"Gonna bake some cookies..."
            #  ^^^^^^^^^^^                                               ^^^^
            sender = args[0][1:args[0].find("!")]  # Julien00859
            self.API.remove_user(args[2], sender)
            self.plugins.part(args[2], sender)

    def mode(self, args: list) -> None:
        # :[email protected] MODE #Dev +h Julien00859
        #  ^^^^^^^^^                                               ^^^^ ^^ ^^^^^^^^^^^

        sender = args[0][1:args[0].find("!")]  # Julien008
        if len(args) >= 5:
            self.API.send_names_query(args[2])
            self.plugins.mode(sender, args[2], args[3], args[4])

    def quit(self, args: list) -> None:
        if len(args) >= 1:
            # :[email protected] QUIT :Quit: Keep calm and do not rage quit
            #  ^^^^^^^^^^^
            sender = args[0][1:args[0].find("!")]  # Julien00859
            for channel in self.API.get_channels():
                self.API.remove_user(channel, sender)
                self.plugins.quit(sender)
开发者ID:Julien00859,项目名称:BotIRC,代码行数:104,代码来源:main.py


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