Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Hodl #17

wants to merge 11 commits into from

Conversation

drewpearce
Copy link
Member

Please review and suggest interface changes.
!help crypto explains the new functions more in depth.

Copy link
Member

@bbriggs bbriggs left a 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.

def __init__(self, baseplate, lock):
super().__init__(baseplate, lock)
self.crypto_index = configparser.ConfigParser()
self.crypto_index.read('crypto_index.ini')
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 59347c9

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'
Copy link
Member

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.

Copy link
Member Author

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

else:
try:
query = message['text'].split()[1]
except:
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 9aecef0
and
090a524

self.reply(message, "Invalid query", opts)
self.reply(message, self._lookup_symbol(query), opts)

def _parse_multi_commands(self, message_list):
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants