Basic plugins support #5

Merged
skeh merged 4 commits from plugins into main 2021-04-08 01:55:48 +00:00
2 changed files with 17 additions and 7 deletions
Showing only changes of commit 9e8d05fc90 - Show all commits

1
plugins/__init__.py Normal file
View File

@ -0,0 +1 @@
from chats import AUTHOR_TYPES

View File

@ -11,9 +11,10 @@ from chats import FakeChat, YoutubeLive
class App(Process):
def __init__(self, chat_processes):
def __init__(self, chat_processes, plugins):
super().__init__()
self._chat_processes = chat_processes
self._plugins = plugins
self.size = self.width, self.height = 500, 1200
self._title = 'Chat monitor'
@ -45,15 +46,23 @@ class App(Process):
process.control_pipe.send(bound_action)
def tick(self, dt):
for process in self._chat_processes:
if not process.message_queue.empty():
message = process.message_queue.get()
for plugin in self._plugins:
message = plugin.on_message(message)
if message is None:
break
else:
message_view = MessageView(message, self.size)
self.chat_log.append(message_view)
self._log_scroll += message_view.rect.height
for message in self.chat_log:
message.tick(dt)
for name, process in self._chat_processes.items():
if not process.message_queue.empty():
new_message = process.message_queue.get()
message = MessageView(new_message, self.size)
self.chat_log.append(message)
self._log_scroll += message.rect.height
for plugin in self._plugins:
plugin.tick(dt)
if (self._log_scroll > 0):
self._log_scroll -= min(max((dt / 1000) * (self._log_scroll) * self._scroll_speed, 0.25), self.height / 4)