Skip to content

Commit a592c1f

Browse files
committed
Merge branch 'main' into feature/conduits
2 parents 2873be3 + 7db6c91 commit a592c1f

File tree

7 files changed

+237
-2
lines changed

7 files changed

+237
-2
lines changed

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: 🐛 Bug Report
3+
description: Submit a bug report for TwitchIO
4+
title: "[Bug]: "
5+
labels: ["Unconfirmed Bug", "Needs Verification"]
6+
body:
7+
- type: textarea
8+
id: what-happened
9+
attributes:
10+
label: "What actually happened?"
11+
description: "Please enter details about the issue, including tracebacks if applicable (in codeblocks)."
12+
placeholder: "My Bot will not start!"
13+
validations:
14+
required: true
15+
- type: textarea
16+
id: expected-outcome
17+
attributes:
18+
label: "What did you expect to happen instead?"
19+
description: "Please enter what you hoped or expected to happen instead of the issue that occurred."
20+
placeholder: "My Bot started successfully!"
21+
validations:
22+
required: true
23+
- type: textarea
24+
id: mre
25+
attributes:
26+
label: "Minimum reproducible example:"
27+
description: "Please provide the minimum necessary code to reproduce your issue, if relevant."
28+
render: python
29+
- type: textarea
30+
id: repro-steps
31+
attributes:
32+
label: "Steps to reproduce the problem"
33+
description: "It may not be obvious how to *cause* the issue, so please explain below."
34+
validations:
35+
required: true
36+
- type: textarea
37+
id: logs
38+
attributes:
39+
label: "Additional logs:"
40+
description: "If there is any logging output that may be relevant, please add it here."
41+
- type: textarea
42+
id: environment-details
43+
attributes:
44+
label: "System and Environment information"
45+
description: "Please put the output of `python -m twitchio --version` here:"
46+
validations:
47+
required: true

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: TwitchIO Documentation
4+
url: https://twitchio.dev/en/latest/index.html
5+
about: Official TwitchIO documentation - please check here before opening an issue.
6+
- name: Discord
7+
url: https://discord.gg/RAKc3HF
8+
about: Join our Discord community to chat or receive help, or get in touch with the maintainers.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Feature Request"
2+
description: Create an issue for a new feature request
3+
title: "Enhancement: <title>"
4+
labels:
5+
- "Enhancement"
6+
body:
7+
- type: textarea
8+
id: summary
9+
attributes:
10+
label: "Summary"
11+
description: Provide a brief summary of your feature request
12+
placeholder: Describe in a few lines your feature request
13+
validations:
14+
required: true
15+
- type: textarea
16+
id: basic_example
17+
attributes:
18+
label: "Basic Examples"
19+
description: Indicate here some basic examples of your feature.
20+
placeholder: Provide some basic example of your feature request
21+
validations:
22+
required: false
23+
- type: textarea
24+
id: drawbacks
25+
attributes:
26+
label: "Drawbacks and Impact"
27+
description: What are the drawbacks or impacts of your feature request?
28+
placeholder: Describe any of the drawbacks or impacts of your feature request
29+
validations:
30+
required: false
31+
- type: textarea
32+
id: unresolved_question
33+
attributes:
34+
label: "Unresolved questions"
35+
description: What, if any, unresolved questions do you have about your feature request?
36+
placeholder: Identify any unresolved issues.
37+
validations:
38+
required: false

docs/getting-started/faq.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,28 @@ You can also create a :class:`~twitchio.PartialUser` with :meth:`~twitchio.Clien
8383
If you are using :class:`~twitchio.ext.commands.Command`'s or anywhere :class:`~twitchio.ext.commands.Context` is available,
8484
or are receiving a :class:`~twitchio.ChatMessage`, consider looking at :class:`~twitchio.Chatter` for a more complete object
8585
with more information and helpers.
86+
87+
.. _bot-id-owner-id:
88+
89+
How do I get the user IDs for BOT_ID and OWNER_ID?
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
If you do not know your user ID you can quickly fetch it using the :meth:`~twitchio.Client.fetch_users` method.
93+
94+
.. code:: python3
95+
96+
import asyncio
97+
import twitchio
98+
99+
CLIENT_ID: str = "..."
100+
CLIENT_SECRET: str = "..."
101+
102+
async def main() -> None:
103+
async with twitchio.Client(client_id=CLIENT_ID, client_secret=CLIENT_SECRET) as client:
104+
await client.login()
105+
user = await client.fetch_users(logins=["chillymosh", "my_bot"])
106+
for u in user:
107+
print(f"User: {u.name} - ID: {u.id}")
108+
109+
if __name__ == "__main__":
110+
asyncio.run(main())

docs/getting-started/quickstart.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Before running the code below, there just a couple more steps we need to take.
3737
#. Stop the bot and uncomment everything in ``setup_hook``.
3838
#. Start the bot.
3939

40+
.. note::
41+
If you are unsure how to get the user IDs for BOT_ID and OWNER_ID, please check :ref:`bot-id-owner-id`
42+
4043
**You only have to do this sequence of steps once. Or if the scopes need to change.**
4144

4245
.. code:: python3

twitchio/client.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,33 @@ def __init__(
172172

173173
self.__waiter: asyncio.Event = asyncio.Event()
174174

175+
@property
176+
def adapter(self) -> BaseAdapter:
177+
"""Property returning the :class:`~twitchio.AiohttpAdapter` or :class:`~twitchio.StarlettepAdapter` the bot is
178+
currently running."""
179+
return self._adapter
180+
181+
async def set_adapter(self, adapter: BaseAdapter) -> None:
182+
"""|async|
183+
184+
Method which sets and starts a new web adapter which inherits from either :class:`~twitchio.AiohttpAdapter` or
185+
:class:`~twitchio.StarlettepAdapter` or implements the :class:`~twitchio.BaseAdapter` specifications.
186+
187+
Parameters
188+
----------
189+
adapter: :class:`~twitchio.BaseAdapter`
190+
The new adapter to assign and start.
191+
192+
Returns
193+
-------
194+
None
195+
"""
196+
if self._adapter:
197+
await self._adapter.close()
198+
199+
self._adapter = adapter
200+
await self._adapter.run()
201+
175202
@property
176203
def tokens(self) -> MappingProxyType[str, TokenMappingData]:
177204
"""Property which returns a read-only mapping of the tokens that are managed by the `Client`.
@@ -1643,6 +1670,56 @@ async def fetch_users(
16431670
data = await self._http.get_users(ids=ids, logins=logins, token_for=token_for)
16441671
return [User(d, http=self._http) for d in data["data"]]
16451672

1673+
async def fetch_user(
1674+
self,
1675+
*,
1676+
id: str | int | None = None,
1677+
login: str | None = None,
1678+
token_for: str | PartialUser | None = None,
1679+
) -> User | None:
1680+
"""|coro|
1681+
1682+
Fetch information about one user.
1683+
1684+
.. note::
1685+
1686+
You may look up a specific user using their user ID or login name.
1687+
1688+
If you don't specify an ID or login name but provide the `token_for` parameter,
1689+
the request returns information about the user associated with the access token.
1690+
1691+
To include the user's verified email address in the response,
1692+
you must have a user access token that includes the `user:read:email` scope.
1693+
1694+
Parameters
1695+
----------
1696+
id: str | int | None
1697+
The id of the user to fetch information about.
1698+
login: str | None
1699+
The login name of the user to fetch information about.
1700+
token_for: str | PartialUser | None
1701+
|token_for|
1702+
1703+
If this parameter is provided, the token must have the `user:read:email` scope
1704+
in order to request the user's verified email address.
1705+
1706+
Returns
1707+
-------
1708+
:class:`twitchio.User`
1709+
A :class:`twitchio.User` object.
1710+
1711+
Raises
1712+
------
1713+
ValueError
1714+
Please provide only one of `id` or `login`.
1715+
"""
1716+
1717+
if id is not None and login is not None:
1718+
raise ValueError("Please provide only one of `id` or `login`.")
1719+
1720+
data = await self._http.get_users(ids=id, logins=login, token_for=token_for)
1721+
return User(data["data"][0], http=self._http) if data["data"] else None
1722+
16461723
def search_categories(
16471724
self,
16481725
query: str,
@@ -2459,6 +2536,43 @@ async def fetch_eventsub_subscriptions(
24592536
status=status,
24602537
)
24612538

2539+
async def fetch_eventsub_subscription(
2540+
self,
2541+
subscription_id: str,
2542+
*,
2543+
token_for: str | PartialUser | None = None,
2544+
) -> EventsubSubscription | None:
2545+
"""|coro|
2546+
2547+
Fetches a specific Eventsub Subscription for either webhook or websocket.
2548+
2549+
.. note::
2550+
This endpoint returns disabled WebSocket subscriptions for a minimum of 1 minute as compared to webhooks which returns disabled subscriptions for a minimum of 10 days.
2551+
2552+
Parameters
2553+
-----------
2554+
subscription_id: str
2555+
The specific subscription ID to fetch.
2556+
token_for: str | PartialUser | None
2557+
By default, if this is ignored or set to None then the App Token is used. This is the case when you want to fetch webhook events.
2558+
2559+
Provide a user ID here for when you want to fetch websocket events tied to a user.
2560+
2561+
Returns
2562+
--------
2563+
EventsubSubscription | None
2564+
"""
2565+
2566+
data = await self._http.get_eventsub_subscription(
2567+
type=None,
2568+
max_results=None,
2569+
token_for=token_for,
2570+
subscription_id=subscription_id,
2571+
user_id=None,
2572+
status=None,
2573+
)
2574+
return await anext(data.subscriptions, None)
2575+
24622576
async def delete_eventsub_subscription(self, id: str, *, token_for: str | PartialUser | None = None) -> None:
24632577
"""|coro|
24642578

twitchio/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class PartialUser:
8888
id: str | int
8989
The user's ID.
9090
name: str | None
91-
The user's name. In most cases, this is provided. There are however, rare cases where it is not.
91+
The user's name. Also known as *username* or *login name*. In most cases, this is provided. There are however, rare cases where it is not.
9292
display_name: str | None
9393
The user's display name in chat. In most cases, this is provided otherwise fallsback to `name`. There are however, rare cases where it is not.
9494
"""
@@ -3459,7 +3459,7 @@ class User(PartialUser):
34593459
id: str
34603460
The user's ID.
34613461
name: str | None
3462-
The user's name. In most cases, this is provided. There are however, rare cases where it is not.
3462+
The user's name. Also known as *username* or *login name*. In most cases, this is provided. There are however, rare cases where it is not.
34633463
display_name: str
34643464
The display name of the user.
34653465
type: Literal["admin", "global_mod", "staff", ""]

0 commit comments

Comments
 (0)