mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 15:15:37 +01:00
Add lock
This commit is contained in:
@@ -41,6 +41,8 @@ class TokenStorage:
|
|||||||
|
|
||||||
|
|
||||||
class TwitchService:
|
class TwitchService:
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
SCOPES = [
|
SCOPES = [
|
||||||
AuthScope.CHAT_READ,
|
AuthScope.CHAT_READ,
|
||||||
AuthScope.CHAT_EDIT,
|
AuthScope.CHAT_EDIT,
|
||||||
@@ -126,6 +128,7 @@ class TwitchService:
|
|||||||
if stream is None:
|
if stream is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
async with self.lock:
|
||||||
current_state = self.state.get(brodcaster_id)
|
current_state = self.state.get(brodcaster_id)
|
||||||
if current_state is None:
|
if current_state is None:
|
||||||
return
|
return
|
||||||
@@ -152,9 +155,9 @@ class TwitchService:
|
|||||||
last_live_at=datetime.now()
|
last_live_at=datetime.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async with self.lock:
|
||||||
current_state = self.state.get(streamer_id)
|
current_state = self.state.get(streamer_id)
|
||||||
|
|
||||||
|
|
||||||
is_need_notify = current_state is None or (datetime.now() - current_state.last_live_at).seconds >= self.ONLINE_NOTIFICATION_DELAY
|
is_need_notify = current_state is None or (datetime.now() - current_state.last_live_at).seconds >= self.ONLINE_NOTIFICATION_DELAY
|
||||||
|
|
||||||
self.state[streamer_id] = state
|
self.state[streamer_id] = state
|
||||||
|
|||||||
Reference in New Issue
Block a user