コード例 #1
0
 def process(self, event):
     message = event.message
     chat = message.chat
     new_chat_member = message.new_chat_member
     if new_chat_member is not None:
         if new_chat_member.id == self.cache.bot_info.id:
             reply = Message.create_reply(
                 message, "Hi! I'm " + self.cache.bot_info.first_name +
                 " and have just entered " + chat.title)
         else:
             reply = Message.create_reply(
                 message, "Hello " + new_chat_member.first_name +
                 ". Welcome to " + chat.title)
         self.api.send_message(reply)
コード例 #2
0
 def send_current_status(self, handler, prepend=""):
     status = handler.get_status_string()
     response = prepend + "Current status of *%s*: *%s*" % (handler.feature,
                                                            status.upper())
     self.api.send_message(Message.create_reply(handler.event.message,
                                                response),
                           parse_mode="Markdown")
コード例 #3
0
 def process(self, event):
     from_ = event.message.from_
     if from_ is not None and str(from_.id) == self.config.admin_user_id:
         self._continue(event)
     else:
         error_response = "You are not allowed to perform this action (admins only)."
         self.api.send_message(
             Message.create_reply(event.message, error_response))
コード例 #4
0
 def process(self, event):
     message = event.message
     left_chat_member = message.left_chat_member
     if left_chat_member is not None:
         if left_chat_member.id != self.cache.bot_info.id:
             reply = Message.create_reply(
                 message, "" + left_chat_member.first_name +
                 " was kicked by " + message.from_.first_name)
             self.api.send_message(reply)
コード例 #5
0
 def process(self, event):
     chat = event.message.chat
     if chat.type == "private":
         # lets consider private chat members are admins :)
         self._continue(event)
     else:
         user = event.message.from_
         if user is not None:
             chat_member = self.api.no_async.getChatMember(chat_id=chat.id,
                                                           user_id=user.id)
             if chat_member.status in ("creator", "administrator"):
                 self._continue(event)
             else:
                 error_response = "Sorry, this command is only available to group admins."
                 self.api.send_message(
                     Message.create_reply(event.message, error_response))
コード例 #6
0
 def process(self, event):
     self.api.send_message(Message.create_reply(event.message, self.text))
コード例 #7
0
 def process(self, event):
     response_text = "Bot stopped.\nYou need to launch it manually for it to work again."
     self.api.no_async.send_message(
         Message.create_reply(event.message, response_text))
     sys.exit(EXIT_STATUS_TO_HALT_BOT)
コード例 #8
0
 def process(self, event):
     response_text = "Restarting bot...\nCommands might not work while restarting."
     self.api.no_async.send_message(
         Message.create_reply(event.message, response_text))
     raise KeyboardInterrupt()