-
Notifications
You must be signed in to change notification settings - Fork 0
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
Hodl #17
base: master
Are you sure you want to change the base?
Hodl #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got through about 50% of it. I'll finish as time permits later this week.
Basically, parsing multiple arguments is hard. It gets harder when you want to branch many, many ways.
legos/cryptocurrency.py
Outdated
def __init__(self, baseplate, lock): | ||
super().__init__(baseplate, lock) | ||
self.crypto_index = configparser.ConfigParser() | ||
self.crypto_index.read('crypto_index.ini') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use a config file, you should check for presence first. I recommend making a configure method to handle this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by 59347c9
legos/cryptocurrency.py
Outdated
self.crypto_index.read('crypto_index.ini') | ||
if 'crypto_index' not in self.crypto_index.sections(): | ||
self.crypto_index['crypto_index'] = {} | ||
self.crypto_index['crypto_index']['fsyms'] = 'BTC' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Cryptowatch may have used the horribly cryptic fsyms
and tsyms
, but that doesn't mean we have to. It would probably benefit the user if we made these terms more clear and documented what they correspond to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved.
changed crypto_index to hodl
changed fsyms to convert_from
changed tsyms to convert_to
legos/cryptocurrency.py
Outdated
else: | ||
try: | ||
query = message['text'].split()[1] | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're splitting and looking for an index here, the exception you're almost certainly going to raise is an IndexError
, which is what I would catch. Upon catching the index error, I'd then return a helpful message indicating as much.
try:
query: message['text'].split()[1]
except IndexError:
self.reply(message, "Not enough arguments or something", opts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legos/cryptocurrency.py
Outdated
self.reply(message, "Invalid query", opts) | ||
self.reply(message, self._lookup_symbol(query), opts) | ||
|
||
def _parse_multi_commands(self, message_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're falling into the same trap we fell into with the proto-legobot back in 2013-14. This pattern didn't scale well for us back then and probably won't in this case either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'splain this one more plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tried to write something along a similar pattern where we'd basically split the message and then branch on each option. It ended up getting messy, which was what drove us to the plugin model.
Using argparse for positional arguments or splitting hodl into another lego might be the way to go given how many branches we're starting to accumulate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved by moving hodl to its own lego
Please review and suggest interface changes.
!help crypto explains the new functions more in depth.