Initial commit
This commit is contained in:
61
Makefile
61
Makefile
@@ -2,18 +2,71 @@
|
|||||||
|
|
||||||
GOOPTS=CGO_ENABLED=0
|
GOOPTS=CGO_ENABLED=0
|
||||||
BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l -trimpath -buildvcs=false
|
BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l -trimpath -buildvcs=false
|
||||||
|
MYNAME=bunny-bot
|
||||||
|
BINARY=$MYNAME
|
||||||
|
RMCMD=$(RM) -r
|
||||||
|
|
||||||
|
# На windows имя бинарника может зависеть не только от платформы, но и от выбранной цели, для linux-а суффикс .exe
|
||||||
|
# не нужен
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
ifeq ($(strip $(GOOS)),)
|
||||||
|
BINARY=${MYNAME}.exe
|
||||||
|
RMCMD=DEL /Q /F
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Явно определяем символ новой строки, чтобы избежать неоднозначности на windows
|
||||||
|
define IFS
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
||||||
|
|
||||||
all: clean build
|
all: clean build
|
||||||
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
${GOOPTS} go build ${BUILDOPTS} -o bunny-bot ./cmd/bunny-bot
|
# Ну и дальше просто билдим бинарник средствами гошки
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
# вариант с powershell на windows
|
||||||
|
ifeq ($(SHELL),sh.exe)
|
||||||
|
SET "CGO_ENABLED=0"
|
||||||
|
go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
else
|
||||||
|
# вариант с jetbrains golang на windows
|
||||||
|
CGO_ENABLED=0 go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
# вариант с bash/git (windows) и bash (linux)
|
||||||
|
CGO_ENABLED=0 go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bunny-bot
|
ifeq ($(OS),Windows_NT)
|
||||||
|
ifeq (,$(findstring(Git/usr/bin/sh.exe, $(SHELL))))
|
||||||
|
rm -rf ${BINARY}
|
||||||
|
else
|
||||||
|
if exist ${BINARY} ${RMCMD} ${BINARY} >nul
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
${RMCMD} ${BINARY}
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
upgrade:
|
upgrade:
|
||||||
rm -rf vendor
|
ifeq ($(OS),Windows_NT)
|
||||||
go get -u -t -tool ./...
|
# вариант с jetbrains golang на windows или powershell на windows
|
||||||
|
ifeq ($(SHELL),sh.exe)
|
||||||
|
if exist vendor del /F /S /Q vendor >nul
|
||||||
|
# вариант с git/bash на windows
|
||||||
|
else
|
||||||
|
$(RM) -r vendor
|
||||||
|
endif
|
||||||
|
# вариант с bash на linux
|
||||||
|
else
|
||||||
|
$(RM) -r vendor
|
||||||
|
endif
|
||||||
|
go get -d -u ./...
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ func leftChatMember(msg *echotron.Update) {
|
|||||||
msg.Message.Chat.ID,
|
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(
|
if err := Cfg.SaveKeyValue(
|
||||||
"LeftMembers",
|
"LeftMembers",
|
||||||
fmt.Sprintf("%d", msg.Message.Chat.ID),
|
fmt.Sprintf("%d", msg.Message.Chat.ID),
|
||||||
|
|||||||
32
internal/moon/photo.go
Normal file
32
internal/moon/photo.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
49
internal/moon/reaction.go
Normal file
49
internal/moon/reaction.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
16
internal/moon/reactionCount.go
Normal file
16
internal/moon/reactionCount.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -72,6 +72,24 @@ func telegramMsgParser(msg *echotron.Update) {
|
|||||||
return
|
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))
|
Log.Debug(spew.Sdump(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package moon
|
package moon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/NicoNex/echotron/v3"
|
"github.com/NicoNex/echotron/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,25 +37,6 @@ func textMessage(msg *echotron.Update) {
|
|||||||
msg.Message.Text,
|
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: */
|
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||||
|
|||||||
Reference in New Issue
Block a user