一个python3库,用于轻松构建devrant机器人
drbot的Python项目详细描述
drbot
python3库,用于轻松构建devrant机器人程序
使用
要创建bot,只需扩展BotBuilder
类并定义onNotif()
方法
fromdrbot.botbuilderimportBotBuilder,NotifType# Testing setupclassMyBot(BotBuilder):onNotif(self,type,content):# Handle notifs herepass# Create a botmy_bot=MyBot("username","password")# Set how long the bot should wait between notif queries (in seconds)interval=10# Start the botmy_bot.start(interval)
就这样!
使用API
每个BotBuilder
类都有一个内置的api包装器。这可以通过self.api
访问,并包含以下方法:
getUserInfo(username:str)->dictgetUsername(user_id:int)->strpostRant(body:str,tags:str)->NonepostComment(rant_id:int,content:str)->NonegetComment(comment_id:int)->dict
BotBuilder
自动处理登录、会话、notif管理和一些数据解析。如果您希望覆盖这些方法,您可能会对以下api方法感兴趣:
login(username:str,password:str)->NonehasAuthExpired()->boolgetNotifs()->listclearNotifs()->NonegetUserId(username:str)->int
安装
这个库在pypi上是可用的。
安装python3.7
和python3-pip
后,运行:
pip3 install drbot
安装drbot