本文整理汇总了Python中oyoyo.client.IRCClient.connected_event方法的典型用法代码示例。如果您正苦于以下问题:Python IRCClient.connected_event方法的具体用法?Python IRCClient.connected_event怎么用?Python IRCClient.connected_event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oyoyo.client.IRCClient
的用法示例。
在下文中一共展示了IRCClient.connected_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from oyoyo.client import IRCClient [as 别名]
# 或者: from oyoyo.client.IRCClient import connected_event [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