Initial commit
This commit is contained in:
72
Makefile
72
Makefile
@@ -2,18 +2,82 @@
|
|||||||
|
|
||||||
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 -rf
|
||||||
|
|
||||||
|
# На windows имя бинарника может зависеть не только от платформы, но и от выбранной цели, для linux-а суффикс .exe
|
||||||
|
# не нужен
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
ifdef GOOS
|
||||||
|
ifeq ($(GOOS),windows)
|
||||||
|
BINARY=${MYNAME}.exe
|
||||||
|
else # not ifeq ($(GOOS),windows)
|
||||||
|
BINARY=${MYNAME}
|
||||||
|
endif # ifeq ($(GOOS),windows)
|
||||||
|
else # not ifdef GOOS
|
||||||
|
BINARY=${MYNAME}.exe
|
||||||
|
endif # ifdef GOOS
|
||||||
|
ifeq ($(SHELL), sh.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)
|
||||||
|
# Looks like on windows gnu make explicitly set SHELL to sh.exe, if it was not set.
|
||||||
|
ifeq ($(SHELL), sh.exe)
|
||||||
|
# # Vanilla cmd.exe / powershell.
|
||||||
|
SET "CGO_ENABLED=0"
|
||||||
|
go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
else ifeq (,$(findstring(Git/usr/bin/sh.exe, $(SHELL))))
|
||||||
|
# # git-bash
|
||||||
|
CGO_ENABLED=0 go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
else # not ifeq (,$(findstring(Git/usr/bin/sh.exe, $(SHELL))))
|
||||||
|
# # Some other shell.
|
||||||
|
# # TODO: handle it.
|
||||||
|
$(info "-- Dunno how to handle this ${SHELL}")
|
||||||
|
endif # ifeq (,$(findstring(Git/usr/bin/sh.exe, $(SHELL))))
|
||||||
|
else # not ($(OS),Windows_NT)
|
||||||
|
CGO_ENABLED=0 go build ${BUILDOPTS} -o ${BINARY} ./cmd/${MYNAME}
|
||||||
|
endif # ifeq ($(OS),Windows_NT)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bunny-bot
|
ifeq ($(OS),Windows_NT)
|
||||||
|
ifeq ($(SHELL),sh.exe)
|
||||||
|
# # Vanilla cmd.exe / powershell.
|
||||||
|
if exist ${BINARY} ${RMCMD} ${BINARY}
|
||||||
|
else # not ifeq ($(SHELL),sh.exe)
|
||||||
|
${RMCMD} ./${BINARY}
|
||||||
|
endif # ifeq ($(SHELL),sh.exe)
|
||||||
|
else # not ifeq ($(OS),Windows_NT)
|
||||||
|
${RMCMD} ./${BINARY}
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
upgrade:
|
upgrade:
|
||||||
rm -rf vendor
|
ifeq ($(OS),Windows_NT)
|
||||||
go get -u -t -tool ./...
|
ifeq ($(SHELL),sh.exe)
|
||||||
|
# # Vanilla cmd.exe / powershell.
|
||||||
|
if exist vendor DEL /F /S /Q vendor >nul
|
||||||
|
else # not ifeq ($(SHELL),sh.exe)
|
||||||
|
# # git-bash
|
||||||
|
$(RM) -r vendor
|
||||||
|
endif # ifeq ($(SHELL),sh.exe)
|
||||||
|
else # not ifeq ($(OS),Windows_NT)
|
||||||
|
$(RM) -r vendor
|
||||||
|
endif
|
||||||
|
go get -d -u ./...
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
||||||
|
|
||||||
|
|||||||
@@ -14,3 +14,5 @@ func animation(msg *echotron.Update) {
|
|||||||
msg.Message.Chat.ID,
|
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
|
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,
|
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),
|
||||||
|
|||||||
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
|
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