Skip to content

Commit

Permalink
core: Updated gotgbot to v2.0.0-rc.27 and use new GetText() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed May 28, 2024
1 parent d008920 commit 5e4f18a
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 43 deletions.
5 changes: 1 addition & 4 deletions bot/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ func (p *Processor) onMessage(b *gotgbot.Bot, ctx *ext.Context) error {
}
}

text := msg.Caption
if text == "" {
text = msg.Text
}
text := msg.GetText()

for _, plg := range p.managerService.Plugins() {
plg := plg
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.5

require (
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.25
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27
github.com/go-shiori/go-readability v0.0.0-20240204090920-819593fddc6b
github.com/go-sql-driver/mysql v1.7.1
github.com/jmoiron/sqlx v1.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.25 h1:VCZg3OsKY19PcXBRRYk2ExeZ3mC8Hm4LqcXcINuFyY4=
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.25/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU=
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27 h1:rOlGzmYC3jPVPLVLWKMiiYuePQ6MV8Cyw5qJYBoMnkY=
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27/go.mod h1:kL1v4iIjlalwm3gCYGvF4NLa3hs+aKEfRkNJvj4aoDU=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
2 changes: 1 addition & 1 deletion plugin/afk/afk.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (p *Plugin) goAFK(b *gotgbot.Bot, c plugin.GobotContext) error {
}

func (p *Plugin) checkAFK(b *gotgbot.Bot, c plugin.GobotContext) error {
if strings.HasPrefix(tgUtils.AnyText(c.EffectiveMessage), "/afk") {
if strings.HasPrefix(c.EffectiveMessage.GetText(), "/afk") {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ func (p *Plugin) onGemini(b *gotgbot.Bot, c plugin.GobotContext) error {

if tgUtils.IsReply(c.EffectiveMessage) {
photo = tgUtils.GetBestResolution(c.EffectiveMessage.ReplyToMessage.Photo)
if tgUtils.AnyText(c.EffectiveMessage.ReplyToMessage) != "" {
if c.EffectiveMessage.ReplyToMessage.GetText() != "" {
inputText.WriteString("-- ZUSÄTZLICHER KONTEXT --\n")
inputText.WriteString("Dies ist zusätzlicher Kontext. Wiederhole diesen nicht wortwörtlich!\n\n")
inputText.WriteString(fmt.Sprintf("Nachricht von %s", c.EffectiveMessage.ReplyToMessage.From.FirstName))
if c.EffectiveMessage.ReplyToMessage.From.LastName != "" {
inputText.WriteString(fmt.Sprintf(" %s", c.EffectiveMessage.ReplyToMessage.From.LastName))
}
inputText.WriteString(":\n")
inputText.WriteString(tgUtils.AnyText(c.EffectiveMessage.ReplyToMessage))
inputText.WriteString(c.EffectiveMessage.ReplyToMessage.GetText())

if c.EffectiveMessage.Quote != nil && c.EffectiveMessage.Quote.Text != "" {
inputText.WriteString("\n-- Beziehe dich nur auf folgenden Textteil: --\n")
Expand Down
10 changes: 2 additions & 8 deletions plugin/replace/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func onReplace(b *gotgbot.Bot, c plugin.GobotContext) error {
return nil
}

text := c.EffectiveMessage.ReplyToMessage.Text
if text == "" {
text = c.EffectiveMessage.ReplyToMessage.Caption
}
text := c.EffectiveMessage.ReplyToMessage.GetText()

if text == "" {
return nil
Expand Down Expand Up @@ -81,10 +78,7 @@ func onRegexReplace(b *gotgbot.Bot, c plugin.GobotContext) error {
return nil
}

text := c.EffectiveMessage.ReplyToMessage.Text
if text == "" {
text = c.EffectiveMessage.ReplyToMessage.Caption
}
text := c.EffectiveMessage.ReplyToMessage.GetText()

if text == "" {
return nil
Expand Down
27 changes: 0 additions & 27 deletions utils/tgUtils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ import (
"github.com/PaulSonOfLars/gotgbot/v2"
)

func AnyEntities(message *gotgbot.Message) []gotgbot.MessageEntity {
entities := message.Entities
if message.Entities == nil {
entities = message.CaptionEntities
}
return entities
}

func AnyText(message *gotgbot.Message) string {
text := message.Text
if message.Text == "" {
text = message.Caption
}
return text
}

func ParseAnyEntities(message *gotgbot.Message, entity *gotgbot.MessageEntity) gotgbot.ParsedMessageEntity {
switch {
case message.Text != "":
return message.ParseEntity(*entity)
case message.Caption != "":
return message.ParseCaptionEntity(*entity)
default:
return gotgbot.ParsedMessageEntity{}
}
}

// ParseAnyEntityTypes is a simplied version of ParseEntityTypes that accepts a slice instead of a map for entites types
// that should be parsed. It also uses caption entites when they exist.
func ParseAnyEntityTypes(message *gotgbot.Message, only []EntityType) []gotgbot.ParsedMessageEntity {
Expand Down

0 comments on commit 5e4f18a

Please sign in to comment.