2012-08-14 03:51:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-08-30 17:15:14 +00:00
|
|
|
# Nemubot is a smart and modulable IM bot.
|
2015-01-03 19:17:46 +00:00
|
|
|
# Copyright (C) 2012-2015 Mercier Pierre-Olivier
|
2012-08-14 03:51:55 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2015-05-11 05:41:04 +00:00
|
|
|
import threading
|
|
|
|
|
|
|
|
_lock = threading.Lock()
|
2012-04-09 02:19:39 +00:00
|
|
|
|
2014-08-30 17:15:14 +00:00
|
|
|
# Lists for select
|
|
|
|
_rlist = []
|
|
|
|
_wlist = []
|
|
|
|
_xlist = []
|
2012-04-09 02:19:39 +00:00
|
|
|
|
2014-11-09 13:11:54 +00:00
|
|
|
|
2015-07-15 05:48:41 +00:00
|
|
|
def factory(uri):
|
|
|
|
from urllib.parse import urlparse, unquote
|
|
|
|
o = urlparse(uri)
|
|
|
|
|
|
|
|
if o.scheme == "irc" or o.scheme == "ircs":
|
|
|
|
# http://www.w3.org/Addressing/draft-mirashi-url-irc-01.txt
|
|
|
|
# http://www-archive.mozilla.org/projects/rt-messaging/chatzilla/irc-urls.html
|
|
|
|
args = dict()
|
|
|
|
|
|
|
|
modifiers = o.path.split(",")
|
|
|
|
target = unquote(modifiers.pop(0)[1:])
|
|
|
|
|
|
|
|
if o.scheme == "ircs": args["ssl"] = True
|
|
|
|
if o.hostname is not None: args["host"] = o.hostname
|
|
|
|
if o.port is not None: args["port"] = o.port
|
|
|
|
if o.username is not None: args["username"] = o.username
|
|
|
|
if o.password is not None: args["password"] = o.password
|
|
|
|
|
|
|
|
queries = o.query.split("&")
|
|
|
|
for q in queries:
|
|
|
|
key, val = tuple(q.split("=", 1))
|
|
|
|
if key == "msg":
|
|
|
|
args["on_connect"] = [ "PRIVMSG %s :%s" % (target, unquote(val)) ]
|
|
|
|
elif key == "key":
|
|
|
|
args["channels"] = [ (target, unquote(val)) ]
|
|
|
|
elif key == "pass":
|
|
|
|
args["password"] = unquote(val)
|
|
|
|
elif key == "charset":
|
|
|
|
args["encoding"] = unquote(val)
|
|
|
|
|
|
|
|
if "channels" not in args and "isnick" not in modifiers:
|
|
|
|
args["channels"] = [ target ]
|
|
|
|
|
|
|
|
from nemubot.server.IRC import IRC as IRCServer
|
|
|
|
return IRCServer(**args)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2015-02-21 12:51:40 +00:00
|
|
|
def reload():
|
|
|
|
import imp
|
2014-10-09 05:39:38 +00:00
|
|
|
|
2015-02-21 12:51:40 +00:00
|
|
|
import nemubot.server.abstract
|
|
|
|
imp.reload(nemubot.server.abstract)
|
2014-10-09 05:39:38 +00:00
|
|
|
|
2015-01-03 19:17:46 +00:00
|
|
|
import nemubot.server.socket
|
|
|
|
imp.reload(nemubot.server.socket)
|
2014-10-09 05:39:38 +00:00
|
|
|
|
2015-01-03 19:17:46 +00:00
|
|
|
import nemubot.server.IRC
|
|
|
|
imp.reload(nemubot.server.IRC)
|