move save of config to separate method in IrcAdmin, save config when receiving ^C
This commit is contained in:
parent
88186e1425
commit
861c343f2b
1
TODO
1
TODO
@ -10,7 +10,6 @@ dr.botzo --- TODO
|
||||
* karma v2
|
||||
* some sort of cron interface (periodic events)
|
||||
* named pipe to send commands to the bot outside of IRC
|
||||
* properly save when receiving ^C
|
||||
* url module
|
||||
* direct adds implied. also do historical urls?
|
||||
* last 20 or something?
|
||||
|
@ -15,6 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ConfigParser import NoOptionError
|
||||
import signal
|
||||
import sys
|
||||
|
||||
from irclib import irclib
|
||||
@ -29,6 +30,9 @@ class IrcAdmin(Module):
|
||||
super(IrcAdmin, self).__init__(config, server, modlist)
|
||||
modlist.append(self)
|
||||
|
||||
# we define save, so we'll bite the bullet and take SIGINT
|
||||
signal.signal(signal.SIGINT, self.sigint_handler)
|
||||
|
||||
def register_handlers(self, server):
|
||||
server.add_global_handler('welcome', self.on_connect)
|
||||
server.add_global_handler('pubmsg', self.on_pubmsg)
|
||||
@ -99,8 +103,7 @@ class IrcAdmin(Module):
|
||||
if replypath is not None:
|
||||
connection.privmsg(replypath, 'quitting')
|
||||
connection.quit(' '.join(whats[1:]))
|
||||
with open('dr.botzo.cfg', 'w') as cfg:
|
||||
self.config.write(cfg)
|
||||
self.save_config()
|
||||
sys.exit()
|
||||
|
||||
def sub_autojoin_manipulate(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
@ -158,5 +161,16 @@ class IrcAdmin(Module):
|
||||
else:
|
||||
connection.privmsg(replypath, replystr)
|
||||
|
||||
# Save the config file.
|
||||
def save_config(self):
|
||||
with open('dr.botzo.cfg', 'w') as cfg:
|
||||
self.config.write(cfg)
|
||||
|
||||
# SIGINT signal handler
|
||||
def sigint_handler(self, signal, frame):
|
||||
self.save_config()
|
||||
print('saved config')
|
||||
sys.exit()
|
||||
|
||||
# vi:tabstop=4:expandtab:autoindent
|
||||
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
||||
|
Loading…
Reference in New Issue
Block a user