基于异步的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是验证javax的正确方法。坚持不懈实体管理器。移除(对象实体)实际移除了实体   安卓通过网络JAVA发送文件   java Android 3.0加载器将永远保留   JavaSpringBoot2。x自动将HTTP重定向到HTTPS   java我想创建一个spring批处理项目,其中批处理不使用我的数据源   java在jsp中获取线程本地类的实例   java IntelliJ运行自己对processResources gradle任务的解释   使用Java代码将SPARQL查询到DBPedia   java为什么JFrame绘制图形三次而不是一次?   无法运行编译的Java代码无法找到或加载主类   java 安卓:如何实现splashscreen   java如何通过共享链接获取当前位置数据(Android应用程序开发)?   java在连接其他线程时被中断