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


Python IRCClient.blocking方法代码示例

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


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

示例1: send

# 需要导入模块: from oyoyo.client import IRCClient [as 别名]
# 或者: from oyoyo.client.IRCClient import blocking [as 别名]
    def send(self, text, **kwargs):

        server, channel = self.contact_info.split("/")
        try: server, port = server.split(":")
        except: port = "6667"
        
        server = server.strip().lower()
        channel = channel.strip()
        port = int(port.strip())
        
        # for referencing in active_connectoins
        key = "%s:%d" % (server, port)
        
        
        # do we already have an existing connection?
        active = self.active_connections.get(key, None)
        if active:
            self.log.info("found existing connection to %s" % key)
            conn, client = active
            client.started = time.time()
            client.command_handler.channel_cache[channel] = self.channel
            client.connected_event.wait()
            helpers.join(client, channel)
            helpers.msg(client, channel, text)
        
        # or do we need a new connection?
        else:            
            def connect_cb(client):
                self.log.info("called connect callback")
                client.connected_event.send()
                eventlet.spawn_n(join_cb, client)
                
            def join_cb(client):
                self.log.info("called join callback")
                client.got_nick_event.wait()                
                helpers.join(client, channel)
                helpers.msg(client, channel, text)
            
            self.log.info("we need a new irc connection to %s", key)
            client = IRCClient(
                IRCHandler, host=server,
                port=port, nick="PanoptaOutage",
                connect_cb=connect_cb, blocking=True
            )
            client.connected_event = eventlet.event.Event()
            client.got_nick_event = eventlet.event.Event()
            client.command_handler.channel_cache[channel] = self.channel
            client.command_handler.log = self.log
            client.command_handler.server = server
            client.started = time.time()
            client.blocking = False
            
            self.log.info("connecting to %s", key)
            conn = client.connect()
            
            self.active_connections[key] = (conn, client)
        
            # this will disconnect after 60 seconds
            def persist_in_background():
                client.started = time.time()
                self.log.info("idling connection to %s for %d seconds" % (key, IRC.timeout))
                
                while client.started + IRC.timeout > time.time() and conn.next():
                    time.sleep(0.5)

                self.log.info("disconnecting from %s" % key)
                del self.active_connections[key]
                
                quit_messages = [
                    "herpderp",
                    "I want to die peacefully in my sleep, like my grandfather.. Not screaming like the passengers in his car.",
                    "Do not argue with an idiot. He will drag you down to his level and beat you with experience.",
                    "If I agreed with you we'd both be wrong.",
                    "The early bird might get the worm, but the second mouse gets the cheese.",
                    "I thought I wanted a career, turns out I just wanted paychecks.",
                    "I didn't say it was your fault, I said I was blaming you.",
                ]
                helpers.quit(client, random.choice(quit_messages))
                    
            eventlet.spawn_n(persist_in_background)
        
        return "irc message to %s" % self.contact_info
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:84,代码来源:IRC.py

示例2: chanTopic

# 需要导入模块: from oyoyo.client import IRCClient [as 别名]
# 或者: from oyoyo.client.IRCClient import blocking [as 别名]
	def chanTopic(self, chan, topic):
		'''Update Chan topic'''
		newTopic = str(topic)

		# Split the new topic into segments
		newSegments = [item.strip() for item in newTopic.split('-')]

		# Fetch old topic segments, if any exist
		try:
			f = open('%s.txt' % chan, 'r')
			oldSegments = [item.strip() for item in f.readlines()]
			f.close()
		except IOError:
			oldSegments = []

		# Save and tweet new segments
		for newSegment in newSegments:
			if newSegment not in oldSegments:
				f = open('%s.txt' % chan, 'a')
				f.write(newSegment + '\n')
				f.close()
				api['Channel'].PostUpdate(newSegment)

 
cli = IRCClient(MyHandler, host="irc.server.org", port=6667, nick="TwitterBot")
cli.blocking = True

app = IRCApp()
app.addClient(cli)
app.run()
开发者ID:johndrinkwater,项目名称:twit-topic,代码行数:32,代码来源:twittopic.py


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