Skip to content

Commit

Permalink
Add notice events
Browse files Browse the repository at this point in the history
Add notice events
  • Loading branch information
chillymosh committed May 27, 2023
1 parent be7c763 commit 52f8af5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
5 changes: 4 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Master
- Added :func:`~twitchio.Client.fetch_global_chat_badges`
- Added User method :func:`~twitchio.PartialUser.fetch_chat_badges`
- Added repr for :class:`~twitchio.SearchUser`

- Added two new events
- Added ::func:`~twitchio.Client.event_notice`
- Added ::func:`~twitchio.Client.event_raw_notice`

- Bug fixes
- Fix :func:`~twitchio.Client.search_categories` due to :attr:`~twitchio.Game.igdb_id` being added to :class:`~twitchio.Game`
- Made Chatter :attr:`~twitchio.Chatter.id` property public
Expand Down
51 changes: 51 additions & 0 deletions twitchio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,3 +1055,54 @@ async def event_channel_join_failure(self, channel: str):
The channel name that was attempted to be joined.
"""
logger.error(f'The channel "{channel}" was unable to be joined. Check the channel is valid.')

async def event_raw_notice(self, data: str):
"""|coro|
Event called with the raw NOTICE data received by Twitch.
Parameters
------------
data: str
The raw NOTICE data received from Twitch.
Example
---------
.. code:: py
@bot.event()
async def event_raw_notice(data):
print(data)
"""
pass

async def event_notice(self, msg_id: str, channel: Channel, message: str):
"""|coro|
Event called with the NOTICE data received by Twitch.
.. tip::
For more information on NOTICE msg_ids visit:
https://dev.twitch.tv/docs/irc/msg-id/
Parameters
------------
msg_id: str
The msg_id that indicates what the NOTICE type.
channel: str
The channel the NOTICE message originated from.
message: str
The message of the NOTICE.
Example
---------
.. code:: py
@bot.event()
async def event_notice(msg_id, channel, message):
print(data)
"""
pass
12 changes: 1 addition & 11 deletions twitchio/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@
if typing.TYPE_CHECKING:
from .websocket import WSConnection

ACTIONS = (
"JOIN",
"PART",
"PING",
"PRIVMSG",
"PRIVMSG(ECHO)",
"USERSTATE",
"MODE",
"WHISPER",
"USERNOTICE",
)
ACTIONS = ("JOIN", "PART", "PING", "PRIVMSG", "PRIVMSG(ECHO)", "USERSTATE", "MODE", "WHISPER", "USERNOTICE", "NOTICE")
ACTIONS2 = ("USERSTATE", "ROOMSTATE", "PRIVMSG", "USERNOTICE", "WHISPER")
USER_SUB = re.compile(r":(?P<user>.*)!")
MESSAGE_RE = re.compile(r":(?P<useraddr>\S+) (?P<action>\S+) (?P<channel>\S+)( :(?P<message>.*))?$")
Expand Down
10 changes: 10 additions & 0 deletions twitchio/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(
"PRIVMSG(ECHO)": self._privmsg_echo,
"USERSTATE": self._userstate,
"USERNOTICE": self._usernotice,
"NOTICE": self._notice,
"JOIN": self._join,
"MODE": self._mode,
"RECONNECT": self._reconnect,
Expand Down Expand Up @@ -501,6 +502,15 @@ async def _usernotice(self, parsed):

self.dispatch("raw_usernotice", channel, tags)

async def _notice(self, parsed):
log.debug(f'ACTION: NOTICE:: {parsed["channel"]}')
msg_id = parsed["groups"][0].split("=")[1]
channel = Channel(name=parsed["channel"], websocket=self)
message = parsed["message"]

self.dispatch("raw_notice", parsed["data"])
self.dispatch("notice", msg_id, channel, message)

async def _join(self, parsed):
log.debug(f'ACTION: JOIN:: {parsed["channel"]}')
channel = parsed["channel"]
Expand Down

0 comments on commit 52f8af5

Please sign in to comment.