769 changes: 769 additions & 0 deletions opsdroid/connector/twitch/__init__.py

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions opsdroid/connector/twitch/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Events for Twitch Connector."""
import logging

from opsdroid import events

_LOGGER = logging.getLogger(__name__)


class UserFollowed(events.Event):
"""Event class to trigger when a user follows the streamer."""

def __init__(self, follower, followed_at, *args, **kwargs):
"""Follower username of the follower, followed_at is the timestamp of the following."""
super().__init__(*args, **kwargs)
self.follower = follower
self.followed_at = followed_at


class StreamStarted(events.Event):
"""Event class that triggers when streamer started broadcasting."""

def __init__(self, title, viewers, started_at, *args, **kwargs):
"""Event that is triggered when a streamer starts broadcasting.
This event is triggered after 2 minutes of starting the broascast and
contains a few attributes that you can access.
``title`` your broadcast title
``viewers`` total number of viewers that your channel has
``started_at`` timestamp when you went live
"""
super().__init__(*args, **kwargs)
self.title = title
self.viewers = viewers
self.started_at = started_at


class StreamEnded(events.Event):
"""Event class that triggers when streamer stoppped broadcasting."""


class CreateClip(events.Event):
"""Event class that creates a clip once triggered."""

def __init__(self, id, *args, **kwargs):
"""Id is your streamer id."""
super().__init__(*args, **kwargs)
self.id = id


class UpdateTitle(events.Event):
"""Event class that updates channel title."""

def __init__(self, status, *args, **kwargs):
"""Status is the new title for your channel."""
super().__init__(*args, **kwargs)
self.status = status


class UserSubscribed(events.Event):
"""Event class that triggers whenever a user subscribes to the channel."""

def __init__(self, user, message, *args, **kwargs):
"""User is the username of the subscriber, message is the sub message, can be None."""
super().__init__(*args, **kwargs)
self.user = user
self.message = message


class UserGiftedSubscription(events.Event):
"""Event class that triggers when a user gifts a subscription to someone."""

def __init__(self, gifter_name, gifted_named, *args, **kwargs):
"""Gifter_name is the sub that gifted a sub, gifted name is the gifted viewer."""
super().__init__(*args, **kwargs)
self.gifter_name = gifter_name
self.gifted_name = gifted_named
881 changes: 881 additions & 0 deletions opsdroid/connector/twitch/tests/test_connector_twitch.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions opsdroid/connector/twitch/tests/twitch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"access_token": "token123", "refresh_token": "refresh_token123"}
6 changes: 6 additions & 0 deletions opsdroid/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@
WATSON_API_ENDPOINT = "https://{gateway}.watsonplatform.net/assistant/api"
WATSON_API_VERSION = "2019-02-28"
ENV_VAR_REGEX = r"^\"?\${?(?=\_?[A-Z])([A-Z-_]+)}?\"?$"

TWITCH_OAUTH_ENDPOINT = "https://id.twitch.tv/oauth2/token"
TWITCH_WEBHOOK_ENDPOINT = "https://api.twitch.tv/helix/webhooks/hub"
TWITCH_API_ENDPOINT = "https://api.twitch.tv/helix"
TWITCH_IRC_MESSAGE_REGEX = r"@.*;id=(?P<message_id>.*);m.*user-id=(?P<user_id>.*);user-type=.*:(?P<user>.*?)!.*PRIVMSG.*:(?P<message>.*)"
TWITCH_JSON = os.path.join(DEFAULT_ROOT_PATH, "twitch.json")
12 changes: 12 additions & 0 deletions opsdroid/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ class JoinRoom(Event):
"""Event class to represent a user joining a room."""


class LeaveRoom(Event):
"""Event class to represent a user leaving a room."""


class UserInvite(Event):
"""Event class to represent a user being invited to a room."""

Expand All @@ -478,3 +482,11 @@ class PinMessage(Event):

class UnpinMessage(Event):
"""Event to represent unpinning a message or other event."""


class DeleteMessage(Event):
"""Event to represent deleting a message or other event."""


class BanUser(Event):
"""Event to represent the banning of a user from a room."""
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dialogflow==1.0.0
astroid==2.4.1
pytest==6.0.1
pytest-asyncio==0.12.0
pytest-aiohttp==0.3.0
pytest-cov==2.7.1
pytest-timeout==1.4.0
pytest-mock==3.2.0
Expand Down