Compare commits
No commits in common. "19211278c8bd52c2973dc3899c3c4180c654571d" and "af7514f38a4bbd3eabbb0b4e05e15c4feef7b5f2" have entirely different histories.
19211278c8
...
af7514f38a
|
@ -19,21 +19,6 @@ class STATES(Enum):
|
||||||
FAILURE = auto()
|
FAILURE = auto()
|
||||||
|
|
||||||
|
|
||||||
class EVENTS(Enum):
|
|
||||||
SUB = auto()
|
|
||||||
RESUB = auto()
|
|
||||||
SUBGIFT = auto()
|
|
||||||
ANONSUBGIFT = auto()
|
|
||||||
SUBMYSTERYGIFT = auto()
|
|
||||||
GIFTPAIDUPGRADE = auto()
|
|
||||||
REWARDGIFT = auto()
|
|
||||||
ANONGIFTPAIDUPGRADE = auto()
|
|
||||||
RAID = auto()
|
|
||||||
UNRAID = auto()
|
|
||||||
RITUAL = auto()
|
|
||||||
BITSBADGETIER = auto()
|
|
||||||
|
|
||||||
|
|
||||||
class NonBlockingWebsocket(Process):
|
class NonBlockingWebsocket(Process):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -122,9 +107,6 @@ class Process(ChatProcess):
|
||||||
if cmd == 'PRIVMSG':
|
if cmd == 'PRIVMSG':
|
||||||
normalized_message = Process.normalize_message(hostmask, tags, args)
|
normalized_message = Process.normalize_message(hostmask, tags, args)
|
||||||
self._message_queue.put(normalized_message)
|
self._message_queue.put(normalized_message)
|
||||||
elif cmd == 'USERNOTICE':
|
|
||||||
normalized_message = Process.normalize_event(hostmask, tags, args)
|
|
||||||
self._message_queue.put(normalized_message)
|
|
||||||
elif cmd == 'PING':
|
elif cmd == 'PING':
|
||||||
self._ws.send(f"PONG {' '.join(args)}")
|
self._ws.send(f"PONG {' '.join(args)}")
|
||||||
else:
|
else:
|
||||||
|
@ -137,25 +119,12 @@ class Process(ChatProcess):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_badges(self, tags):
|
def normalize_message(cls, hostmask, tags, args):
|
||||||
if isinstance(tags.get('badges'), str):
|
badges = [badge.split('/')[0] for badge in tags.get('badges', '').split(',')]
|
||||||
return [badge.split('/')[0] for badge in tags['badges'].split(',')]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def parse_message(self, args):
|
|
||||||
# First arg is the room (which we dont care about, since it should only ever be #user)
|
# First arg is the room (which we dont care about, since it should only ever be #user)
|
||||||
# First character of the second arg is the data delimiter (:)
|
# First character of the second arg is the data delimiter (:)
|
||||||
return ' '.join(args[1:])[1:]
|
message = ' '.join(args[1:])[1:]
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def normalize_message(cls, hostmask, tags, args):
|
|
||||||
|
|
||||||
badges = Process.parse_badges(tags)
|
|
||||||
message = Process.parse_message(args)
|
|
||||||
|
|
||||||
monitization = tags.get('bits')
|
|
||||||
|
|
||||||
if 'broadcaster' in badges:
|
if 'broadcaster' in badges:
|
||||||
author_type = AUTHOR_TYPES.OWNER
|
author_type = AUTHOR_TYPES.OWNER
|
||||||
|
@ -166,32 +135,5 @@ class Process(ChatProcess):
|
||||||
else:
|
else:
|
||||||
author_type = AUTHOR_TYPES.USER
|
author_type = AUTHOR_TYPES.USER
|
||||||
|
|
||||||
author_color = tags['color'] if isinstance(tags.get('color'), str) else None
|
return Message(message, tags.get('display-name', hostmask[0]), tags.get('id'), author_type,
|
||||||
|
author_color=tags.get('color'))
|
||||||
return Message(message, tags.get('display-name', hostmask[0]), tags.get('user-id'), author_type,
|
|
||||||
author_color=author_color, monitization=monitization)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def normalize_event(cls, hostmask, tags, args):
|
|
||||||
badges = Process.parse_badges(tags)
|
|
||||||
user_message = Process.parse_message(args)
|
|
||||||
|
|
||||||
message = f"*{tags['system-msg'].strip()}*"
|
|
||||||
if user_message != '':
|
|
||||||
message += f" - {user_message}"
|
|
||||||
|
|
||||||
if 'broadcaster' in badges:
|
|
||||||
author_type = AUTHOR_TYPES.OWNER
|
|
||||||
elif any(target_badge in badges for target_badge in ['admin', 'moderator', 'global_mod']):
|
|
||||||
author_type = AUTHOR_TYPES.MODERATOR
|
|
||||||
elif 'subscriber' in badges:
|
|
||||||
author_type = AUTHOR_TYPES.PATRON
|
|
||||||
else:
|
|
||||||
author_type = AUTHOR_TYPES.USER
|
|
||||||
|
|
||||||
author_color = tags['color'] if isinstance(tags.get('color'), str) and tags['color'] != '' else None
|
|
||||||
|
|
||||||
event = EVENTS.__members__[tags['msg-id'].upper()]
|
|
||||||
|
|
||||||
return Message(message, tags.get('display-name', hostmask[0]), tags.get('user-id'), author_type,
|
|
||||||
author_color=author_color, for_event=event)
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class AUTHOR_TYPES(Enum):
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
def __init__(self, text, author_name, author_id, author_type,
|
def __init__(self, text, author_name, author_id, author_type,
|
||||||
author_color=None, monitization=None, for_event=None):
|
author_color=None, monitization=None):
|
||||||
self._text = text
|
self._text = text
|
||||||
self._author_name = author_name
|
self._author_name = author_name
|
||||||
self._author_id = author_id
|
self._author_id = author_id
|
||||||
|
@ -21,7 +21,6 @@ class Message:
|
||||||
self._author_type = author_type
|
self._author_type = author_type
|
||||||
self._author_color = author_color
|
self._author_color = author_color
|
||||||
self._monitization = monitization
|
self._monitization = monitization
|
||||||
self._for_event = for_event
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
|
@ -46,10 +45,3 @@ class Message:
|
||||||
@property
|
@property
|
||||||
def monitization(self):
|
def monitization(self):
|
||||||
return self._monitization
|
return self._monitization
|
||||||
|
|
||||||
@property
|
|
||||||
def for_event(self):
|
|
||||||
return self._for_event
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"{self._author_name} - \"{self._text}\" : author_type = {self._author_type}, monitization = {self._monitization}, for_event = {self._for_event}"
|
|
||||||
|
|
Loading…
Reference in New Issue