示例#1
0
 def boughtItem(self, del_index):
     item_name = to_buy_list[del_index]
     del to_buy_list[del_index]
     self.writeListToFile()
     # self.sender.sendMessage(text=u'Okay。依家仲' + self.genBuyList(), reply_markup=self.genKeyboard())
     for white_user in white_list:
         self.bot.sendMessage(white_user, text=u'買左:' + chkNConv(item_name), reply_markup=self.genKeyboard())
示例#2
0
    def genKeyboard(self):
        print('generate keyboard')
        show_keyboard = {'keyboard': [[u'今日 day 幾',u'某日係 day 幾'], [u'有乜未買?', u'有野要買']]}

        for idx, item in enumerate(to_buy_list):
            show_keyboard['keyboard'].append([u'買左[' + chkNConv(idx.__str__()) + u']: ' + chkNConv(item)])
        return show_keyboard
示例#3
0
    def on_message(self, msg):
        print('on_message() is being called')
        flavor = telepot.flavor(msg)

        # normal message
        if flavor == 'normal':
            content_type, chat_type, _chat_id = telepot.glance2(msg)
            print('Normal Message:', content_type, chat_type, _chat_id, '; message content: ', msg)

            if _chat_id in white_list :

                if self._convert_type == ConverType.nothing:
                    if chkNConv(msg['text']) == u'/start' or chkNConv(msg['text']) == u'/today' or chkNConv(msg['text']) == u'今日 day 幾':
                        self.sender.sendMessage(text=u'Today is ' + chkNConv(str(date.today())) + u'. \n' +
                                                               u'It is my day ' + chkNConv(str(Jinny.getNumOfDays())) + u'. \n' +
                                                               u'Use /help for more options',
                                                reply_markup=self.genKeyboard())
                    elif chkNConv(msg['text']) == u'/help':
                        self.sender.sendMessage(text=u'/today - get today\'s date and my day count. \n' +
                                                               u'/help - for those who have bad memory. \n' +
                                                               u'/query - check my day count for a particular date. \n',
                                                reply_markup=self.genKeyboard())
                    elif chkNConv(msg['text']) == u'/query' or chkNConv(msg['text']) == u'某日係 day 幾':
                        self._convert_type = ConverType.asking_date
                        self.sender.sendMessage(text=u'邊日呀 ?', reply_markup={'hide_keyboard': True})
                    elif chkNConv(msg['text']) == u'/No' :
                        self._convert_type = ConverType.nothing
                        self.sender.sendMessage(text=u'Bye !',
                                                reply_markup=self.genKeyboard())
                    elif chkNConv(msg['text']) == u'有野要買':
                        self._convert_type = ConverType.adding_to_buy
                        self.sender.sendMessage(text=u'買乜?', reply_markup={'hide_keyboard': True})
                    elif chkNConv(msg['text']) == u'有乜未買?':
                        self.sender.sendMessage(text=self.genBuyList(), reply_markup=self.genKeyboard())
                    elif re.compile(u'買左\[\d+\].*').match(chkNConv(msg['text'])) != None:
                        match_obj = re.compile(u'買左\[(\d+)\].*').match(chkNConv(msg['text']))
                        del_index = match_obj.group(1)
                        self.boughtItem(del_index=int(del_index))

                    else:
                        self.sender.sendMessage(text=u'我唔明呀。\n' +
                                                     u'你試多次啦。或者用 /help 我就教你用。')
                elif self._convert_type == ConverType.asking_date:
                    try :
                        self.sender.sendMessage(text=u'For ' + chkNConv(msg['text']) + u', It is my day ' +
                                                     chkNConv(str(Jinny.getNumOfDaysSpecific(msg['text']))) +
                                                     u'. Any other date to ask ? /No ?')
                    except BaseException :
                        self.sender.sendMessage(text=u'Not a data that I can understand ! \n' +
                                                     u'What date (YYYYMMDD) ? \nOr you done ? ( /No )')
                elif self._convert_type == ConverType.adding_to_buy:
                    if chkNConv(msg['text']) == u'/done':
                        self._convert_type = ConverType.nothing
                        self.doneWithBuyList()
                        self.writeListToFile()
                    else:
                        to_buy_list.append(chkNConv(msg['text']))
                        self.sender.sendMessage(text=u'仲有冇?如果冇,就用 /done 完結。', reply_markup={'hide_keyboard': True})
                else:
                    self.sender.sendMessage(text=u'我唔明呀。\n' +
                                                 u'你試多次啦。或者用 /help 我就教你用。')

            else:
                self.sender.sendMessage(text=u'你邊位呀?')
        else:
            raise telepot.BadFlavor(msg)

        print(u'to buy list: ' + self.genBuyList())
示例#4
0
    def genBuyList(self):
        buy_list = u'要買呢D:\n\n'
        for item in to_buy_list:
            buy_list = buy_list + u'- ' + chkNConv(item) + u'\n'

        return buy_list