Initial commit
This commit is contained in:
@@ -14,3 +14,5 @@ func animation(msg *echotron.Update) {
|
||||
msg.Message.Chat.ID,
|
||||
)
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
|
||||
@@ -93,3 +93,5 @@ func CasCheckID(id int64) (bool, error) {
|
||||
|
||||
return result, fmt.Errorf("unable to parse response from api.cas.chat: %s", string(body)) //nolint: err113
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
|
||||
@@ -19,6 +19,8 @@ func leftChatMember(msg *echotron.Update) {
|
||||
msg.Message.Chat.ID,
|
||||
)
|
||||
|
||||
// Save people that left chat to pebbledb. To preserve their state.
|
||||
// TODO: Remove items on chatMemberUpdated event.
|
||||
if err := Cfg.SaveKeyValue(
|
||||
"LeftMembers",
|
||||
fmt.Sprintf("%d", msg.Message.Chat.ID),
|
||||
|
||||
34
internal/moon/photo.go
Normal file
34
internal/moon/photo.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package moon
|
||||
|
||||
import "github.com/NicoNex/echotron/v3"
|
||||
|
||||
func photo(msg *echotron.Update) {
|
||||
if msg.Message.Text != "" {
|
||||
Log.Infof(
|
||||
"User %s %s (username = %s, id = %d) sent %d photos to %s %s (%d) with text: %s",
|
||||
msg.Message.From.FirstName,
|
||||
msg.Message.From.LastName,
|
||||
msg.Message.From.Username,
|
||||
msg.Message.From.ID,
|
||||
len(msg.Message.Photo),
|
||||
msg.Message.Chat.Type,
|
||||
msg.Message.Chat.Title,
|
||||
msg.Message.Chat.ID,
|
||||
msg.Message.Text,
|
||||
)
|
||||
} else {
|
||||
Log.Infof(
|
||||
"User %s %s (username = %s, id = %d) sent %d photos to %s %s (%d)",
|
||||
msg.Message.From.FirstName,
|
||||
msg.Message.From.LastName,
|
||||
msg.Message.From.Username,
|
||||
msg.Message.From.ID,
|
||||
len(msg.Message.Photo),
|
||||
msg.Message.Chat.Type,
|
||||
msg.Message.Chat.Title,
|
||||
msg.Message.Chat.ID,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
51
internal/moon/reaction.go
Normal file
51
internal/moon/reaction.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package moon
|
||||
|
||||
import "github.com/NicoNex/echotron/v3"
|
||||
|
||||
func reaction(msg *echotron.Update) {
|
||||
var reactionString string
|
||||
|
||||
for _, item := range msg.MessageReaction.NewReaction {
|
||||
if item.Type == "Emoji" {
|
||||
reactionString += item.Emoji
|
||||
} else if item.Type == "CustomEmoji" {
|
||||
reactionString += item.CustomEmoji
|
||||
}
|
||||
}
|
||||
|
||||
if reactionString != "" {
|
||||
Log.Infof(
|
||||
"User %s %s (username = %s, id = %d) set reaction %s to chat %s %s (%d)",
|
||||
msg.MessageReaction.User.FirstName,
|
||||
msg.MessageReaction.User.LastName,
|
||||
msg.MessageReaction.User.Username,
|
||||
msg.MessageReaction.User.ID,
|
||||
reactionString,
|
||||
msg.MessageReaction.Chat.Type,
|
||||
msg.MessageReaction.Chat.Title,
|
||||
msg.MessageReaction.Chat.ID,
|
||||
)
|
||||
} else {
|
||||
for _, item := range msg.MessageReaction.OldReaction {
|
||||
if item.Type == "Emoji" {
|
||||
reactionString += item.Emoji
|
||||
} else if item.Type == "CustomEmoji" {
|
||||
reactionString += item.CustomEmoji
|
||||
}
|
||||
}
|
||||
|
||||
Log.Infof(
|
||||
"User %s %s (username = %s, id = %d) removed reaction %s to chat %s %s (%d)",
|
||||
msg.MessageReaction.User.FirstName,
|
||||
msg.MessageReaction.User.LastName,
|
||||
msg.MessageReaction.User.Username,
|
||||
msg.MessageReaction.User.ID,
|
||||
reactionString,
|
||||
msg.MessageReaction.Chat.Type,
|
||||
msg.MessageReaction.Chat.Title,
|
||||
msg.MessageReaction.Chat.ID,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
18
internal/moon/reactionCount.go
Normal file
18
internal/moon/reactionCount.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func reactionCount(msg *echotron.Update) {
|
||||
Log.Infof(
|
||||
"Reaction count event in %s %s (%d): %",
|
||||
msg.MessageReaction.Chat.Type,
|
||||
msg.MessageReaction.Chat.Title,
|
||||
msg.MessageReaction.Chat.ID,
|
||||
spew.Sdump(msg),
|
||||
)
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
@@ -91,3 +91,5 @@ func squash(chatid int64, chattype, chattitle string, userid int64, firstname, l
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
|
||||
@@ -72,6 +72,24 @@ func telegramMsgParser(msg *echotron.Update) {
|
||||
return
|
||||
}
|
||||
|
||||
if msg.MessageReaction != nil {
|
||||
reaction(msg)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if msg.MessageReactionCount != nil {
|
||||
reactionCount(msg)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if msg.Message != nil && msg.Message.Photo != nil {
|
||||
photo(msg)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Log.Debug(spew.Sdump(msg))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
@@ -40,25 +37,6 @@ func textMessage(msg *echotron.Update) {
|
||||
msg.Message.Text,
|
||||
)
|
||||
}
|
||||
|
||||
// Update database of new members :)
|
||||
// Try to get timestamp when this member joined to chat
|
||||
if joinTimestampString := Cfg.GetValue(
|
||||
"NewMembers",
|
||||
fmt.Sprintf("%d", msg.Message.Chat.ID),
|
||||
fmt.Sprintf("%d", msg.Message.From.ID),
|
||||
); joinTimestampString == "" {
|
||||
if err := Cfg.SaveKeyValue(
|
||||
"NewMembers",
|
||||
fmt.Sprintf("%d", msg.Message.Chat.ID),
|
||||
fmt.Sprintf("%d", msg.Message.From.ID),
|
||||
fmt.Sprintf("%d", time.Now().Unix()),
|
||||
); err != nil {
|
||||
Log.Error(err)
|
||||
} else {
|
||||
Log.Infof("Info about new userid %d saved to new users db", msg.Message.From.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
|
||||
Reference in New Issue
Block a user