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

Undefined method 'reply_message' for Tourmaline::Message #64

Open
joseafga opened this issue May 26, 2023 · 0 comments
Open

Undefined method 'reply_message' for Tourmaline::Message #64

joseafga opened this issue May 26, 2023 · 0 comments

Comments

@joseafga
Copy link

When I try to use ctx.update.chats with master branch I get the following error:

In src/main.cr:6:14

 6 | ctx.update.chats do |chat|
                ^----
Error: instantiating 'Tourmaline::Update#chats()'


In lib/tourmaline/src/tourmaline/types/custom/update.cr:72:12

 72 | self.chats.each { |c| block.call(c) }
           ^----
Error: instantiating 'Tourmaline::Update#chats()'


In lib/tourmaline/src/tourmaline/types/custom/update.cr:54:30

 54 | chats.concat(message.chats) if message
                           ^----
Error: instantiating 'Tourmaline::Message#chats()'


In lib/tourmaline/src/tourmaline/types/custom/message.cr:61:31

 61 | if reply_message = self.reply_message
                              ^------------
Error: undefined method 'reply_message' for Tourmaline::Message

Did you mean 'reply_to_message'?

Tourmaline::Message trace:

  lib/tourmaline/src/tourmaline/types/custom/message.cr:61

          if reply_message = self.reply_message

How to replicate

# shard.yml
dependencies:
  tourmaline:
    github: protoncr/tourmaline
    branch: master
# src/main.cr
require "tourmaline"

client = Tourmaline::Client.new(ENV["BOT_TOKEN"])

echo_handler = Tourmaline::CommandHandler.new("echo") do |ctx|
  ctx.update.chats do |chat|
    puts chat.id
  end
end

client.register(echo_handler)

client.poll

Possible fix

As mentioned in the error itself: "Did you mean 'reply_to_message'?"
When the changed reply_message to reply_to_message, it seems to work as expected.

diff --git a/src/tourmaline/types/custom/message.cr b/src/tourmaline/types/custom/message.cr
index f0ccdf00..5e49e4e9 100644
--- a/src/tourmaline/types/custom/message.cr
+++ b/src/tourmaline/types/custom/message.cr
@@ -58,8 +58,8 @@ module Tourmaline
       chats << self.chat
       chats << self.sender_chat
       chats << self.forward_from_chat
-      if reply_message = self.reply_message
-        chats.concat(reply_message.chats)
+      if reply_to_message = self.reply_to_message
+        chats.concat(reply_to_message.chats)
       end
       chats.compact.uniq
     end
nobodywasishere added a commit to nobodywasishere/tourmaline that referenced this issue Jan 31, 2024
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

No branches or pull requests

1 participant