Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 9f2eb27

Browse files
authored
Merge pull request #23 from DirectiveAthena/api-additions
Api additions (partiall)
2 parents a0c4333 + 9e4a20b commit 9f2eb27

File tree

2 files changed

+226
-41
lines changed

2 files changed

+226
-41
lines changed

src/AthenaTwitchBot/data/twitch_api_urls.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,38 @@
1313
# - Code -
1414
# ----------------------------------------------------------------------------------------------------------------------
1515
class TwitchApiURL(enum.Enum):
16-
users = "https://api.twitch.tv/helix/users"
17-
scopes = "https://id.twitch.tv/oauth2/validate"
18-
19-
commercial = "https://api.twitch.tv/helix/channels/commercial"
2016
analytics_extension = "https://api.twitch.tv/helix/analytics/extensions"
2117
analytics_game = "https://api.twitch.tv/helix/analytics/games"
18+
badges_chat = "https://api.twitch.tv/helix/chat/badges"
19+
badges_global = "https://api.twitch.tv/helix/chat/badges/global"
2220
bits_leaderboard = "https://api.twitch.tv/helix/bits/leaderboard"
23-
cheermotes = "https://api.twitch.tv/helix/bits/cheermotes"
24-
extension_transactions = "https://api.twitch.tv/helix/extensions/transactions"
25-
channel_information = "https://api.twitch.tv/helix/channels"
2621
channel_editors = "https://api.twitch.tv/helix/channels/editors"
27-
custom_rewards = "https://api.twitch.tv/helix/channel_points/custom_rewards"
22+
channel_information = "https://api.twitch.tv/helix/channels"
23+
chat_settings = "https://api.twitch.tv/helix/chat/settings"
24+
cheermotes = "https://api.twitch.tv/helix/bits/cheermotes"
25+
clips= "https://api.twitch.tv/helix/clips"
26+
commercial = "https://api.twitch.tv/helix/channels/commercial"
2827
custom_reward_redemptions = "https://api.twitch.tv/helix/channel_points/custom_rewards/redemptions"
28+
custom_rewards = "https://api.twitch.tv/helix/channel_points/custom_rewards"
2929
emotes_chat = "https://api.twitch.tv/helix/chat/emotes"
3030
emotes_global = "https://api.twitch.tv/helix/chat/emotes/global"
3131
emotes_set = "https://api.twitch.tv/helix/chat/emotes/set"
32-
badges_chat = "https://api.twitch.tv/helix/chat/badges"
33-
badges_global = "https://api.twitch.tv/helix/chat/badges/global"
34-
chat_settings = "https://api.twitch.tv/helix/chat/settings"
35-
clips= "https://api.twitch.tv/helix/clips"
32+
enforcements_status = "https://api.twitch.tv/helix/moderation/enforcements/status"
3633
entitlements_code = "https://api.twitch.tv/helix/entitlements/codes"
3734
entitlements_drops = "https://api.twitch.tv/helix/entitlements/drops"
35+
eventsub_subscriptions ="https://api.twitch.tv/helix/eventsub/subscriptions"
36+
extension = "https://api.twitch.tv/helix/extensions"
37+
extension_chat = "https://api.twitch.tv/helix/extensions/chat"
3838
extension_configurations = "https://api.twitch.tv/helix/extensions/configurations"
39-
games_top = "https://api.twitch.tv/helix/games/top"
39+
extension_jwt_secrets = "https://api.twitch.tv/helix/extensions/jwt/secrets"
40+
extension_live = "https://api.twitch.tv/helix/extensions/live"
41+
extension_pubsub = "https://api.twitch.tv/helix/extensions/pubsub"
42+
extension_released = "https://api.twitch.tv/helix/extensions/released"
43+
extension_transactions = "https://api.twitch.tv/helix/extensions/transactions"
4044
games = "https://api.twitch.tv/helix/games"
45+
games_top = "https://api.twitch.tv/helix/games/top"
4146
goals = "https://api.twitch.tv/helix/goals"
4247
hypetrain = "https://api.twitch.tv/helix/hypetrain/events"
43-
enforcements_status = "https://api.twitch.tv/helix/moderation/enforcements/status"
48+
scopes = "https://id.twitch.tv/oauth2/validate"
49+
users = "https://api.twitch.tv/helix/users"
50+
videos = "https://api.twitch.tv/helix/videos"

src/AthenaTwitchBot/models/twitch_api/twitch_api.py

Lines changed: 205 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -579,68 +579,239 @@ async def set_extension_configuration_segment(
579579

580580
# ------------------------------------------------------------------------------------------------------------------
581581
@connected_to_twitch
582-
async def set_extension_required_configuration(self):
583-
return NotImplemented
582+
async def set_extension_required_configuration(
583+
self, extension_id:str,required_configuration:str,extension_version:str
584+
):
585+
return await self._request(
586+
callback=requests.put,
587+
url=TwitchApiURL.extension_configurations.value,
588+
headers=self._header_json,
589+
query_parameters={"broadcaster_id": self.user.id},
590+
data={
591+
"broadcaster_id":self.user.id,
592+
"required_configuration":required_configuration,
593+
"extension_version":extension_version,
594+
"extension_id":extension_id
595+
}
596+
)
584597

585598
# ------------------------------------------------------------------------------------------------------------------
586599
@connected_to_twitch
587-
async def send_extension_pubsub_message(self):
588-
return NotImplemented
600+
async def send_extension_pubsub_message(
601+
self, target:list,is_global_broadcast:bool,message:str
602+
):
603+
return await self._request(
604+
callback=requests.post,
605+
url=TwitchApiURL.extension_pubsub.value,
606+
headers=self._header_json,
607+
data={
608+
"broadcaster_id":self.user.id,
609+
"is_global_broadcast":is_global_broadcast,
610+
"message":message,
611+
"target":target
612+
}
613+
)
589614

590615
# ------------------------------------------------------------------------------------------------------------------
591616
@connected_to_twitch
592-
async def get_extension_live_channels(self):
593-
return NotImplemented
617+
async def get_extension_live_channels(
618+
self, extension_id:str,*,first:int=None,after:str
619+
):
620+
return await self._request(
621+
callback=requests.post,
622+
url=TwitchApiURL.extension_live.value,
623+
headers=self._header,
624+
query_parameters={
625+
k:v
626+
for k, v in {
627+
"extension_id": extension_id,
628+
"first":first,
629+
"after":after
630+
}.items()
631+
if v is not None
632+
},
633+
)
594634

595635
# ------------------------------------------------------------------------------------------------------------------
596636
@connected_to_twitch
597637
async def get_extension_secrets(self):
598-
return NotImplemented
638+
return await self._request(
639+
callback=requests.get,
640+
url=TwitchApiURL.extension_configurations.value,
641+
headers=self._header,
642+
)
599643

600644
# ------------------------------------------------------------------------------------------------------------------
601645
@connected_to_twitch
602-
async def create_extension_secret(self):
603-
return NotImplemented
646+
async def create_extension_secret(
647+
self, extension_id:str,*,delay:int=None
648+
):
649+
return await self._request(
650+
callback=requests.post,
651+
url=TwitchApiURL.extension_jwt_secrets.value,
652+
headers=self._header,
653+
query_parameters={
654+
k:v
655+
for k, v in {
656+
"extension_id": extension_id,
657+
"delay":delay
658+
}.items()
659+
if v is not None
660+
},
661+
)
604662

605663
# ------------------------------------------------------------------------------------------------------------------
606664
@connected_to_twitch
607-
async def send_extension_chat_message(self):
608-
return NotImplemented
665+
async def send_extension_chat_message(
666+
self, text:str,extension_id:str,extension_version:str
667+
):
668+
return await self._request(
669+
callback=requests.post,
670+
url=TwitchApiURL.extension_chat.value,
671+
headers=self._header_json,
672+
query_parameters={
673+
"broadcaster_id":self.user.id
674+
},
675+
data={
676+
"text":text,
677+
"extension_id":extension_id,
678+
"extension_version":extension_version
679+
}
680+
)
609681

610682
# ------------------------------------------------------------------------------------------------------------------
611683
@connected_to_twitch
612-
async def get_extensions(self):
613-
return NotImplemented
684+
async def get_extensions(
685+
self, extension_id:str,*,extension_version:str=None
686+
):
687+
return await self._request(
688+
callback=requests.get,
689+
url=TwitchApiURL.extension.value,
690+
headers=self._header,
691+
query_parameters={
692+
k:v
693+
for k, v in
694+
{"extension_id": extension_id,
695+
"extension_version": extension_version}.items()
696+
if v is not None
697+
}
698+
)
614699

615700
# ------------------------------------------------------------------------------------------------------------------
616701
@connected_to_twitch
617-
async def get_released_extensions(self):
618-
return NotImplemented
702+
async def get_released_extensions(
703+
self, extension_id:str,*,extension_version:str=None
704+
):
705+
return await self._request(
706+
callback=requests.get,
707+
url=TwitchApiURL.extension_released.value,
708+
headers=self._header,
709+
query_parameters={
710+
k:v
711+
for k, v in
712+
{"extension_id": extension_id,
713+
"extension_version": extension_version}.items()
714+
if v is not None
715+
}
716+
)
619717

620718
# ------------------------------------------------------------------------------------------------------------------
621719
@connected_to_twitch
622-
async def get_extension_bits_products(self):
623-
return NotImplemented
720+
async def get_extension_bits_products(
721+
self, *,should_include_all:bool=None
722+
):
723+
return await self._request(
724+
callback=requests.get,
725+
url=TwitchApiURL.extension.value,
726+
headers=self._header,
727+
query_parameters={
728+
k:v
729+
for k, v in
730+
{"should_include_all": should_include_all}.items()
731+
if v is not None
732+
}
733+
)
624734

625735
# ------------------------------------------------------------------------------------------------------------------
626736
@connected_to_twitch
627-
async def update_extension_bits_product(self):
628-
return NotImplemented
737+
async def update_extension_bits_product(
738+
self, sku:str,cost_amount:int, cost_type:str,display_name:str,
739+
*,in_development:bool=None,expiration:str=None,is_broadcast:bool=None
740+
):
741+
return await self._request(
742+
callback=requests.put,
743+
url=TwitchApiURL.extension.value,
744+
headers=self._header_json,
745+
data={
746+
k:v
747+
for k,v in
748+
{
749+
"sku": sku,
750+
"cost": {
751+
"amount": cost_amount,
752+
"type": cost_type
753+
},
754+
"display_name": display_name,
755+
"in_development":in_development,
756+
"expiration":expiration,
757+
"is_broadcast":is_broadcast
758+
}.items()
759+
if v is not None
760+
}
761+
)
629762

630763
# ------------------------------------------------------------------------------------------------------------------
631764
@connected_to_twitch
632-
async def create_eventsub_subscription(self):
633-
return NotImplemented
765+
async def create_eventsub_subscription(
766+
self, type_:str,version:str, condition:dict,transport:dict,
767+
):
768+
return await self._request(
769+
callback=requests.post,
770+
url=TwitchApiURL.eventsub_subscriptions.value,
771+
headers=self._header_json,
772+
data={
773+
"type": type_,
774+
"version": version,
775+
"condition": condition,
776+
"transport":transport
777+
}
778+
)
634779

635780
# ------------------------------------------------------------------------------------------------------------------
636781
@connected_to_twitch
637-
async def delete_eventsub_subscription(self):
638-
return NotImplemented
782+
async def delete_eventsub_subscription(
783+
self, id_:str
784+
):
785+
return await self._request(
786+
callback=requests.delete,
787+
url=TwitchApiURL.eventsub_subscriptions.value,
788+
headers=self._header,
789+
query_parameters={
790+
"id": id_
791+
}
792+
)
639793

640794
# ------------------------------------------------------------------------------------------------------------------
641795
@connected_to_twitch
642-
async def get_eventsub_subscriptions(self):
643-
return NotImplemented
796+
async def get_eventsub_subscriptions(
797+
self,*, status:str=None, type_:str=None, user_id:str=None, after:str
798+
):
799+
return await self._request(
800+
callback=requests.get,
801+
url=TwitchApiURL.eventsub_subscriptions.value,
802+
headers=self._header,
803+
query_parameters={
804+
k:v
805+
for k,v in
806+
{
807+
"status": status,
808+
"type":type_,
809+
"user_id":user_id,
810+
"after":after
811+
}.items()
812+
if v is not None
813+
}
814+
)
644815

645816
# ------------------------------------------------------------------------------------------------------------------
646817
@connected_to_twitch
@@ -962,9 +1133,16 @@ async def get_videos(self):
9621133
return NotImplemented
9631134

9641135
# ------------------------------------------------------------------------------------------------------------------
1136+
@user_has_scope(scope=TwitchApiScopes.ChannelManageVideos)
9651137
@connected_to_twitch
966-
async def delete_videos(self):
967-
return NotImplemented
1138+
async def delete_videos(self,id_:str):
1139+
return await self._request(
1140+
callback=requests.delete,
1141+
url=TwitchApiURL.videos.value,
1142+
headers=self._header,
1143+
query_parameters={"id": id_}
1144+
1145+
)
9681146

9691147

9701148

0 commit comments

Comments
 (0)