如何在Errbot中正确设置插件的配置?

时间:2018-06-08 13:44:38

标签: python plugins configuration errbot

我尝试按照文档提供的示例进行操作:

9.1. Plugin configuration through the built-in !config command

但是,我无法恢复设置为'NoneType'的插件配置

[@admin ➡ @errbot] >>> !plugin config Samples
Default configuration for this plugin (you can copy and paste this directly as a command):
 !plugin config Samples
{'ID_TOKEN': '00112233445566778899aabbccddeeff', 'USERNAME': 'changeme'}


[@admin ➡ @errbot] >>> !mycommand
Computer says nooo. See logs for details:
 'NoneType' object is not subscriptable

[@admin ➡ @errbot] >>> !about
This is Errbot version 5.2.0

这是我的插件代码sample.py

from errbot import BotPlugin, botcmd

class Samples(BotPlugin):
    """Samples of plugins from Errbot documentation"""

    # 9. Configuration
    # 9.1. Plugin configuration through the built-in !config command
    def get_configuration_template(self):
        return {'ID_TOKEN': '00112233445566778899aabbccddeeff',
                'USERNAME':'changeme'}

    @botcmd
    def mycommand(self, mess, args):
        # oh I need my TOKEN !
        token = self.config['ID_TOKEN']

我不确定这是一个错误还是错误的配置。

解决方案

我必须在给出配置后调用

[@admin ➡ @errbot] >>> !plugin config Samples {'ID_TOKEN' : '00112233445566778899aabbccddeeff', 'USERNAME':'changeme'}
Plugin configuration done.

[@admin ➡ @errbot] >>> !mycommand
00112233445566778899aabbccddeeff

@gbin感谢您的帮助

1 个答案:

答案 0 :(得分:1)

你需要发送带有json配置的config命令,这里errbot只是告诉你需要做什么来配置它。