[Chat] Port fakechat to plugin

This commit is contained in:
Derek 2023-01-18 18:54:26 -05:00
parent 402227f731
commit a6d1162665
4 changed files with 61 additions and 80 deletions
ovtk_audiencekit
chats/FakeChat
plugins/FakeChat

View file

@ -1,79 +0,0 @@
import random
from enum import Enum, auto
from ovtk_audiencekit.chats import ChatProcess
from ovtk_audiencekit.events import Event, Message, SysMessage
from ovtk_audiencekit.events.Message import USER_TYPE
class STATES(Enum):
PAUSED = auto()
RUNNING = auto()
class StartStop(Event):
pass
class FakeChat(ChatProcess):
def __init__(self, *args, max_delay=10, max_messages_per_chunk=1, start_paused=True, max_monitization=None, **kwargs):
super().__init__(*args, **kwargs)
self._max_delay = max_delay
self._max_messages_per_chunk = max_messages_per_chunk
self._max_monitization = max_monitization
self.state = STATES.PAUSED if start_paused else STATES.RUNNING
def process_messages(self, event, next_state):
if isinstance(event, StartStop):
running = not self.state == STATES.RUNNING
text = 'Fake chat activated!' if running else 'Disabled fake chat'
sys_msg = SysMessage(self._name, text)
self.publish(sys_msg)
return STATES.RUNNING if running else STATES.PAUSED
def loop(self, next_state):
if self.state == STATES.PAUSED:
return None
while range(int(random.random() * (self._max_messages_per_chunk + 1))):
author_name, author_id, author_type = random.choice([
('Random user', '123123', USER_TYPE.PATRON),
('Some Guy', '723894', USER_TYPE.PATRON),
('xX_ButtSlayerMan1967_Xx', '324234', USER_TYPE.PATRON),
('My name is uncessisarily long why does yt allow this', '123786986', USER_TYPE.PATRON),
('Taco Bell official (i wish)', '8979823', USER_TYPE.PATRON),
('skeh', '1337', USER_TYPE.OWNER),
('rando_mod', '6969', USER_TYPE.MODERATOR),
])
text = random.choice([
'Some fake user saying some shid',
'Another fake message from a fake fan (lol)',
'Why play games when you could eat bean',
'pog more like log',
'playing the game :drake_dislike:\nspending hours getting the game to run well :drake_like:',
'now thats what i call epic',
'POG',
'cheese',
'oh yeah, thats one neat chat',
'lmao fake chat',
'nice chat you got there, be a shame if someone spammed it',
' i like m y whitespace ',
'no i \n\n\n like my\nwhite\nspace',
'this fake user is chatty and say a lot of various things, but its still a coherent sentance somehow',
'Thanks for coming to my ted talk. Tonight, I discuss what exactly it means to be your little pogchamp, and how "come here" is actually propoganda in disquise. I am very good at parties i swear, please come to my party p l ea se',
'USRE VERY EXCITE POGGGG POG POGGGGGGGGGGGGGGGGGGGGGGGG POGPOGPOGGGG',
'spaamamspmapmdpmaspmspsapmspmapsmpasmspmapmpasmspmapmspampsmpaspaspamapmspmapmspmapsmpamspamspmapsmpmaspmapmspamspmapsmpamspmpamspms',
])
if self._max_monitization and random.random() > 0.5:
amount = random.random() * self._max_monitization
monitization = (amount, amount)
else:
monitization = None
fake_message = Message(self._name, text,
author_name, author_id, author_type,
monitization=monitization)
self.publish(fake_message)
return random.random() * self._max_delay

View file

@ -1 +0,0 @@
from .FakeChat import FakeChat as Process

View file

@ -0,0 +1,60 @@
import random
import asyncio
from enum import Enum, auto
from ovtk_audiencekit.plugins import PluginBase
from ovtk_audiencekit.events import Event, Message, SysMessage
from ovtk_audiencekit.events.Message import USER_TYPE
test_users = [
('Random user', '123123', USER_TYPE.USER),
('Some Guy', '723894', USER_TYPE.PATRON),
('xX_ButtSlayerMan1967_Xx', '324234', USER_TYPE.VIP),
('The hacker known as Anonymous', '1337', USER_TYPE.ANON),
('My name is uncessisarily long why does yt allow this', '123786986', USER_TYPE.USER),
('Taco Bell official (i wish)', '8979823', USER_TYPE.PATRON),
('skeh', '420', USER_TYPE.OWNER),
('chat maid', '6969', USER_TYPE.MODERATOR),
]
test_messages = [
('Another fake message from a fake fan (lol)', None),
('Why play games when you could eat bean', None),
('pog more like log', None),
('now thats what i call epic', None),
('POG', None),
('oh yeah, thats one neat chat', None),
('lmao fake chat', None),
(' i like m y whitespace ', None),
('no i \n\n\n like my\nwhite\nspace', None),
('Thanks for coming to my ted talk. Tonight, I discuss what exactly it means to be your little pogchamp, and how "come here" is actually propoganda in disquise. I am very good at parties i swear, please come to my party p l ea se', None),
('USRE VERY EXCITE POGGGG POG POGGGGGGGGGGGGGGGGGGGGGGGG POGPOGPOGGGG', None),
('spaamamspmapmdpmaspmspsapmspmapsmpasmspmapmpasmspmapmspampsmpaspaspamapmspmapmspmapsmpamspamspmapsmpmaspmapmspamspmapsmpamspmpamspms', None),
('poggy woggy freebie deeby', 0),
('Hey do you want a penny', 0.01),
('show feet', 10),
('whats up guys suspcicously wealthy furry here', 1_000),
]
class FakeChat(PluginBase):
def __init__(self, *args, max_delay=10, max_messages_per_chunk=1, **kwargs):
super().__init__(*args, **kwargs)
self._max_delay = max_delay
self._max_messages_per_chunk = max_messages_per_chunk
self._readtask = asyncio.get_event_loop().create_task(self.loop())
async def loop(self):
while True:
while range(int(random.random() * (self._max_messages_per_chunk + 1))):
author_name, author_id, author_type = random.choice(test_users)
text, monitization = random.choice(test_messages)
fake_message = Message(self._name, text,
author_name, author_id, author_type,
monitization=monitization)
self.send_to_bus(fake_message)
await asyncio.sleep(random.random() * self._max_delay)
def run(self):
pass

View file

@ -0,0 +1 @@
from .FakeChat import FakeChat as Plugin