コード例 #1
0
ファイル: main.py プロジェクト: tshradheya/countmeinbot
    def handle_exception(self, exception, debug):
        if isinstance(exception, apiproxy_errors.OverQuotaError):
            logging.warning(exception)

            if self.update.message:
                uid = str(self.update.message.chat.id)
                backend.send_message(chat_id=uid, text=self.ERROR_OVER_QUOTA)
            elif self.update.callback_query:
                self.answer_callback_query(self.ERROR_OVER_QUOTA)
            elif self.update.inline_query:
                result = {
                    'type': 'article',
                    'id': 'OVER_QUOTA',
                    'thumb_url': self.THUMB_URL,
                    'title': 'Sorry!',
                    'description': self.ERROR_OVER_QUOTA,
                    'input_message_content': {
                        'message_text': self.ERROR_OVER_QUOTA
                    }
                }
                self.answer_inline_query([result])

            return

        logging.exception(exception)
        self.abort(500)
コード例 #2
0
ファイル: gui.py プロジェクト: Olczix/BSK_project1
 def send_message(self):
     # add validation if encryption_mode is empty/None
     action_result = backend.send_message(
         message=self.message.text, encryption_mode=self.encryption_mode)
     self.message.text = ""
     popUp(action_result)
コード例 #3
0
ファイル: main.py プロジェクト: tshradheya/countmeinbot
 def deliver_poll(poll):
     backend.send_message(0.5,
                          chat_id=uid,
                          text=poll.render_text(),
                          parse_mode='HTML',
                          reply_markup=poll.build_admin_buttons())
コード例 #4
0
ファイル: main.py プロジェクト: tshradheya/countmeinbot
    def handle_message(self):
        message = self.update.message

        User.populate_by_id(message.from_user.id,
                            first_name=message.from_user.first_name,
                            last_name=message.from_user.last_name,
                            username=message.from_user.username)

        if not message.text:
            return

        text = message.text
        uid = str(message.chat.id)
        responding_to = memcache.get(uid)

        def deliver_poll(poll):
            backend.send_message(0.5,
                                 chat_id=uid,
                                 text=poll.render_text(),
                                 parse_mode='HTML',
                                 reply_markup=poll.build_admin_buttons())

        if text.startswith('/start'):
            backend.send_message(chat_id=uid, text=self.NEW_POLL)
            memcache.set(uid, value='START', time=3600)
            return

        elif text == '/done' and responding_to and responding_to.startswith(
                'OPT '):
            poll = Poll.get_by_id(int(responding_to[4:]))
            if not poll.options:
                backend.send_message(chat_id=uid,
                                     text=self.ERROR_PREMATURE_DONE)
                return
            backend.send_message(chat_id=uid, text=self.DONE)
            deliver_poll(poll)

        elif text == '/polls':
            header = [util.make_html_bold('Your polls')]

            recent_polls = Poll.query(
                Poll.admin_uid == uid).order(-Poll.created).fetch(50)
            body = [
                u'{}. {}'.format(i + 1, poll.generate_poll_summary_with_link())
                for i, poll in enumerate(recent_polls)
            ]

            footer = ['Use /start to create a new poll.']

            output = u'\n\n'.join(header + body + footer)

            backend.send_message(chat_id=uid, text=output, parse_mode='HTML')

        elif text.startswith('/view_'):
            try:
                poll = Poll.get_by_id(int(text[6:]))
                if not poll or poll.admin_uid != uid:
                    raise ValueError
                deliver_poll(poll)
            except ValueError:
                backend.send_message(chat_id=uid, text=self.HELP)

        elif responding_to == 'START':
            new_poll_key = Poll.new(admin_uid=uid, title=text).put()
            bold_title = util.make_html_bold_first_line(text)
            backend.send_message(chat_id=uid,
                                 text=self.FIRST_OPTION.format(bold_title),
                                 parse_mode='HTML')
            memcache.set(uid,
                         value='OPT {}'.format(new_poll_key.id()),
                         time=3600)
            return

        elif responding_to and responding_to.startswith('OPT '):
            poll = Poll.get_by_id(int(responding_to[4:]))
            poll.options.append(Option(text))
            poll.put()
            if len(poll.options) < 10:
                backend.send_message(chat_id=uid, text=self.NEXT_OPTION)
                return
            backend.send_message(chat_id=uid, text=self.DONE)
            deliver_poll(poll)

        else:
            backend.send_message(chat_id=uid, text=self.HELP)

        memcache.delete(uid)
コード例 #5
0
 def send_msg(self, event):
     backend.send_message(message=self.text_input.text,
                          encryption_mode='CBC')
     self.send_response.dismiss()
     popUp(PopUpMode.SUCCESS_MESSAGE_SEND)