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

Update message.go #147

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ext/handlers/filters/message/message.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package message

Check failure on line 1 in ext/handlers/filters/message/message.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters/message

import (
"fmt"
Expand Down Expand Up @@ -306,3 +306,15 @@
return TopicEdited(msg) || TopicCreated(msg) ||
TopicClosed(msg) || TopicReopened(msg)
}

func MessageEntityPre(offset int, length int, language string) filters.Filter {

Check failure on line 310 in ext/handlers/filters/message/message.go

View workflow job for this annotation

GitHub Actions / Run go tests

undefined: filters.Filter
return func(ctx *gotgbot.CallbackContext) bool {

Check failure on line 311 in ext/handlers/filters/message/message.go

View workflow job for this annotation

GitHub Actions / Run go tests

undefined: gotgbot.CallbackContext
Copy link
Owner

Choose a reason for hiding this comment

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

This type does not exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

function MessageEntityPre that takes offset, length, and language parameters. However, filters.Filter

func MessageEntityPre(offset int, length int, language string) filters.Filter {
	return func(ctx *gotgbot.CallbackContext) bool {
		return false // Placeholder return value
	}
}

Copy link
Owner

Choose a reason for hiding this comment

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

There are no such types as filter.Filter, or gotgbot.CallbackContext.

entities := ctx.Message.Entities
Copy link
Owner

Choose a reason for hiding this comment

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

This will only work on text messages, and not on media messages; that relies on message.CaptionEntities.

Copy link
Contributor Author

@TG-BOTSNETWORK TG-BOTSNETWORK Feb 18, 2024

Choose a reason for hiding this comment

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

about it only working on text messages and not media messages, yeah iam included media messages in below cod

func MessageEntityPre(offset int, length int, language string) filters.Filter {
	return func(ctx *gotgbot.CallbackContext) bool {
		var entities []*gotgbot.MessageEntity
		if ctx.Message.Text != nil {
			entities = ctx.Message.Entities
		} else if ctx.Message.CaptionEntities != nil {
			entities = ctx.Message.CaptionEntities
		} else {
			return false // Neither text nor caption entities are present
		}

		for _, entity := range entities {
			if entity.Offset == offset && entity.Length == length && entity.Language == language {
				return true
			}
		}
		return false
	}
}

Copy link
Owner

Choose a reason for hiding this comment

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

Please don't make code changes in the PR comments, make your code changes to the PR itself. I cant merge a comment :)

for _, entity := range entities {
if entity.Offset == offset && entity.Length == length && entity.Language == language {
Copy link
Owner

Choose a reason for hiding this comment

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

Do you have any example scenarios where one is able to predict both the offset and the length of an incoming message entity? I am not able to come up with one myself.

Additionally, this check is not asserting that the entity is a pre entity, as suggested by the method name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

predicting both the offset and length of an incoming message entity might not always be feasible or practical, especially in real-time scenarios. However, if you're dealing with predefined message formats or templates, you could potentially predict these values based on the structure of your messages.

Here is one example to you understand proper
Let's say you have a system where users submit code snippets in a specific format, and you know that each code snippet starts at a fixed offset and has a fixed length. In this case, you can predict the offset and length of the code snippet entity based on the message format.

However, if the offset and length need to be dynamically determined based on user input or other factors, predicting them accurately might be challenging. In such cases, it's often better to rely on other attributes or patterns in the message content rather than trying to predict specific offsets and lengths.

Regarding the method name not asserting that the entity is a pre entity, you're correct. If you want to specifically filter preformatted code entities, you should include additional checks for the entity type.

Copy link
Owner

@PaulSonOfLars PaulSonOfLars Feb 18, 2024

Choose a reason for hiding this comment

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

As you've noted yourself, this isnt feasible or practical. Which makes this function very unlikely to be used. Users that will hit the niche usecase you've mentioned can simply implement the filter themselves, to work exactly like they need.

Given this, it sounds like we agree that this PR should not be merged.

return true
}
}
return false
}
}
Loading