Skip to content

Send /cleanup response to private user chat instead of current chat. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2017

Conversation

noplanman
Copy link

Added a new parameter to the Command class called $private_only.

Setting that to true and calling the respective command in a public chat does the following:

  • Delete the public message
  • Post a private message to the sender saying that the command works in private chats only. This message also contains the original command call, so that it can just be copy-pasted.

It would also be possible to simply overwrite the Update object to act as if the command was called from a private chat in the first place, but that might be pushing it.
What do you think?

Also, I haven't managed to get this to work for channels, not quite sure why, but the command doesn't have a message object in it, weirdly 😕

@jacklul
Copy link
Owner

jacklul commented Aug 3, 2017

So wait, this removes user message for example user calls /cleanup in group chat then his message gets removed and notice is sent to private chat with him?

@noplanman
Copy link
Author

Exactly. Alternatively, it's obviously also possible to just modify the first command message sent, to the notification message being sent to the private chat, instead of deleting it completely.

@jacklul
Copy link
Owner

jacklul commented Aug 3, 2017

@noplanman Well, I would say it's fine, what's the problem with channel? I don't think bot is supposed to execute commands from messages posted in channels

@noplanman
Copy link
Author

Ah right, of course. So we just completely ignore those then?

@jacklul
Copy link
Owner

jacklul commented Aug 3, 2017

@noplanman As far as I'm understanding the API there is no way to send normal update with message object to the channel? There is channel_post one but we don't use it for handling commands and thats ok.

Should I go on and merge?

@noplanman
Copy link
Author

Yes, we'd have to use $update->getChannelPost().

Strangely though, the command's execute method does get called via channel message.
Hmm, need to see what's up.

Shall we create a separate PR for the $private_only feature? Might make sense to keep it clean.

@jacklul
Copy link
Owner

jacklul commented Aug 3, 2017

Shall we create a separate PR for the $private_only feature? Might make sense to keep it clean.

Yeah.

@noplanman
Copy link
Author

Ok, have made the other PR here: php-telegram-bot#580

When that's merged, we can simply add the parameter to this command, and voilà 👍

@noplanman noplanman changed the title [WIP] New command parameter to enforce usage in private chats only. Send /cleanup response to private user chat instead of current chat. Aug 4, 2017
@noplanman
Copy link
Author

noplanman commented Aug 5, 2017

Alrighty then, have merged and added $private_only = true;.

I think we're ready for this merge too.

Hmm, thinking about this, it would make sense to set $private_only to true by default for all Admin commands I think, what do you think?
In which case I'll remove it again and add it to AdminCommand directly.

@jacklul
Copy link
Owner

jacklul commented Aug 6, 2017

Yep, making it default for admin commands makes sense!

@noplanman
Copy link
Author

Alrighty, have dropped the last commit (with $private_only), so this can be merged, then I'll merge it to develop and add the parameter to AdminCommand directly.

@jacklul jacklul merged commit 782eff0 into jacklul:cleanup_nodb Aug 6, 2017
@noplanman noplanman deleted the cleanup_nodb branch September 4, 2017 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants