Skip to content

Commit 2818672

Browse files
authored
Add user_id property to client (#256)
1 parent d354f0f commit 2818672

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ A simple Chat Bot.
7272
async def event_ready(self):
7373
# We are logged in and ready to chat and use commands...
7474
print(f'Logged in as | {self.nick}')
75+
print(f'User id is | {self.user_id}')
7576
7677
@commands.command()
7778
async def hello(self, ctx: commands.Context):

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
.. currentmodule:: twitchio
22

3+
Master
4+
=====
5+
- TwitchIO
6+
- Add `user_id` property to Client
7+
38
2.1.4
49
======
510
- TwitchIO

docs/quickstart.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Here we will be using the commands extension of TwitchIO to create a Chat Bot.
4141
# Notify us when everything is ready!
4242
# We are logged in and ready to chat and use commands...
4343
print(f'Logged in as | {self.nick}')
44+
print(f'User id is | {self.user_id}')
4445
4546
@commands.command()
4647
async def hello(self, ctx: commands.Context):
@@ -82,6 +83,7 @@ For an exhaustive list of events, visit: `Event Reference <twitchio.html#event-r
8283
# Notify us when everything is ready!
8384
# We are logged in and ready to chat and use commands...
8485
print(f'Logged in as | {self.nick}')
86+
print(f'User id is | {self.user_id}')
8587
8688
async def event_message(self, message):
8789
# Messages with echo set to True are messages sent by the bot...

twitchio/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ def nick(self):
336336
"""The IRC bots nick."""
337337
return self._http.nick or self._connection.nick
338338

339+
@property
340+
def user_id(self):
341+
"""The IRC bot user id."""
342+
return self._http.user_id or self._connection.user_id
343+
339344
def create_user(self, user_id: int, user_name: str) -> PartialUser:
340345
"""
341346
A helper method to create a :class:`twitchio.PartialUser` from a user id and user name.

twitchio/http.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __init__(
9898
self.client_secret = client_secret
9999
self.client_id = client_id
100100
self.nick = None
101+
self.user_id = None
101102

102103
self.bucket = RateBucket(method="http")
103104
self.scopes = kwargs.get("scopes", [])
@@ -325,6 +326,7 @@ async def validate(self, *, token: str = None) -> dict:
325326

326327
if not self.nick:
327328
self.nick = data.get("login")
329+
self.user_id = int(data.get("user_id"))
328330
self.client_id = data.get("client_id")
329331

330332
return data

twitchio/websocket.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(
9090
}
9191

9292
self.nick = None
93+
self.user_id = None
9394
self._token = token
9495
self.modes = modes or ("commands", "tags", "membership")
9596
self._initial_channels = initial_channels or []
@@ -126,6 +127,7 @@ async def _connect(self):
126127
if not self._client._http.nick:
127128
data = await self._client._http.validate(token=self._token)
128129
self.nick = data["login"]
130+
self.user_id = int(data["user_id"])
129131

130132
session = self._client._http.session
131133

0 commit comments

Comments
 (0)