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


Python Stream.recv方法代码示例

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


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

示例1: run

# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import recv [as 别名]
    def run(self):
        """Starts the loop"""
        print (NICK)
        print ("Bot.run()")

        Stream.connect((NETWORK, PORT))
        # receive buffer, and connect setup
        Stream.recv(4096)  # rcv buffer
        Stream.send("NICK " + NICK + "\r\n")
        Stream.send("USER magikarp magikarp magikarp :magikarp\r\n")

        # main loop
        while True:
            data = Stream.recv(4096)  # get lines
            print (data)  # print lines

            # Basic init commands after server connection
            if data.find("MODE " + NICK + " +i") != -1:
                Stream.send("JOIN " + CHAN + "\r\n")
                # Stream.send('PRIVMSG ' + CHAN + ' :Morning, ' + CHAN + '\r\n')

            # Constant ping lookout
            if data.find("PING") != -1:
                Stream.send("PONG " + data.split()[1] + "\r\n")

            elif data.find("PRIVMSG") != -1:  # if there is a PRIVMSG in data then parse it
                message = ":".join(data.split(":")[2:])  # split the command from the message
                print (message)

                function = message.split()[0]  # split the massage to get function name

                if (
                    message.lower().find("awesome") != -1 and not function.find("^") != -1
                ):  # split the massage to get function name:
                    nick = data.split("!")[0].replace(":", "")  # snatch the nick issuing the command
                    destination = "".join(data.split(":")[:2]).split(" ")[-2]
                    # Stream.send('PRIVMSG ' + destination + ' :Yeah ' + nick + '! Awesome!\r\n')

                if Parser().ContainsAny(message, ["http", "http", "www", ".com", ".org", ".eu"]) == 1:
                    nick = data.split("!")[0].replace(":", "")  # snatch the nick issuing the command
                    destination = "".join(data.split(":")[:2]).split(" ")[-2]
                    arg = data.split()
                    args = []
                    for index, item in enumerate(arg):  # for every index and item in arg
                        if (
                            index > 2
                            and Parser().ContainsAny(item, ["http", "http", "www", ".com", ".org", ".eu"]) == 1
                        ):
                            n = 1
                            if args == []:
                                # item = (item.split(':', 1)[1])
                                args.append(item)
                            else:
                                args.append(" " + item)
                                n += 1

                    args.append("\n")
                    print args

                    if args != "":
                        fileObj = open(FILEDIR + "/botlinks", "a")
                        fileObj.write("[" + destination + "] " + CurrentTimeString() + " " + nick + ": ")
                        for i in args:
                            fileObj.write(i)
                        fileObj.close()

                if message.lower().find("^") != -1:  # if the message contains the chan name
                    nick = data.split("!")[0].replace(":", "")  # snatch the nick issuing the command
                    print ("nick: " + nick)
                    destination = "".join(data.split(":")[:2]).split(" ")[-2]
                    print ("dest: " + destination)
                    function = message.split()[0]  # split the massage to get function name
                    print ("function: " + function)
                    print ("The function called is " + function + " from " + nick)  # command and the caller
                    arg = data.split()  # arg[0] is the actual comand

                    args = ""
                    for index, item in enumerate(arg):  # for every index and item in arg
                        if index > 3:
                            if args == "":
                                args = item
                            else:
                                args += " " + item
                    print (args)

                    if function == "^credits":  # if function is equal to ^credits
                        Stream.send(
                            "PRIVMSG "
                            + destination
                            + " :"
                            + nick
                            + ": I'm developed by magikmw - http://github.com/magikmw/magikarp \r\n"
                        )

                    elif function == "^say":
                        if args != "":
                            # Stream.send('PRIVMSG ' + destination + ' :' + args + '\r\n')
                            Stream.send(
                                "PRIVMSG "
                                + destination
#.........这里部分代码省略.........
开发者ID:magikmw,项目名称:magikarp,代码行数:103,代码来源:bot.py


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