电报机器人框架
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()
```
`` 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()
```