Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: handle 005 RPL_ISUPPORT event #1758

Merged
merged 4 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/source/irc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Backends
:show-inheritance:


ISUPPORT
========

.. automodule:: sopel.irc.isupport
:members:


Utility
=======

Expand Down
21 changes: 21 additions & 0 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
from random import randint

from sopel import loader, module
from sopel.irc import isupport
dgw marked this conversation as resolved.
Show resolved Hide resolved
from sopel.irc.utils import CapReq
from sopel.tools import Identifier, events, iteritems, jobs, target, web


if sys.version_info.major >= 3:
unicode = str

Expand Down Expand Up @@ -195,6 +197,25 @@ def startup(bot, trigger):
_execute_perform(bot)


@module.priority('high')
@module.event(events.RPL_ISUPPORT)
@module.thread(False)
@module.unblockable
@module.rule('are supported by this server')
def handle_isupport(bot, trigger):
"""Handle ``RPL_ISUPPORT`` events."""
parameters = {}
for arg in trigger.args:
try:
key, value = isupport.parse_parameter(arg)
parameters[key] = value
except ValueError:
# ignore malformed parameter: log a warning and continue
LOGGER.warning('Unable to parse ISUPPORT parameter: %r', arg)

bot._isupport = bot._isupport.apply(**parameters)


@module.require_privmsg()
@module.require_owner()
@module.commands('useserviceauth')
Expand Down
10 changes: 10 additions & 0 deletions sopel/irc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from sopel.trigger import PreTrigger

from .backends import AsynchatBackend, SSLAsynchatBackend
from .isupport import ISupport
from .utils import safe, CapReq

if sys.version_info.major >= 3:
Expand All @@ -67,6 +68,7 @@ def __init__(self, settings):
self._nick = tools.Identifier(settings.core.nick)
self._user = settings.core.user
self._name = settings.core.name
self._isupport = ISupport()

self.backend = None
"""IRC Connection Backend."""
Expand Down Expand Up @@ -108,6 +110,14 @@ def config(self):
# TODO: Deprecate config, replaced by settings
return self.settings

@property
def isupport(self):
"""Features advertised by the server.

:type: :class:`~.isupport.ISupport` instance
"""
return self._isupport

# Connection

def get_irc_backend(self):
Expand Down
Loading