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 41 additions and 1 deletions
Showing only changes of commit 9e8d05fc90 - Show all commits

View File

@ -6,6 +6,7 @@ from chats import YoutubeLive
from chats.ChatProcess import LIFECYCLE_MESSAGES
from chats.FakeChat import FakeChat
from ui.App import App
from plugins.PogCount import PogCounter
EVENT_POLL_FREQ = 0.1
GOOGLE_API_SECRETS_PATH = 'googleapi.secret.json'
@ -19,7 +20,10 @@ if __name__ == '__main__':
else:
print('No client secrets - disabling youtube chat client. Hit "f" to enable a testing client')
app = App(chat_processes)
plugins = [PogCounter('../live-status.txt', prefix='Pog count: ')]
app = App(chat_processes, plugins)
for process in chat_processes:
process.start()
app.start()

36
plugins/PogCount.py Normal file
View File

@ -0,0 +1,36 @@
class PogCounter:
def __init__(self, out, prefix=None):
self.out = out
self.prefix = prefix
self._count = 0
self._timer = 0
self._dirty = True
def normalize(self, text):
def remove_dups(text):
last_char = None
for char in list(text):
if last_char == char:
continue
last_char = char
yield char
return ''.join(remove_dups(text.lower()))
def tick(self, dt):
self._timer += dt
if self._timer > 1 and self._dirty:
with open(self.out, 'w') as f:
f.write(f"{self.prefix}{self._count}")
self._timer = 0
self._dirty = False
def handle_event(self, event):
pass
def on_message(self, message):
normalized = self.normalize(message['text'])
if any(phrase in normalized for phrase in ['pog', 'p o g']):
self._count += 1
self._dirty = True
return message