2012-08-14 03:51:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
|
|
|
# Copyright (C) 2012 Mercier Pierre-Olivier
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-08-16 02:32:47 +00:00
|
|
|
from datetime import datetime
|
2012-10-15 00:46:23 +00:00
|
|
|
from datetime import timedelta
|
2012-08-23 16:20:45 +00:00
|
|
|
from queue import Queue
|
2012-08-16 02:32:47 +00:00
|
|
|
import threading
|
2012-10-15 00:46:23 +00:00
|
|
|
import time
|
2012-08-16 02:32:47 +00:00
|
|
|
|
2012-10-04 11:36:25 +00:00
|
|
|
import consumer
|
2012-08-14 04:56:28 +00:00
|
|
|
import event
|
2012-08-31 03:21:19 +00:00
|
|
|
import hooks
|
2012-08-27 22:27:02 +00:00
|
|
|
from networkbot import NetworkBot
|
2012-11-02 11:10:37 +00:00
|
|
|
from IRCServer import IRCServer
|
|
|
|
import response
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-30 23:36:23 +00:00
|
|
|
ID_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
|
2012-08-31 03:21:19 +00:00
|
|
|
class Bot:
|
2012-11-02 11:10:37 +00:00
|
|
|
def __init__(self, ip, realname, mp=list()):
|
2012-08-31 03:21:19 +00:00
|
|
|
# Bot general informations
|
2012-11-02 11:10:37 +00:00
|
|
|
self.version = 3.3
|
|
|
|
self.version_txt = "3.3-dev"
|
|
|
|
|
|
|
|
# Save various informations
|
|
|
|
self.ip = ip
|
|
|
|
self.realname = realname
|
|
|
|
self.ctcp_capabilities = dict()
|
|
|
|
self.init_ctcp_capabilities()
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-27 22:27:02 +00:00
|
|
|
# Keep global context: servers and modules
|
2012-11-02 11:10:37 +00:00
|
|
|
self.servers = dict()
|
|
|
|
self.modules = dict()
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-27 22:27:02 +00:00
|
|
|
# Context paths
|
2012-08-14 03:51:55 +00:00
|
|
|
self.modules_path = mp
|
2012-08-23 16:20:45 +00:00
|
|
|
self.datas_path = './datas/'
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-27 22:27:02 +00:00
|
|
|
# Events
|
2012-08-23 16:20:45 +00:00
|
|
|
self.events = list()
|
2012-08-16 02:32:47 +00:00
|
|
|
self.event_timer = None
|
|
|
|
|
2012-08-31 03:21:19 +00:00
|
|
|
# Own hooks
|
|
|
|
self.hooks = hooks.MessagesHook(self)
|
|
|
|
|
2012-08-27 22:27:02 +00:00
|
|
|
# Other known bots, making a bots network
|
2012-09-01 13:49:30 +00:00
|
|
|
self.network = dict()
|
2012-08-31 03:21:19 +00:00
|
|
|
self.hooks_cache = dict()
|
2012-08-27 22:27:02 +00:00
|
|
|
|
|
|
|
# Messages to be treated
|
2012-10-04 11:36:25 +00:00
|
|
|
self.cnsr_queue = Queue()
|
|
|
|
self.cnsr_thrd = list()
|
|
|
|
self.cnsr_thrd_size = -1
|
2012-08-23 16:20:45 +00:00
|
|
|
|
2012-08-16 02:32:47 +00:00
|
|
|
|
2012-11-02 11:10:37 +00:00
|
|
|
def init_ctcp_capabilities(self):
|
|
|
|
"""Reset existing CTCP capabilities to default one"""
|
|
|
|
self.ctcp_capabilities["ACTION"] = lambda msg: print ("ACTION receive")
|
|
|
|
self.ctcp_capabilities["CLIENTINFO"] = self._ctcp_clientinfo
|
|
|
|
self.ctcp_capabilities["DCC"] = self._ctcp_dcc
|
|
|
|
self.ctcp_capabilities["NEMUBOT"] = lambda srv, msg: _ctcp_response(
|
|
|
|
msg.sender, "NEMUBOT %f" % self.version)
|
|
|
|
self.ctcp_capabilities["TIME"] = lambda srv, msg: _ctcp_response(
|
|
|
|
msg.sender, "TIME %s" % (datetime.now()))
|
|
|
|
self.ctcp_capabilities["USERINFO"] = lambda srv, msg: _ctcp_response(
|
|
|
|
msg.sender, "USERINFO %s" % self.realname)
|
|
|
|
self.ctcp_capabilities["VERSION"] = lambda srv, msg: _ctcp_response(
|
|
|
|
msg.sender, "VERSION nemubot v%s" % self.version_txt)
|
|
|
|
|
|
|
|
def _ctcp_clientinfo(self, srv, msg):
|
|
|
|
"""Response to CLIENTINFO CTCP message"""
|
|
|
|
return _ctcp_response(msg.sndr,
|
|
|
|
" ".join(self.ctcp_capabilities.keys()))
|
|
|
|
|
|
|
|
def _ctcp_dcc(self, srv, msg):
|
|
|
|
"""Response to DCC CTCP message"""
|
|
|
|
ip = self.srv.toIP(int(msg.cmds[3]))
|
|
|
|
conn = DCC(srv, msg.sender)
|
|
|
|
if conn.accept_user(ip, int(msg.cmds[4])):
|
|
|
|
srv.dcc_clients[conn.sender] = conn
|
|
|
|
conn.send_dcc("Hello %s!" % conn.nick)
|
|
|
|
else:
|
|
|
|
print ("DCC: unable to connect to %s:%s" % (ip, msg.cmds[4]))
|
|
|
|
|
|
|
|
|
2012-09-02 16:40:44 +00:00
|
|
|
def add_event(self, evt, eid=None):
|
2012-08-30 23:36:23 +00:00
|
|
|
"""Register an event and return its identifiant for futur update"""
|
2012-09-02 16:40:44 +00:00
|
|
|
if eid is None:
|
|
|
|
# Find an ID
|
|
|
|
now = datetime.now()
|
|
|
|
evt.id = "%d%c%d%d%c%d%d%c%d" % (now.year, ID_letters[now.microsecond % 52],
|
|
|
|
now.month, now.day, ID_letters[now.microsecond % 42],
|
|
|
|
now.hour, now.minute, ID_letters[now.microsecond % 32],
|
|
|
|
now.second)
|
|
|
|
else:
|
|
|
|
evt.id = eid
|
2012-08-30 23:36:23 +00:00
|
|
|
|
2012-08-16 02:32:47 +00:00
|
|
|
# Add the event in place
|
|
|
|
t = evt.current
|
2012-09-01 13:49:30 +00:00
|
|
|
i = -1
|
2012-08-16 02:32:47 +00:00
|
|
|
for i in range(0, len(self.events)):
|
|
|
|
if self.events[i].current > t:
|
2012-09-01 13:49:30 +00:00
|
|
|
i -= 1
|
2012-08-16 02:32:47 +00:00
|
|
|
break
|
2012-09-01 13:49:30 +00:00
|
|
|
self.events.insert(i + 1, evt)
|
|
|
|
if i == -1:
|
2012-08-16 02:32:47 +00:00
|
|
|
self.update_timer()
|
2012-09-02 16:40:44 +00:00
|
|
|
if len(self.events) <= 0 or self.events[i+1] != evt:
|
|
|
|
return None
|
2012-08-16 02:32:47 +00:00
|
|
|
|
2012-08-30 23:36:23 +00:00
|
|
|
return evt.id
|
|
|
|
|
|
|
|
def del_event(self, id):
|
|
|
|
"""Find and remove an event from list"""
|
2012-09-01 13:49:30 +00:00
|
|
|
if len(self.events) > 0 and id == self.events[0].id:
|
|
|
|
self.events.remove(self.events[0])
|
|
|
|
self.update_timer()
|
|
|
|
return True
|
|
|
|
|
2012-08-30 23:36:23 +00:00
|
|
|
for evt in self.events:
|
|
|
|
if evt.id == id:
|
|
|
|
self.events.remove(evt)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2012-08-16 02:32:47 +00:00
|
|
|
def update_timer(self):
|
2012-08-16 02:53:46 +00:00
|
|
|
"""Relaunch the timer to end with the closest event"""
|
2012-08-16 02:32:47 +00:00
|
|
|
# Reset the timer if this is the first item
|
|
|
|
if self.event_timer is not None:
|
|
|
|
self.event_timer.cancel()
|
|
|
|
if len(self.events) > 0:
|
|
|
|
#print ("Update timer, next in", self.events[0].time_left.seconds,
|
|
|
|
# "seconds")
|
2012-10-15 00:46:23 +00:00
|
|
|
if datetime.now() + timedelta(seconds=5) >= self.events[0].current:
|
|
|
|
while datetime.now() < self.events[0].current:
|
|
|
|
time.sleep(0.6)
|
2012-08-16 02:32:47 +00:00
|
|
|
self.end_timer()
|
|
|
|
else:
|
|
|
|
self.event_timer = threading.Timer(
|
|
|
|
self.events[0].time_left.seconds + 1, self.end_timer)
|
|
|
|
self.event_timer.start()
|
|
|
|
#else:
|
|
|
|
# print ("Update timer: no timer left")
|
|
|
|
|
|
|
|
def end_timer(self):
|
2012-08-16 02:53:46 +00:00
|
|
|
"""Function called at the end of the timer"""
|
2012-08-16 02:32:47 +00:00
|
|
|
#print ("end timer")
|
|
|
|
while len(self.events)>0 and datetime.now() >= self.events[0].current:
|
|
|
|
#print ("end timer: while")
|
|
|
|
evt = self.events.pop(0)
|
2012-11-02 11:10:37 +00:00
|
|
|
self.cnsr_queue.put_nowait(consumer.EventConsumer(evt))
|
2012-10-04 11:36:25 +00:00
|
|
|
self.update_consumers()
|
|
|
|
|
2012-08-16 02:32:47 +00:00
|
|
|
self.update_timer()
|
2012-08-14 04:56:28 +00:00
|
|
|
|
2012-08-14 03:51:55 +00:00
|
|
|
|
|
|
|
def addServer(self, node, nick, owner, realname):
|
|
|
|
"""Add a new server to the context"""
|
2012-11-02 11:10:37 +00:00
|
|
|
srv = IRCServer(node, nick, owner, realname)
|
2012-08-14 03:51:55 +00:00
|
|
|
if srv.id not in self.servers:
|
|
|
|
self.servers[srv.id] = srv
|
|
|
|
if srv.autoconnect:
|
2012-11-02 11:10:37 +00:00
|
|
|
srv.launch(self.receive_message)
|
2012-08-14 03:51:55 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def add_module(self, module):
|
|
|
|
"""Add a module to the context, if already exists, unload the
|
|
|
|
old one before"""
|
|
|
|
# Check if the module already exists
|
|
|
|
for mod in self.modules.keys():
|
|
|
|
if self.modules[mod].name == module.name:
|
|
|
|
self.unload_module(self.modules[mod].name)
|
|
|
|
break
|
|
|
|
|
|
|
|
self.modules[module.name] = module
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def add_modules_path(self, path):
|
|
|
|
"""Add a path to the modules_path array, used by module loader"""
|
|
|
|
# The path must end by / char
|
|
|
|
if path[len(path)-1] != "/":
|
|
|
|
path = path + "/"
|
|
|
|
|
|
|
|
if path not in self.modules_path:
|
|
|
|
self.modules_path.append(path)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def unload_module(self, name, verb=False):
|
|
|
|
"""Unload a module"""
|
|
|
|
if name in self.modules:
|
2012-10-04 11:36:25 +00:00
|
|
|
print (name)
|
2012-08-14 03:51:55 +00:00
|
|
|
self.modules[name].save()
|
|
|
|
if hasattr(self.modules[name], "unload"):
|
2012-09-01 13:49:30 +00:00
|
|
|
self.modules[name].unload(self)
|
2012-09-01 09:23:41 +00:00
|
|
|
# Remove registered hooks
|
|
|
|
for (s, h) in self.modules[name].REGISTERED_HOOKS:
|
|
|
|
self.hooks.del_hook(s, h)
|
2012-08-14 03:51:55 +00:00
|
|
|
# Remove from the dict
|
|
|
|
del self.modules[name]
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2012-10-04 11:36:25 +00:00
|
|
|
def update_consumers(self):
|
|
|
|
"""Launch new consumer thread if necessary"""
|
|
|
|
if self.cnsr_queue.qsize() > self.cnsr_thrd_size:
|
|
|
|
c = consumer.Consumer(self)
|
|
|
|
self.cnsr_thrd.append(c)
|
|
|
|
c.start()
|
|
|
|
self.cnsr_thrd_size += 2
|
|
|
|
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-31 01:52:49 +00:00
|
|
|
def receive_message(self, srv, raw_msg, private=False, data=None):
|
2012-08-23 16:20:45 +00:00
|
|
|
"""Queued the message for treatment"""
|
2012-10-04 11:36:25 +00:00
|
|
|
#print (raw_msg)
|
|
|
|
self.cnsr_queue.put_nowait(consumer.MessageConsumer(srv, raw_msg, datetime.now(), private, data))
|
2012-08-23 16:20:45 +00:00
|
|
|
|
|
|
|
# Launch a new thread if necessary
|
2012-10-04 11:36:25 +00:00
|
|
|
self.update_consumers()
|
2012-08-23 16:20:45 +00:00
|
|
|
|
|
|
|
|
2012-08-27 22:27:02 +00:00
|
|
|
def add_networkbot(self, srv, dest, dcc=None):
|
|
|
|
"""Append a new bot into the network"""
|
|
|
|
id = srv.id + "/" + dest
|
|
|
|
if id not in self.network:
|
|
|
|
self.network[id] = NetworkBot(self, srv, dest, dcc)
|
|
|
|
return self.network[id]
|
|
|
|
|
|
|
|
|
2012-08-14 03:51:55 +00:00
|
|
|
def quit(self, verb=False):
|
|
|
|
"""Save and unload modules and disconnect servers"""
|
2012-08-16 02:53:46 +00:00
|
|
|
if self.event_timer is not None:
|
|
|
|
if verb: print ("Stop the event timer...")
|
|
|
|
self.event_timer.cancel()
|
|
|
|
|
2012-08-14 03:51:55 +00:00
|
|
|
if verb: print ("Save and unload all modules...")
|
|
|
|
k = list(self.modules.keys())
|
|
|
|
for mod in k:
|
|
|
|
self.unload_module(mod, verb)
|
|
|
|
|
|
|
|
if verb: print ("Close all servers connection...")
|
|
|
|
k = list(self.servers.keys())
|
|
|
|
for srv in k:
|
|
|
|
self.servers[srv].disconnect()
|
|
|
|
|
2012-08-31 03:21:19 +00:00
|
|
|
# Hooks cache
|
|
|
|
|
|
|
|
def create_cache(self, name):
|
|
|
|
if name not in self.hooks_cache:
|
|
|
|
if isinstance(self.hooks.__dict__[name], list):
|
|
|
|
self.hooks_cache[name] = list()
|
|
|
|
|
|
|
|
# Start by adding locals hooks
|
|
|
|
for h in self.hooks.__dict__[name]:
|
|
|
|
tpl = (h, 0, self.hooks.__dict__[name])
|
|
|
|
self.hooks_cache[name].append(tpl)
|
|
|
|
|
|
|
|
# Now, add extermal hooks
|
|
|
|
level = 0
|
|
|
|
while level == 0 or lvl_exist:
|
|
|
|
lvl_exist = False
|
|
|
|
for ext in self.network:
|
|
|
|
if len(self.network[ext].hooks) > level:
|
|
|
|
lvl_exist = True
|
|
|
|
for h in self.network[ext].hooks[level].__dict__[name]:
|
|
|
|
if h not in self.hooks_cache[name]:
|
|
|
|
self.hooks_cache[name].append((h, level + 1,
|
|
|
|
self.network[ext].hooks[level].__dict__[name]))
|
|
|
|
level += 1
|
|
|
|
|
|
|
|
elif isinstance(self.hooks.__dict__[name], dict):
|
|
|
|
self.hooks_cache[name] = dict()
|
|
|
|
|
|
|
|
# Start by adding locals hooks
|
|
|
|
for h in self.hooks.__dict__[name]:
|
|
|
|
self.hooks_cache[name][h] = (self.hooks.__dict__[name][h], 0,
|
|
|
|
self.hooks.__dict__[name])
|
|
|
|
|
|
|
|
# Now, add extermal hooks
|
|
|
|
level = 0
|
|
|
|
while level == 0 or lvl_exist:
|
|
|
|
lvl_exist = False
|
|
|
|
for ext in self.network:
|
|
|
|
if len(self.network[ext].hooks) > level:
|
|
|
|
lvl_exist = True
|
|
|
|
for h in self.network[ext].hooks[level].__dict__[name]:
|
|
|
|
if h not in self.hooks_cache[name]:
|
|
|
|
self.hooks_cache[name][h] = (self.network[ext].hooks[level].__dict__[name][h], level + 1, self.network[ext].hooks[level].__dict__[name])
|
|
|
|
level += 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
raise Exception(name + " hook type unrecognized")
|
|
|
|
|
|
|
|
return self.hooks_cache[name]
|
|
|
|
|
|
|
|
# Treatment
|
|
|
|
|
|
|
|
def check_rest_times(self, store, hook):
|
|
|
|
"""Remove from store the hook if it has been executed given time"""
|
|
|
|
if hook.times == 0:
|
|
|
|
if isinstance(store, dict):
|
|
|
|
store[hook.name].remove(hook)
|
|
|
|
if len(store) == 0:
|
|
|
|
del store[hook.name]
|
|
|
|
elif isinstance(store, list):
|
|
|
|
store.remove(hook)
|
|
|
|
|
|
|
|
def treat_pre(self, msg):
|
|
|
|
"""Treat a message before all other treatment"""
|
|
|
|
for h, lvl, store in self.create_cache("all_pre"):
|
|
|
|
h.run(msg)
|
|
|
|
self.check_rest_times(store, h)
|
|
|
|
|
|
|
|
|
2012-11-02 11:10:37 +00:00
|
|
|
def treat_post(self, msg):
|
|
|
|
"""Treat a message before send"""
|
|
|
|
for h, lvl, store in self.create_cache("all_post"):
|
|
|
|
c = h.run(msg)
|
|
|
|
self.check_rest_times(store, h)
|
|
|
|
if not c:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2012-08-31 03:21:19 +00:00
|
|
|
def treat_cmd(self, msg):
|
|
|
|
"""Treat a command message"""
|
|
|
|
treated = list()
|
|
|
|
|
|
|
|
# First, treat simple hook
|
|
|
|
cmd_hook = self.create_cache("cmd_hook")
|
|
|
|
if msg.cmd[0] in cmd_hook:
|
|
|
|
(hks, lvl, store) = cmd_hook[msg.cmd[0]]
|
|
|
|
for h in hks:
|
|
|
|
res = h.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, h)
|
|
|
|
|
|
|
|
# Then, treat regexp based hook
|
|
|
|
cmd_rgxp = self.create_cache("cmd_rgxp")
|
|
|
|
for hook, lvl, store in cmd_rgxp:
|
|
|
|
if hook.is_matching(msg.cmd[0], msg.channel):
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
# Finally, treat default hooks if not catched before
|
|
|
|
cmd_default = self.create_cache("cmd_default")
|
|
|
|
for hook, lvl, store in cmd_default:
|
|
|
|
if treated:
|
|
|
|
break
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
return treated
|
|
|
|
|
|
|
|
def treat_ask(self, msg):
|
|
|
|
"""Treat an ask message"""
|
|
|
|
treated = list()
|
|
|
|
|
|
|
|
# First, treat simple hook
|
|
|
|
ask_hook = self.create_cache("ask_hook")
|
|
|
|
if msg.content in ask_hook:
|
|
|
|
hks, lvl, store = ask_hook[msg.content]
|
|
|
|
for h in hks:
|
|
|
|
res = h.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, h)
|
|
|
|
|
|
|
|
# Then, treat regexp based hook
|
|
|
|
ask_rgxp = self.create_cache("ask_rgxp")
|
|
|
|
for hook, lvl, store in ask_rgxp:
|
|
|
|
if hook.is_matching(msg.content, msg.channel):
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
# Finally, treat default hooks if not catched before
|
|
|
|
ask_default = self.create_cache("ask_default")
|
|
|
|
for hook, lvl, store in ask_default:
|
|
|
|
if treated:
|
|
|
|
break
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
return treated
|
|
|
|
|
|
|
|
def treat_answer(self, msg):
|
|
|
|
"""Treat a normal message"""
|
|
|
|
treated = list()
|
|
|
|
|
|
|
|
# First, treat simple hook
|
|
|
|
msg_hook = self.create_cache("msg_hook")
|
|
|
|
if msg.content in msg_hook:
|
|
|
|
hks, lvl, store = msg_hook[msg.content]
|
|
|
|
for h in hks:
|
|
|
|
res = h.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, h)
|
|
|
|
|
|
|
|
# Then, treat regexp based hook
|
|
|
|
msg_rgxp = self.create_cache("msg_rgxp")
|
|
|
|
for hook, lvl, store in msg_rgxp:
|
|
|
|
if hook.is_matching(msg.content, msg.channel):
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
# Finally, treat default hooks if not catched before
|
|
|
|
msg_default = self.create_cache("msg_default")
|
|
|
|
for hook, lvl, store in msg_default:
|
|
|
|
if len(treated) > 0:
|
|
|
|
break
|
|
|
|
res = hook.run(msg)
|
|
|
|
if res is not None and res != False:
|
|
|
|
treated.append(res)
|
|
|
|
self.check_rest_times(store, hook)
|
|
|
|
|
|
|
|
return treated
|
|
|
|
|
2012-11-02 11:10:37 +00:00
|
|
|
def _ctcp_response(sndr, msg):
|
|
|
|
return response.Response(sndr, msg, ctcp=True)
|
2012-08-14 03:51:55 +00:00
|
|
|
|
|
|
|
def hotswap(bak):
|
|
|
|
return Bot(bak.servers, bak.modules, bak.modules_path)
|
|
|
|
|
|
|
|
def reload():
|
|
|
|
import imp
|
|
|
|
|
2012-09-01 13:49:30 +00:00
|
|
|
import channel
|
|
|
|
imp.reload(channel)
|
|
|
|
|
|
|
|
import consumer
|
|
|
|
imp.reload(consumer)
|
|
|
|
|
|
|
|
import DCC
|
|
|
|
imp.reload(DCC)
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-08-14 04:56:28 +00:00
|
|
|
import event
|
|
|
|
imp.reload(event)
|
|
|
|
|
2012-08-14 03:51:55 +00:00
|
|
|
import hooks
|
|
|
|
imp.reload(hooks)
|
|
|
|
|
|
|
|
import importer
|
|
|
|
imp.reload(importer)
|
|
|
|
|
2012-09-01 13:49:30 +00:00
|
|
|
import message
|
|
|
|
imp.reload(message)
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-09-01 13:49:30 +00:00
|
|
|
import prompt.builtins
|
|
|
|
imp.reload(prompt.builtins)
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-09-01 13:49:30 +00:00
|
|
|
import server
|
|
|
|
imp.reload(server)
|
2012-08-14 03:51:55 +00:00
|
|
|
|
2012-09-01 13:49:30 +00:00
|
|
|
import xmlparser
|
|
|
|
imp.reload(xmlparser)
|
|
|
|
import xmlparser.node
|
|
|
|
imp.reload(xmlparser.node)
|