电报机器人框架

telegraph_commander的Python项目详细描述


#电报指挥官电报简单机器人框架首先,扩展basebot类,并提供路由器和配置:
`` python
来自telegraph_commander.logger import get_console_handler
来自telegraph_commander.bot import basebot
来自telegraph_commander.command import command router,botcommand
从telegraph_commander.config导入botconfig





yourbotconfig类(botconfig):
telegraph_api_key='<;api_key>;'
默认_命令='菜单'



class yourbot(basebot):
router_class=commandrouter
config_class=yourbotconfig


````

2.将命令绑定到路由器:
`` python
@bot.router.command('menu')
类menucommand(botcommand):
异步定义运行(self):
等待self.telegram_api.send_消息(self.chat_id,'select action',变体= [BR/> BR/> @ BR/> @ Boo.Cube。命令('MUL)
类MuleCu命令(BOTCORMART):
PARAM=(
DICT(name =“操作数1”,标题=“第一个参数”),
DICT(name=操作数2),title='second argument')

异步定义运行句柄(self):
结果=浮点(self.operand_1)*浮点(self.operand_2)
等待self.telegram_api.send_消息(self.chat_id,'result:{}.format(result))
````

3.添加控制台日志处理程序(可选),并运行bot:
``python
bot.logger.add handler(get_console_handler())
bot.run()
```

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

推荐PyPI第三方库


热门话题
java数据未插入SQLite数据库   Java中内存有效的对象创建   java在方法内部使用“this”(不用于调用方法、构造函数或变量)   java为什么这里会出现NullPointerException?   在REST中使用HATEOAS导致的java循环依赖   java如何定制spring boot横幅?   Java数字基数计算器(即基数10到基数5)   如果在Kotlin vs Java中声明,用作全局上下文的安卓 MainApplication类将崩溃   用于过滤对象的Java lambda函数   java从字符串数组中获取整数列表   java为什么Maven找不到org。json JPMS自动模块?   java将字符串数组转换为int   仅当与阈值字节匹配时,java才会在映射中填充字符串值