Basic plugins support #5
6
main.py
6
main.py
|
@ -6,6 +6,7 @@ from chats import YoutubeLive
|
||||||
from chats.ChatProcess import LIFECYCLE_MESSAGES
|
from chats.ChatProcess import LIFECYCLE_MESSAGES
|
||||||
from chats.FakeChat import FakeChat
|
from chats.FakeChat import FakeChat
|
||||||
from ui.App import App
|
from ui.App import App
|
||||||
|
from plugins.PogCount import PogCounter
|
||||||
|
|
||||||
EVENT_POLL_FREQ = 0.1
|
EVENT_POLL_FREQ = 0.1
|
||||||
GOOGLE_API_SECRETS_PATH = 'googleapi.secret.json'
|
GOOGLE_API_SECRETS_PATH = 'googleapi.secret.json'
|
||||||
|
@ -19,7 +20,10 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print('No client secrets - disabling youtube chat client. Hit "f" to enable a testing client')
|
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:
|
for process in chat_processes:
|
||||||
process.start()
|
process.start()
|
||||||
app.start()
|
app.start()
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue