From 33aa1debca00406732945f73e2f569a685b1a068 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Fri, 13 Mar 2015 20:13:00 +0000 Subject: [PATCH] reddit: fix amount parsing It was only allowing floats (ie, with a decimal dot). --- tipbot/modules/reddit.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/reddit.py b/tipbot/modules/reddit.py index 41e4b9f..bdd607e 100644 --- a/tipbot/modules/reddit.py +++ b/tipbot/modules/reddit.py @@ -152,12 +152,16 @@ class RedditNetwork(Network): # reddit special: +x as a reply means tip if not is_pm and hasattr(item,'parent_id'): line=line.replace(self.keyword,'').strip() - if re.match("\+[0-9]*\.[0-9]*",line): + if re.match("\+[0-9]*(\.[0-9]*)?",line): if self.on_command: try: parent_item=self.reddit.get_info(thing_id=item.parent_id) + if not hasattr(parent_item,'author'): + raise RuntimeError('Parent item has no author') author=parent_item.author.name - synthetic_cmd=['tip',author,line.replace('+','')] + match=re.search("\+[0-9]*(\.[0-9]*)?",line) + amount=match.group(0) + synthetic_cmd=['tip',author,amount.replace('+','')] log_log('Running synthetic command: %s' % (str(synthetic_cmd))) self.on_command(link,synthetic_cmd) except Exception,e: