-
-
Notifications
You must be signed in to change notification settings - Fork 187
Fix help command not working in group chats #10
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
Conversation
Reply was sent to sender's chat instead of the group.
@0xEAB This is intentional, to make sure that no admin commands get leaked by mistake. If you want it be available in group chats too, then make that change to your own Remember, this is just an example repository, trying to focus on the safest defaults. You will need to manually copy any commands you want to use, and modify them if necessary. Anyway thanks for your contribution! |
Especially because it is an example, it shouldn't have any unexpected behaviour imho. I admit I haven't thought of accidently leaking any commands, but I'll look into it, as I assume there is a better solution. |
Don't ge wrong, but doesn't the help example "leak" all commands to everyone anyway? |
I totally agree with that, but:
Yes it does, in this example! Thing is, that many users seem to just copy paste various commands from here, adjusting them only a little bit, without actually understanding certain implications. So to be safe, the default is "no-leak". If a user then wants to be able to use it in public groups, that's a very small change to make 👍 I really appreciate your thoughts on this, please do keep the ideas / suggestions / critique coming! |
Thanks for your reply 😃 I understand your concerns, of course. So, I've added an additional check that ensures that no admin commands are sent to any non-admin users (which happens atm if there aren't any admins) or groups. |
This doesn't cover the command-specific help yet. I'm gonna fix that, too. |
You'd be happy to know about the Look at the PR here: php-telegram-bot/core#580 Or are you referring to something (slightly) different? |
I don't want to make /help private_only. The result would be the same as it is now. Sending the notification into user's private chat (like private_only does), is still a bad idea. If the user hasn't started a private conversation with the bot, he'll just experience a broken-looking bot. My idea is to just hide the admin-section from the help command if the receiver is a group or a non-admin user. 😊 |
Right, now I understand, thanks for explaining! In that case, you could probably just change what you wanted to initially in this PR, from But having said that, being safe-safe is always good 👍 So go ahead and make that fix 🎉 |
I'm glad you finally got what my intention was. I should have written a more detailed opener for this PR. 🙈 Done! If you find any further issues introduced by my changes, don't hestiate to tell me ... |
Wait ... I haven't taken care of this yet: 0xEAB@daec7ea |
May I ask you for your opinion on that? 0xEAB@daec7ea#commitcomment-24075658 |
Ok, have written a response there. Let's try to keep the discussion here, to keep it easier to follow. Now, regarding your latest changes here. Have you heard about the DRY principle? If not, have a quick read to know what it's all about. Namely, I'm pointing at the new conditions you've added to the two Having said all that, it's not relevant to check if a user in an admin or not, or if it's an admin command we're busy looping through. If (s)he's an admin, the admin commands are available, no need to double check that. The only thing that needs checking, is if we're in a private or group chat. Best just check if Apart from that it looks ok to me 🎉 Hope this makes sense, otherwise I'm happy to open a PR onto your PR, to explain it better 👍 (As you may have noticed by now, I try to keep all code that's going into this project as clean and simple as possible 😇) |
Just to throw it in the room, we could also implement things like this as a command config. Maybe another time though 😁 |
Yeah, I know the DRY principle, and I admit that my changes are a bit dirty. I'll improve that. Of course, I've noticed that you care about cleaness and plainness. |
anything else to do? 🙈 |
Commands/HelpCommand.php
Outdated
@@ -39,17 +39,20 @@ class HelpCommand extends UserCommand | |||
/** | |||
* @var string | |||
*/ | |||
protected $version = '1.2.0'; | |||
protected $version = '1.2.1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for 1.3.0 here, as this isn't just a bug fix, but a nice functionality change.
Commands/HelpCommand.php
Outdated
@@ -64,7 +67,7 @@ public function execute() | |||
$data['text'] .= '/' . $user_command->getName() . ' - ' . $user_command->getDescription() . PHP_EOL; | |||
} | |||
|
|||
if (count($admin_commands) > 0) { | |||
if ((count($admin_commands) > 0) && $safe_to_show) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap these, as a boolean is quicker to evaluate. If it's not safe to show anyway, no need to count the admin commands.
Small speed improvement, because every millisecond counts 😇
(also, you can drop the parenthesis around count(...) > 0
)
@@ -77,7 +80,7 @@ public function execute() | |||
} | |||
|
|||
$command_str = str_replace('/', '', $command_str); | |||
if (isset($all_commands[$command_str])) { | |||
if (isset($all_commands[$command_str]) && ($safe_to_show || !$all_commands[$command_str]->isAdminCommand())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! Way clearer to understand what's happening here 👍
Wonderful! Thanks a lot for your contribution @0xEAB 🎉 |
You're welcome. I'm always happy when I can give something back to projects whose software I use. 😊 |
Reply was sent to sender's chat instead of the group.