mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-06-05 03:49:37 +00:00
Detect completed drops via notifications feed
This commit is contained in:
37
constants.py
37
constants.py
@@ -97,7 +97,7 @@ JsonType = Dict[str, Any]
|
|||||||
URLType = NewType("URLType", str)
|
URLType = NewType("URLType", str)
|
||||||
TopicProcess: TypeAlias = "abc.Callable[[int, JsonType], Any]"
|
TopicProcess: TypeAlias = "abc.Callable[[int, JsonType], Any]"
|
||||||
# Values
|
# Values
|
||||||
BASE_TOPICS = 2
|
BASE_TOPICS = 3
|
||||||
MAX_WEBSOCKETS = 8
|
MAX_WEBSOCKETS = 8
|
||||||
WS_TOPICS_LIMIT = 50
|
WS_TOPICS_LIMIT = 50
|
||||||
TOPICS_PER_CHANNEL = 2
|
TOPICS_PER_CHANNEL = 2
|
||||||
@@ -324,6 +324,33 @@ GQL_OPERATIONS: dict[str, GQLOperation] = {
|
|||||||
"sortTypeIsRecency": False,
|
"sortTypeIsRecency": False,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
"NotificationsView": GQLOperation( # unused, triggers notifications "update-summary"
|
||||||
|
"OnsiteNotifications_View",
|
||||||
|
"f6bdb1298f376539487f28b7f8a6b5d7434ec04ba4d7dc5c232b258410ae04d6",
|
||||||
|
variables={
|
||||||
|
"input": {},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"NotificationsList": GQLOperation( # unused
|
||||||
|
"OnsiteNotifications_ListNotifications",
|
||||||
|
"e709b905ddb963d7cf4a8f6760148926ecbd0eee0f2edc48d1cf17f3e87f6490",
|
||||||
|
variables={
|
||||||
|
"cursor": "",
|
||||||
|
"displayType": "VIEWER",
|
||||||
|
"language": "en",
|
||||||
|
"limit": 10,
|
||||||
|
"shouldLoadLastBroadcast": False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"NotificationsDelete": GQLOperation(
|
||||||
|
"OnsiteNotifications_DeleteNotification",
|
||||||
|
"13d463c831f28ffe17dccf55b3148ed8b3edbbd0ebadd56352f1ff0160616816",
|
||||||
|
variables={
|
||||||
|
"input": {
|
||||||
|
"id": "", # ID of the notification to delete
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -368,15 +395,15 @@ class WebsocketTopic:
|
|||||||
|
|
||||||
WEBSOCKET_TOPICS: dict[str, dict[str, str]] = {
|
WEBSOCKET_TOPICS: dict[str, dict[str, str]] = {
|
||||||
"User": { # Using user_id
|
"User": { # Using user_id
|
||||||
"Drops": "user-drop-events",
|
|
||||||
"CommunityPoints": "community-points-user-v1",
|
|
||||||
"Presence": "presence", # unused
|
"Presence": "presence", # unused
|
||||||
"Notifications": "onsite-notifications", # unused
|
"Drops": "user-drop-events",
|
||||||
|
"Notifications": "onsite-notifications",
|
||||||
|
"CommunityPoints": "community-points-user-v1",
|
||||||
},
|
},
|
||||||
"Channel": { # Using channel_id
|
"Channel": { # Using channel_id
|
||||||
"Drops": "channel-drop-events", # unused
|
"Drops": "channel-drop-events", # unused
|
||||||
"CommunityPoints": "community-points-channel-v1", # unused
|
|
||||||
"StreamState": "video-playback-by-id",
|
"StreamState": "video-playback-by-id",
|
||||||
"StreamUpdate": "broadcast-settings-update",
|
"StreamUpdate": "broadcast-settings-update",
|
||||||
|
"CommunityPoints": "community-points-channel-v1", # unused
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
15
twitch.py
15
twitch.py
@@ -790,6 +790,9 @@ class Twitch:
|
|||||||
self.websocket.add_topics([
|
self.websocket.add_topics([
|
||||||
WebsocketTopic("User", "Drops", auth_state.user_id, self.process_drops),
|
WebsocketTopic("User", "Drops", auth_state.user_id, self.process_drops),
|
||||||
WebsocketTopic("User", "CommunityPoints", auth_state.user_id, self.process_points),
|
WebsocketTopic("User", "CommunityPoints", auth_state.user_id, self.process_points),
|
||||||
|
WebsocketTopic(
|
||||||
|
"User", "Notifications", auth_state.user_id, self.process_notifications
|
||||||
|
),
|
||||||
])
|
])
|
||||||
full_cleanup: bool = False
|
full_cleanup: bool = False
|
||||||
channels: Final[OrderedDict[int, Channel]] = self.channels
|
channels: Final[OrderedDict[int, Channel]] = self.channels
|
||||||
@@ -1391,6 +1394,18 @@ class Twitch:
|
|||||||
self._drop_update.set_result(False)
|
self._drop_update.set_result(False)
|
||||||
self._drop_update = None
|
self._drop_update = None
|
||||||
|
|
||||||
|
@task_wrapper
|
||||||
|
async def process_notifications(self, user_id: int, message: JsonType):
|
||||||
|
if message["type"] == "create-notification":
|
||||||
|
data: JsonType = message["data"]["notification"]
|
||||||
|
if data["type"] == "user_drop_reward_reminder_notification":
|
||||||
|
self.change_state(State.INVENTORY_FETCH)
|
||||||
|
await self.gql_request(
|
||||||
|
GQL_OPERATIONS["NotificationsDelete"].with_variables(
|
||||||
|
{"input": {"id": data["id"]}}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@task_wrapper
|
@task_wrapper
|
||||||
async def process_points(self, user_id: int, message: JsonType):
|
async def process_points(self, user_id: int, message: JsonType):
|
||||||
# Example payloads:
|
# Example payloads:
|
||||||
|
|||||||
Reference in New Issue
Block a user