Skip to content

Delete messages#84

Merged
emilyalbini merged 1 commit intopython-botogram:masterfrom
MarcoBuster:delete-messages
Jun 15, 2017
Merged

Delete messages#84
emilyalbini merged 1 commit intopython-botogram:masterfrom
MarcoBuster:delete-messages

Conversation

@MarcoBuster
Copy link
Copy Markdown
Member

In upcoming Telegram bots API upgrade, bots will able to delete messages sent by itself and sent by users in a supergroup where the bot is admin.
I've added two new methods, message.delete() and chat.delete_message().

Example usage:

@bot.command("delete")
def delete(chat, message, args):
   if message.reply_to_message:
        message.reply_to_message.delete()
   else:
        message.reply("Reply to a message to delete it!")
        return

   message.delete()
   msg = chat.send("Message deleted, sir!")
   time.sleep(5)
   chat.delete_message(msg)  # Or msg.delete()

return self._api.call("sendContact", args, expect=_objects().Message)

@_require_api
def delete_message(self, message):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add the docstring.

message = message.message_id

return self._api.call("deleteMessage", {
"chat_id": self.id, "message_id": message
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put all of these on their own line, with a traling comma in all of them?

{
    "chat_id": self.id,
    "message_id": message,
}

def delete(self):
"""Delete the message"""
return self._api.call("deleteMessage", {"chat_id": self.chat.id,
"message_id": self.message_id})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same style for the parameters as the other method.


Delete the selected message.
A message can be deleted only if is sent by the bot or sent in a supergroup by an user where the bot is admin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add the versionadded (0.4) and the documentation for the parameter.


Delete the message self.
A message can be deleted only if is sent by the bot or sent in a supergroup by an user where the bot is admin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add the versionadded (0.4)

@emilyalbini emilyalbini added this to the botogram 0.4 milestone May 7, 2017
@MarcoBuster
Copy link
Copy Markdown
Member Author

@pietroalbini Done, it's all ok, right?

emilyalbini
emilyalbini previously approved these changes May 7, 2017
Copy link
Copy Markdown
Contributor

@emilyalbini emilyalbini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

emilyalbini
emilyalbini previously approved these changes May 7, 2017
Copy link
Copy Markdown
Contributor

@emilyalbini emilyalbini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MarcoBuster
Copy link
Copy Markdown
Member Author

MarcoBuster commented May 21, 2017

@pietroalbini Maybe we're ready to merge?

@emilyalbini
Copy link
Copy Markdown
Contributor

Can you add in the docs that in supergroups it's possibile to delete some service messages?


.. py:method:: delete()

Delete the message self.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? "Delete this message. The message can be deleted only if... It can also be deleted if it's one of the supported service messages."


.. py:method:: delete_message(message)

Delete the selected message.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Delete the message with the provided ID"

Copy link
Copy Markdown
Member Author

@MarcoBuster MarcoBuster Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...or botogram.Message object

Copy link
Copy Markdown
Contributor

@emilyalbini emilyalbini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@emilyalbini emilyalbini merged commit 2ce9f50 into python-botogram:master Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants