Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #32 from alanbriolat/master

Disable configuration saving
  • Loading branch information...
commit 378f75c3287ea6240afeb7d24660259ef11a223b 2 parents 1856d72 + d4676e8
@Haegin Haegin authored
Showing with 25 additions and 27 deletions.
  1. +0 −4 csbot/core.py
  2. +25 −23 doc/writing-plugins.rst
View
4 csbot/core.py
@@ -93,10 +93,6 @@ def teardown(self):
super(Bot, self).teardown()
self.plugins.broadcast('teardown', static=False)
- # Save configuration
- with open(self.config_path, 'w') as cfg:
- self.config_root.write(cfg)
-
def post_event(self, event):
self.events.post_event(event)
View
48 doc/writing-plugins.rst
@@ -110,17 +110,13 @@ dictionary in addition to supporting its own API.
An example of using plugin configuration::
- class Bomb(Plugin):
- """A bomb which remembers if it was armed or not, even across bot restarts."""
- @Plugin.command('explode')
- def explode(self, e):
- if self.config.getboolean('armed', False):
- print('Boom!')
- self.config['armed'] = False
-
- @Plugin.command('arm')
- def arm(self, e):
- self.config['armed'] = True
+ class Say(Plugin):
+ @Plugin.command('say')
+ def say(self, e):
+ if self.config.getboolean('shout', False):
+ e.protocol.msg(e['reply_to'], e['data'].upper() + '!')
+ else:
+ e.protocol.msg(e['reply_to'], e['data'])
For even more convenience, automatic fallback values are supported through the
:attr:`~.Plugin.CONFIG_DEFAULTS` attribute when using the :meth:`~.Plugin.config_get` or
@@ -129,21 +125,27 @@ For even more convenience, automatic fallback values are supported through the
supports and what the default values are by looking at just one part of the plugin source code. The
above example would look like this::
- class Bomb(Plugin):
+ class Say(Plugin):
CONFIG_DEFAULTS = {
- 'armed': False,
+ 'shout': False,
}
- @Plugin.command('explode')
- def explode(self, e):
- if self.config_getboolean('armed'):
- print('Boom!')
- self.config['armed'] = False
-
- @Plugin.command('arm')
- def arm(self, e):
- self.config['armed'] = True
-
+ @Plugin.command('say')
+ def say(self, e):
+ if self.config_getboolean('shout'):
+ e.protocol.msg(e['reply_to'], e['data'].upper() + '!')
+ else:
+ e.protocol.msg(e['reply_to'], e['data'])
+
+Configuration can be changed at runtime, but won't be saved. This allows for temporary state
+changes, whilst ensuring the startup state of the bot reflects the configuration file. For example,
+the above plugin could be modified with a toggle for the "shout" mode::
+
+ class Say(Plugin):
+ # ...
+ @Plugin.command('toggle')
+ def toggle(self, e):
+ self.config['shout'] = not self.config_get('shout')
Database
--------
Please sign in to comment.
Something went wrong with that request. Please try again.