电报机器人框架

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 ADB设备不显示手机、og droid   java使用存储和保存方法写入属性文件   java为什么要打印这个结果   JavaSpring自动连线和并行流   java如何在Hashmap中存储KStream对象类型的值?   Android中Telugu字符串的java正则表达式?   java平方求幂   Eclipse和Tomcat的java错误   Java数组不继续循环   Jsoup未解析java嵌套html   java Android:如何知道MediaPlayer是否暂停?   跟踪Java POJO类中字段的空值集的最佳方法   java Spring在应用程序属性相对与绝对中配置工作目录?   向固定大小的平面添加随机放置的直线矩形的java方法   JavaEclipse和jasper报告:如何定位log4j。财产?