Skip to content
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

(fix) Passing context #351

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Conversation

stanislavlysenko0912
Copy link
Contributor

Issue #348

Added the feature for the bot to see the context when used:

  • /chat
  • /chat "GROUP_TRIGGER_KEYWORD"
image

@stanislavlysenko0912
Copy link
Contributor Author

Perhaps an implementation with a modification of the "message_text" function would be more universal, which would unpack the command and the Prompt, but for the sake of such a function I think there is no point in modifying it

bot/telegram_bot.py Outdated Show resolved Hide resolved
@n3d1117
Copy link
Owner

n3d1117 commented Jul 2, 2023

Hey @stanislavlysenko0912, apologies for the super late reply! Thanks for opening this, just checked and I think the fix could be made even simpler. I've commented the suggestion, let me know!

@stanislavlysenko0912
Copy link
Contributor Author

stanislavlysenko0912 commented Jul 2, 2023

Hey @stanislavlysenko0912, apologies for the super late reply! Thanks for opening this, just checked and I think the fix could be made even simpler. I've commented the suggestion, let me know!

I'm sorry I answered the wrong place, just in the thread)
Anyway, I think you'll see what I mean.

I could take the time to look for another way to implement, if you want - but so far nothing comes to mind :D

Wait a bit, I'll look into it tomorrow.
Maybe I'll come up with something more interesting.

@n3d1117
Copy link
Owner

n3d1117 commented Jul 2, 2023

I'm sorry I answered the wrong place, just in the thread) Anyway, I think you'll see what I mean.

Huh? Sorry I don't get it, did you answer somewhere else?

I could take the time to look for another way to implement, if you want - but so far nothing comes to mind :D

Nothing wrong with your original PR, but could you check out the fix I suggested in the review above?

It's basically this:

if prompt.lower().startswith(trigger_keyword.lower()) or update.message.text.lower().startswith('/chat'):
      if prompt.lower().startswith(trigger_keyword.lower()):
          prompt = prompt[len(trigger_keyword):].strip()

instead of:

raw_text = update.message.text.lower()
prompt_lower = prompt.lower()
if raw_text.startswith('/chat') or prompt_lower.startswith(trigger_keyword):
    if not prompt_lower.startswith(trigger_keyword):
        prompt = f'{trigger_keyword} {prompt}'

@stanislavlysenko0912
Copy link
Contributor Author

stanislavlysenko0912 commented Jul 4, 2023

@n3d1117

Your code will be work correctly, if remove this line after condition

trigger_keyword = self.config['group_trigger_keyword']

if prompt.lower().startswith(trigger_keyword.lower()) or update.message.text.lower().startswith('/chat'):
    if prompt.lower().startswith(trigger_keyword.lower()):
        prompt = prompt[len(trigger_keyword):].strip()

    prompt = prompt[len(trigger_keyword):].strip() # delete this line, because it will be remove first symbol every time

    if update.message.reply_to_message and \
            update.message.reply_to_message.text and \
            update.message.reply_to_message.from_user.id != context.bot.id:
        prompt = f'"{update.message.reply_to_message.text}" {prompt}'

@n3d1117
Copy link
Owner

n3d1117 commented Jul 6, 2023

Thanks @stanislavlysenko0912!

@n3d1117 n3d1117 merged commit 672ab3e into n3d1117:main Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants