-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Command to Type Logic #66
Comments
How should this be done?
|
I like 2 a class method in |
Sure, I could do it. Or do you want to work on this? :P |
You were talking implementation details. 😛 You can take it, or @senpos since they feel strongly about it. |
I will do it tomorrow, if you don't mind. |
@senpos Please, go ahead :) |
How should this look like? Well, I could do something like this: class TwitchChatEventType(object):
TWITCHCHATJOIN = 'JOIN'
TWITCHCHATLEAVE = 'PART'
TWITCHCHATMESSAGE = 'PRIVMSG'
TWITCHCHATMODE = 'MODE'
TWITCHCHATCLEARCHAT = 'CLEARCHAT'
TWITCHCHATHOSTTARGET = 'HOSTTARGET'
TWITCHCHATNOTICE = 'NOTICE'
TWITCHCHATRECONNECT = 'RECONNECT'
TWITCHCHATROOMSTATE = 'ROOMSTATE'
TWITCHCHATUSERNOTICE = 'USERNOTICE'
TWITCHCHATUSERSTATE = 'USERSTATE'
TWITCHCHATWHISPER = 'WHISPER'
TWITCHCHATCOMMAND = 'COMMAND'
@classmethod
def from_command(cls, command):
if hasattr(cls, command):
return getattr(cls, command)
return cls.TWITCHCHATCOMMAND
class TwitchChatEvent(object):
def __init__(self, channel=None, command=None, message=''):
self.type = TwitchChatEventType.from_command(command)
... But this relies on the way how @PythooonUser will change the naming. So I'd postpone this change. Also, this is not the best way to gain performance. Yes, it is way better than it is now, but worse than Thoughts? |
I like it. It keeps the logic tidy. |
Did you perf test it? |
I wrote a set of performance tests to see which various implementations are fastest (which is the whole reason we are doing this work). https://gist.github.com/joshuaskelly/cc1e11cd19f2f55209f52d25b8aa18c9 My Results:
This is measuring average time per call. |
@joshuaskelly So, should we stick with the fastest way, which is mapping of Twitch commands to the actual internal According to the latest @PythooonUser PR: _COMMAND_TO_TYPE = {
'JOIN': EventType.JOIN,
'PART': EventType.LEAVE,
'PRIVMSG': EventType.MESSAGE,
'MODE': EventType.MODE,
'CLEARCHAT': EventType.CLEARCHAT,
'HOSTTARGET': EventType.HOSTTARGET,
'NOTICE': EventType.NOTICE,
'RECONNECT': EventType.RECONNECT,
'ROOMSTATE': EventType.ROOMSTATE,
'USERNOTICE': EventType.USERNOTICE,
'USERSTATE': EventType.USERSTATE,
'WHISPER': EventType.WHISPER
}
class Event:
def __init__(...):
_COMMAND_TO_TYPE.get(command, EventType.COMMAND) |
Is this still being worked on? |
@PythooonUser |
Summary
Rather than constructing a new command to type dictionary each time an event is init'd, we should cache the dictionary.
The text was updated successfully, but these errors were encountered: