Skip to content

Commit 385a26d

Browse files
committed
Added chatters from the TMI api.
1 parent 104c0bc commit 385a26d

File tree

14 files changed

+175
-4
lines changed

14 files changed

+175
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
test_suite='tests',
4040
tests_require=test_requirements,
4141
url='https://github.com/PetterKraabol/Twitch-Python',
42-
version='0.0.16',
42+
version='0.0.17',
4343
zip_safe=True,
4444
)

twitch/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
from twitch.chat import Chat
44
from twitch.helix import Helix
5+
from twitch.tmi import TMI
56
from twitch.v5 import V5
67

78
name: str = "twitch"
89

910
__all__: List[Callable] = [
1011
Helix,
1112
V5,
12-
Chat
13+
TMI,
14+
Chat,
1315
]

twitch/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class API:
1313
def __init__(self,
1414
base_url: Optional[str] = None,
1515
client_id: Optional[str] = None,
16+
client_secret: Optional[str] = None,
1617
use_cache: Optional[bool] = False,
1718
request_rate: Optional[int] = None,
1819
bearer_token: Optional[str] = None,
@@ -29,6 +30,7 @@ def __init__(self,
2930
"""
3031
self.base_url: Optional[str] = base_url
3132
self.client_id: Optional[str] = client_id
33+
self.client_secret: Optional[str] = client_secret
3234
self.use_cache: bool = use_cache
3335
self.request_rate: Optional[int] = request_rate
3436
self.bearer_token: Optional[str] = bearer_token

twitch/helix/helix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def __init__(self,
3232
bearer_token = 'Bearer ' + bearer_token.lower().lstrip('bearer').strip()
3333

3434
self.api = API(Helix.BASE_URL,
35-
client_id,
35+
client_id=client_id,
36+
client_secret=client_secret,
3637
use_cache=use_cache,
3738
cache_duration=cache_duration,
3839
handle_rate_limit=handle_rate_limit,

twitch/helix/models/user.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Dict, Any
22

33
import twitch.helix as helix
4+
import twitch.tmi as tmi
45
from twitch.api import API
56
from .model import Model
67

@@ -39,6 +40,14 @@ def is_live(self) -> bool:
3940
except helix.StreamNotFound:
4041
return False
4142

43+
@property
44+
def chatters(self) -> 'tmi.Chatters':
45+
source = tmi.TMI('')
46+
source.api = self._api
47+
source.api.base_url = tmi.TMI.BASE_URL
48+
49+
return source.chatters(self.login)
50+
4251
def following(self, **kwargs) -> 'helix.Follows':
4352
kwargs['from_id'] = self.id
4453
return helix.Follows(api=self._api, follow_type='following', **kwargs)

twitch/helix/resources/users.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def __init__(self, api: API, *args):
2424
]
2525
]
2626

27+
# todo: Authenticated user if bearer token is provided
28+
if not len(params['id'] + params['login']):
29+
pass
30+
2731
# Custom user caching
2832
if self._api.use_cache:
2933
cache_hits: Dict[str, list] = {'id': [], 'login': []}
@@ -53,6 +57,7 @@ def __init__(self, api: API, *args):
5357
API.SHARED_CACHE.set(f'helix.users.login.{user.login}', data)
5458
API.SHARED_CACHE.set(f'helix.users.id.{user.id}', data)
5559

60+
5661
def _can_paginate(self) -> bool:
5762
return False
5863

twitch/tmi/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List, Callable
2+
3+
from twitch.tmi.models.chatter import Chatter
4+
from twitch.tmi.resources.chatters import Chatters
5+
from twitch.tmi.tmi import TMI
6+
7+
__all__: List[Callable] = [
8+
TMI,
9+
Chatter, Chatters
10+
]

twitch/tmi/models/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import List, Callable
2+
3+
from .chatter import Chatter
4+
from .model import Model
5+
6+
__all__: List[Callable] = [
7+
Chatter,
8+
Model,
9+
]

twitch/tmi/models/chatter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Dict, Any, List
2+
3+
import twitch.helix as helix
4+
from twitch.api import API
5+
from .model import Model
6+
7+
8+
class Chatter(Model):
9+
10+
def __init__(self, api: API, name: str, chatter_type: str):
11+
super().__init__(api, {})
12+
self.name: str = name
13+
self.type: str = chatter_type
14+
15+
@property
16+
def user(self) -> 'helix.User':
17+
source = helix.Helix('')
18+
source.api = self._api
19+
source.api.base_url = helix.Helix.BASE_URL
20+
return source.user(self.name)

twitch/tmi/models/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from abc import ABCMeta
2+
from dataclasses import dataclass
3+
from typing import Optional, Dict, Any
4+
5+
from twitch.api import API
6+
7+
8+
@dataclass
9+
class Model(metaclass=ABCMeta):
10+
_api: Optional[API]
11+
data: Optional[Dict[str, Any]]

0 commit comments

Comments
 (0)