基于异步的rfc2812兼容irc客户端

bottom的Python项目详细描述


https://readthedocs.org/projects/bottom-docs/badge?style=flat-squarehttps://img.shields.io/travis/numberoverzero/bottom/master.svg?style=flat-squarehttps://img.shields.io/codecov/c/github/numberoverzero/bottom/master.svg?style=flat-squarehttps://img.shields.io/pypi/v/bottom.svg?style=flat-squarehttps://img.shields.io/github/issues-raw/numberoverzero/bottom.svg?style=flat-squarehttps://img.shields.io/pypi/l/bottom.svg?style=flat-square

基于异步的RFC2812兼容IRC客户端(3.5+)

底部不是厨房水槽图书馆。相反,它提供了一致的api 有一个小的表面积,调整性能和易于扩展。 与bottle.py的路由样式类似,连接到事件是一行。

安装

pip install bottom

开始

(完整的文档可在此处获得:http://bottom-docs.readthedocs.io/

创建实例:

importasyncioimportbottomhost='chat.freenode.net'port=6697ssl=TrueNICK="bottom-bot"CHANNEL="#bottom-dev"bot=bottom.Client(host=host,port=port,ssl=ssl)

建立连接时发送nick/user/join:

@bot.on('CLIENT_CONNECT')asyncdefconnect(**kwargs):bot.send('NICK',nick=NICK)bot.send('USER',user=NICK,realname='https://github.com/numberoverzero/bottom')# Don't try to join channels until the server has# sent the MOTD, or signaled that there's no MOTD.done,pending=awaitasyncio.wait([bot.wait("RPL_ENDOFMOTD"),bot.wait("ERR_NOMOTD")],loop=bot.loop,return_when=asyncio.FIRST_COMPLETED)# Cancel whichever waiter's event didn't come in.forfutureinpending:future.cancel()bot.send('JOIN',channel=CHANNEL)

响应ping:

@bot.on('PING')defkeepalive(message,**kwargs):bot.send('PONG',message=message)

回送消息(频道和直接):

@bot.on('PRIVMSG')defmessage(nick,target,message,**kwargs):""" Echo all messages """# don't echo selfifnick==NICK:return# respond directlyiftarget==NICK:target=nickbot.send("PRIVMSG",target=target,message=message)

连接并永远运行机器人:

bot.loop.create_task(bot.connect())bot.loop.run_forever()

API

完整的api由1个类组成,有8个方法:

# manage connectionsasyncClient.connect()asyncClient.disconnect()# send, receive, and wait for rfc-2812 messagesClient.send(command,**kwargs)@Client.on(event)Client.trigger(event,**kwargs)asyncClient.wait(event)# send and receive anything newline-terminated,# provided for eg. IRCv3 extensionsClient.send_raw(message)Client.handle_raw(message)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring安全编程授权   java Android库AAR取决于另一个库   Java/Groovy双精度语句问题   爪哇。查看安卓监视器图形时,release()不会减少我的内存   java无法在子类中使用EventFiringWebDriver对象   java第一个if语句始终为true,但第二个if语句不为true   java如何从作为字符串提供的XML源代码创建可绘制(或XmlResourceParser对象)?   多线程Java并发问题锁和同步方法   java Android Studio注册链接   java ArrayList of ArrayList of String   使用Shadow重新定位的包中的java Kotlin属性不起作用   java在接口org上找不到方法。阿帕奇。伊巴蒂斯。遗嘱执行人。陈述名为prepare的语句处理程序   如何在Java中放大2倍?   java当参数作为RequestBody和RequestParam发送时,sprig控制器无法识别发送的请求