Basic plugins support #5
|
@ -8,9 +8,11 @@ import time
|
||||||
class GracefulShutdownException(Exception):
|
class GracefulShutdownException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LIFECYCLE_MESSAGES(Enum):
|
class LIFECYCLE_MESSAGES(Enum):
|
||||||
SHUTDOWN = auto()
|
SHUTDOWN = auto()
|
||||||
|
|
||||||
|
|
||||||
class ChatProcess(Process, ABC):
|
class ChatProcess(Process, ABC):
|
||||||
def __init__(self, event_poll_frequency):
|
def __init__(self, event_poll_frequency):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -22,6 +24,10 @@ class ChatProcess(Process, ABC):
|
||||||
self._state = None
|
self._state = None
|
||||||
self._next_state = None
|
self._next_state = None
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def keybinds(self):
|
||||||
|
return []
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def loop(self, next_state):
|
def loop(self, next_state):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import time
|
|
||||||
import random
|
import random
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
@ -23,6 +22,12 @@ class FakeChat(ChatProcess):
|
||||||
self._max_messages_per_chunk = 1
|
self._max_messages_per_chunk = 1
|
||||||
self._max_delay = 10
|
self._max_delay = 10
|
||||||
|
|
||||||
|
@property
|
||||||
|
def keybinds(self):
|
||||||
|
return {
|
||||||
|
ord('f'): {'type': CONTROL_MESSAGES.START_STOP}
|
||||||
|
}
|
||||||
|
|
||||||
def process_messages(self, message_type, args, next_state):
|
def process_messages(self, message_type, args, next_state):
|
||||||
if message_type == CONTROL_MESSAGES.START_STOP:
|
if message_type == CONTROL_MESSAGES.START_STOP:
|
||||||
running = not self.state == STATES.RUNNING
|
running = not self.state == STATES.RUNNING
|
||||||
|
|
|
@ -39,22 +39,10 @@ class YoutubeLiveProcess(ChatProcess):
|
||||||
self._live_chat_id = None
|
self._live_chat_id = None
|
||||||
self._page_token = None
|
self._page_token = None
|
||||||
|
|
||||||
@classmethod
|
@property
|
||||||
def normalize_message(cls, message):
|
def keybinds(self):
|
||||||
if message['authorDetails']['isChatOwner']:
|
|
||||||
author_type = AUTHOR_TYPES.OWNER
|
|
||||||
elif message['authorDetails']['isChatModerator']:
|
|
||||||
author_type = AUTHOR_TYPES.MODERATOR
|
|
||||||
elif message['authorDetails']['isChatSponsor']:
|
|
||||||
author_type = AUTHOR_TYPES.PATRON
|
|
||||||
else:
|
|
||||||
author_type = AUTHOR_TYPES.USER
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'text': message['snippet']['displayMessage'],
|
ord('r'): {'type': CONTROL_MESSAGES.RESTART}
|
||||||
'author_name': message['authorDetails']['displayName'],
|
|
||||||
'author_id': message['authorDetails']['channelId'],
|
|
||||||
'author_type': author_type,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def loop(self, next_state):
|
def loop(self, next_state):
|
||||||
|
@ -156,6 +144,24 @@ class YoutubeLiveProcess(ChatProcess):
|
||||||
})
|
})
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def normalize_message(cls, message):
|
||||||
|
if message['authorDetails']['isChatOwner']:
|
||||||
|
author_type = AUTHOR_TYPES.OWNER
|
||||||
|
elif message['authorDetails']['isChatModerator']:
|
||||||
|
author_type = AUTHOR_TYPES.MODERATOR
|
||||||
|
elif message['authorDetails']['isChatSponsor']:
|
||||||
|
author_type = AUTHOR_TYPES.PATRON
|
||||||
|
else:
|
||||||
|
author_type = AUTHOR_TYPES.USER
|
||||||
|
|
||||||
|
return {
|
||||||
|
'text': message['snippet']['displayMessage'],
|
||||||
|
'author_name': message['authorDetails']['displayName'],
|
||||||
|
'author_id': message['authorDetails']['channelId'],
|
||||||
|
'author_type': author_type,
|
||||||
|
}
|
||||||
|
|
||||||
def request_oauth_consent(self):
|
def request_oauth_consent(self):
|
||||||
params = {
|
params = {
|
||||||
'client_id': self._client_secrets['client_id'],
|
'client_id': self._client_secrets['client_id'],
|
||||||
|
|
25
ui/App.py
25
ui/App.py
|
@ -13,17 +13,17 @@ from chats import FakeChat, YoutubeLive
|
||||||
class App(Process):
|
class App(Process):
|
||||||
def __init__(self, chat_processes):
|
def __init__(self, chat_processes):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._running = False
|
self._chat_processes = chat_processes
|
||||||
self._display_surf = None
|
|
||||||
self._title = 'Chat monitor'
|
|
||||||
|
|
||||||
self._chat_processes = {proc.__class__: proc for proc in chat_processes}
|
self.size = self.width, self.height = 500, 1200
|
||||||
self._log_scroll = 0
|
self._title = 'Chat monitor'
|
||||||
self._scroll_speed = 20
|
self._scroll_speed = 20
|
||||||
self._max_fps = 60
|
self._max_fps = 60
|
||||||
|
|
||||||
self.chat_log = deque(maxlen=100)
|
self.chat_log = deque(maxlen=100)
|
||||||
self.size = self.width, self.height = 500, 1200
|
self._log_scroll = 0
|
||||||
|
self._running = False
|
||||||
|
self._display_surf = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def deamon(self):
|
def deamon(self):
|
||||||
|
@ -38,14 +38,11 @@ class App(Process):
|
||||||
def on_event(self, event):
|
def on_event(self, event):
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self._running = False
|
self._running = False
|
||||||
elif event.type == pygame.KEYDOWN and event.key == ord('r'):
|
elif event.type == pygame.KEYDOWN:
|
||||||
self._chat_processes[YoutubeLive.YoutubeLiveProcess].control_pipe.send(
|
for process in self._chat_processes:
|
||||||
{'type': YoutubeLive.CONTROL_MESSAGES.RESTART}
|
bound_action = process.keybinds.get(event.key)
|
||||||
)
|
if bound_action is not None:
|
||||||
elif event.type == pygame.KEYDOWN and event.key == ord('f'):
|
process.control_pipe.send(bound_action)
|
||||||
self._chat_processes[FakeChat.FakeChat].control_pipe.send(
|
|
||||||
{'type': FakeChat.CONTROL_MESSAGES.START_STOP}
|
|
||||||
)
|
|
||||||
|
|
||||||
def tick(self, dt):
|
def tick(self, dt):
|
||||||
for message in self.chat_log:
|
for message in self.chat_log:
|
||||||
|
|
Loading…
Reference in New Issue