GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AddCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %
Metric Value
dl 0
loc 34
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A default() 0 8 3
A add() 0 3 1
A process_howmuch() 0 9 2
A get_amount() 0 8 2
1
import re
2
from functools import partial
3
4
import telegram
5
6
from . import BotCommand, CommandError
7
8
9
class AddCommand(BotCommand):
10
    command = '/add'
11
12
    def get_amount(self, content):
13
        match = re.match('((/add )|(/remove ))?(?P<amount>\d+(\.\d+)?)( (?P<reason>.*))?', content)
14
        if not match:
15
            raise CommandError()
16
17
        amount = float(match.groupdict()['amount'])
18
        reason = match.groupdict()['reason']
19
        return amount, reason
20
21
    def add(self, tab_id, user_id, message_id, date, amount, reason=''):
22
        tab = self.get_tab(tab_id)
23
        tab.add(message_id, user_id, date, amount, reason)
24
25
    def default(self, message):
26
        content = message.text.split(' ', 1)[1] if len(message.text.split(' ', 1)) == 2 else ''
27
        if content:
28
            self.process_howmuch(message)
29
        else:
30
            msg = self.bot.say(message, 'How much?',
31
                               reply_markup=telegram.ForceReply(selective=True))
32
            self.queue(msg, partial(self.process_howmuch))
33
34
    def process_howmuch(self, message):
35
        try:
36
            amount, reason = self.get_amount(message.text)
37
        except CommandError:
38
            self.bot.say(message, "Nope, I don't get ya")
39
            return
40
        self.add(message.chat.id, message.from_user.id, message.message_id,
41
                 message.date, amount, reason)
42
        self.bot.say(message, telegram.Emoji.THUMBS_UP_SIGN)
43