modeChanged() works properly, small changes to module loading
This commit is contained in:
parent
4a7e76a897
commit
b8bbcd4971
91
bot.py
91
bot.py
|
@ -120,34 +120,33 @@ class Fulvia(irc.IRCClient):
|
||||||
print(f"{failed} modules failed to load")
|
print(f"{failed} modules failed to load")
|
||||||
|
|
||||||
|
|
||||||
def register_callable(self, callables):
|
def register_callable(self, func):
|
||||||
"""
|
"""
|
||||||
Registers all callable functions loaded from modules into one
|
Registers all callable functions loaded from modules into one
|
||||||
convenient table.
|
convenient table.
|
||||||
"""
|
"""
|
||||||
for func in callables:
|
if hasattr(func, 'commands'):
|
||||||
if hasattr(func, 'commands'):
|
self._callables[func.__name__] = func
|
||||||
self._callables[func.__name__] = func
|
for cmd in func.commands:
|
||||||
for cmd in func.commands:
|
self.commands[cmd] = tools.Command(cmd)
|
||||||
self.commands[cmd] = tools.Command(cmd)
|
self.commands[cmd]._func_name = func.__name__
|
||||||
self.commands[cmd]._func_name = func.__name__
|
self.commands[cmd].priv = func.priv
|
||||||
self.commands[cmd].priv = func.priv
|
self.commands[cmd].doc = func._docs
|
||||||
self.commands[cmd].doc = func._docs
|
if cmd in func.aliases:
|
||||||
if cmd in func.aliases:
|
self.commands[cmd].canonical = False
|
||||||
self.commands[cmd].canonical = False
|
aliases = [a for a in func.commands if a != cmd]
|
||||||
aliases = [a for a in func.commands if a != cmd]
|
self.commands[cmd].aliases = aliases
|
||||||
self.commands[cmd].aliases = aliases
|
|
||||||
|
|
||||||
if func.hook:
|
if func.hook:
|
||||||
self._callables[func.__name__] = func
|
self._callables[func.__name__] = func
|
||||||
self._hooks.append(func.__name__)
|
self._hooks.append(func.__name__)
|
||||||
|
|
||||||
if func.rate or func.channel_rate or func.global_rate:
|
if func.rate or func.channel_rate or func.global_rate:
|
||||||
self._times[func.__name__] = {}
|
self._times[func.__name__] = {}
|
||||||
|
|
||||||
if hasattr(func, 'url_callback'):
|
if hasattr(func, 'url_callback'):
|
||||||
for url in func.url_callback:
|
for url in func.url_callback:
|
||||||
self.url_callbacks[url] = func
|
self.url_callbacks[url] = func
|
||||||
|
|
||||||
|
|
||||||
def unregister_callable(self, func):
|
def unregister_callable(self, func):
|
||||||
|
@ -239,7 +238,7 @@ class Fulvia(irc.IRCClient):
|
||||||
self._times[func_name]["global"] = time.time()
|
self._times[func_name]["global"] = time.time()
|
||||||
|
|
||||||
if func.thread == True:
|
if func.thread == True:
|
||||||
t = threading.Thread(target=self.call, args=(func, bot, trigger))
|
t = threading.Thread(target=self.call,args=(func, bot, trigger))
|
||||||
t.start()
|
t.start()
|
||||||
else:
|
else:
|
||||||
self.call(func, bot, trigger)
|
self.call(func, bot, trigger)
|
||||||
|
@ -260,17 +259,26 @@ class Fulvia(irc.IRCClient):
|
||||||
|
|
||||||
def modeChanged(self, user, channel, add_mode, modes, args):
|
def modeChanged(self, user, channel, add_mode, modes, args):
|
||||||
"""Called when users or channel's modes are changed."""
|
"""Called when users or channel's modes are changed."""
|
||||||
# TODO: do this function the right way
|
if not channel.startswith("#"): # server level
|
||||||
# TODO: channel modes
|
return
|
||||||
# modes[0] is lazy, but ought to work in most cases
|
|
||||||
if modes[0] in tools.op_level.keys():
|
for n, mode in enumerate(modes):
|
||||||
for n, name in enumerate(args):
|
if args[n] == None: # channel mode
|
||||||
if add_mode:
|
if add_mode:
|
||||||
mode = tools.op_level[modes[n]]
|
self.channels[channel].modes.add(mode)
|
||||||
self.channels[channel].privileges[name] = mode
|
|
||||||
else:
|
else:
|
||||||
# this is extremely lazy and won't work in a lot of cases
|
self.channels[channel].modes.remove(mode)
|
||||||
self.channels[channel].privileges[name] = 0
|
|
||||||
|
elif mode in tools.op_level.keys(): # user mode, op_level mode
|
||||||
|
nick = args[n]
|
||||||
|
op_level = tools.op_level[mode]
|
||||||
|
if add_mode:
|
||||||
|
self.channels[channel].privileges[nick] += op_level
|
||||||
|
else:
|
||||||
|
self.channels[channel].privileges[nick] -= op_level
|
||||||
|
|
||||||
|
else: # user mode, non-op_level mode
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
def signedOn(self):
|
def signedOn(self):
|
||||||
|
@ -348,19 +356,10 @@ class Fulvia(irc.IRCClient):
|
||||||
|
|
||||||
## User commands, from client->server
|
## User commands, from client->server
|
||||||
|
|
||||||
def msg(self, user, message, length=None):
|
|
||||||
"""
|
|
||||||
Send a message to a user or channel. See irc.IRCClient.msg for more
|
|
||||||
information.
|
|
||||||
Provided solely for documentation and clarity's sake.
|
|
||||||
"""
|
|
||||||
irc.IRCClient.msg(self, user, message, length=None)
|
|
||||||
|
|
||||||
|
|
||||||
def reply(self, text, dest, reply_to, notice=False):
|
def reply(self, text, dest, reply_to, notice=False):
|
||||||
"""
|
"""
|
||||||
For compatibility with most of the sopel modules. Will phase it out
|
Sends a message to 'dest' prefixed with 'reply_to' and a colon,
|
||||||
in favor of self.msg eventually.
|
ala "reply_to: text". More useful with the wrapper class.
|
||||||
"""
|
"""
|
||||||
text = reply_to + ": " + text
|
text = reply_to + ": " + text
|
||||||
self.msg(dest, text)
|
self.msg(dest, text)
|
||||||
|
@ -392,11 +391,11 @@ class Fulvia(irc.IRCClient):
|
||||||
|
|
||||||
|
|
||||||
class FulviaWrapper():
|
class FulviaWrapper():
|
||||||
|
"""
|
||||||
|
A wrapper class for Fulvia to provide default destinations for msg
|
||||||
|
methods and so forth.
|
||||||
|
"""
|
||||||
def __init__(self, fulvia, trigger):
|
def __init__(self, fulvia, trigger):
|
||||||
"""
|
|
||||||
A wrapper class for Fulvia to provide default destinations for
|
|
||||||
msg methods and so forth.
|
|
||||||
"""
|
|
||||||
object.__setattr__(self, '_bot', fulvia)
|
object.__setattr__(self, '_bot', fulvia)
|
||||||
object.__setattr__(self, '_trigger', trigger)
|
object.__setattr__(self, '_trigger', trigger)
|
||||||
# directly setting these values would cause a recursion loop
|
# directly setting these values would cause a recursion loop
|
||||||
|
|
|
@ -15,7 +15,8 @@ def load_module(bot, path):
|
||||||
if hasattr(module, 'setup'):
|
if hasattr(module, 'setup'):
|
||||||
module.setup(bot)
|
module.setup(bot)
|
||||||
relevant_parts = process_module(module, bot.config)
|
relevant_parts = process_module(module, bot.config)
|
||||||
bot.register_callable(relevant_parts)
|
for part in relevant_parts:
|
||||||
|
bot.register_callable(part)
|
||||||
|
|
||||||
|
|
||||||
def unload_module(bot, name):
|
def unload_module(bot, name):
|
||||||
|
|
|
@ -42,7 +42,9 @@ def title_auto(bot, trigger):
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
if not res.headers["Content-Type"].startswith("text/html"):
|
if not res.headers.get("Content-Type"):
|
||||||
|
continue
|
||||||
|
if not res.headers.get("Content-Type").startswith("text/html"):
|
||||||
continue
|
continue
|
||||||
if res.text.find("<title>") == -1:
|
if res.text.find("<title>") == -1:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -100,9 +100,8 @@ class Channel(object):
|
||||||
self.privileges = {}
|
self.privileges = {}
|
||||||
"""The op levels of the users in the channel."""
|
"""The op levels of the users in the channel."""
|
||||||
|
|
||||||
self.modes = ""
|
self.modes = set()
|
||||||
"""The mode of the channel."""
|
"""The current modes on the channel."""
|
||||||
# NOTE: this doesn't work yet
|
|
||||||
|
|
||||||
def remove_user(self, nick):
|
def remove_user(self, nick):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user