diff --git a/discord/commands/chat/sendpost.go b/discord/commands/chat/sendpost.go index 6d7e8b4..1742a15 100644 --- a/discord/commands/chat/sendpost.go +++ b/discord/commands/chat/sendpost.go @@ -47,13 +47,17 @@ func (h *SendPostHandler) Handler(s *discordgo.Session, i *discordgo.Interaction err := getPostData(&data, vk) if err != nil { log.Warnf("Error getting post data: %s", err) - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "Error getting post data", Flags: discordgo.MessageFlagsEphemeral, }, }) + if err != nil { + log.Warnf("Error sending message: %s", err) + return + } return } embed := &discordgo.MessageEmbed{ @@ -70,17 +74,21 @@ func (h *SendPostHandler) Handler(s *discordgo.Session, i *discordgo.Interaction } _, err = s.ChannelMessageSendEmbed(i.ChannelID, embed) if err != nil { - log.Warnf("Error sending message: %s", err) + log.Warnf("Error sending discord message: %s", err) return } - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: "Done!", Flags: discordgo.MessageFlagsEphemeral, }, }) + if err != nil { + log.Warnf("Error sending discord message: %s", err) + return + } } func getPostData(data *PostData, vk *api.VK) error { @@ -109,7 +117,7 @@ func getPostData(data *PostData, vk *api.VK) error { log.Fatalf("Error getting group: %s", err) } - text := utils.SortTags(post[0].Text, int(post[0].OwnerID)) + text := utils.SortTags(post[0].Text, post[0].OwnerID) data.Author = group[0].Name data.IconURL = group[0].Photo200 data.Text = text diff --git a/discord/events/bot/ready.go b/discord/events/bot/ready.go index 9a360f3..17cdc0d 100644 --- a/discord/events/bot/ready.go +++ b/discord/events/bot/ready.go @@ -7,7 +7,7 @@ import ( ) func OnReady(d *discordgo.Session, event *discordgo.Ready) { - d.UpdateStatusComplex(discordgo.UpdateStatusData{ + err := d.UpdateStatusComplex(discordgo.UpdateStatusData{ Activities: []*discordgo.Activity{ { Name: "Киберспорт РТУ МИРЭА", @@ -16,5 +16,9 @@ func OnReady(d *discordgo.Session, event *discordgo.Ready) { }, }, }) + if err != nil { + log.Fatalf("Error updating discord status: %s", err) + return + } log.Printf("Discord bot %s is ready!", event.User.String()) } diff --git a/discord/main.go b/discord/main.go index 219ffa6..6c54bb1 100644 --- a/discord/main.go +++ b/discord/main.go @@ -36,10 +36,6 @@ func Init() *discordgo.Session { registerCommandHandlers(discord, commands.CommandHandlers) - if err != nil { - log.Fatalf("error creating slash commands: %v", err) - } - return discord } @@ -73,7 +69,6 @@ func registerCommandHandlers(s *discordgo.Session, commandHandlers []commands.Co _, err := s.ApplicationCommandCreate(s.State.User.ID, "", cmd) if err != nil { log.Fatalf("error creating command %s: %v", cmd.Name, err) - continue } } s.AddHandler(func(dg *discordgo.Session, i *discordgo.InteractionCreate) { @@ -86,5 +81,4 @@ func registerCommandHandlers(s *discordgo.Session, commandHandlers []commands.Co } } }) - } diff --git a/go.mod b/go.mod index 765cad3..eff6456 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.21.0 require ( github.com/SevereCloud/vksdk/v2 v2.16.1 - github.com/bwmarrin/discordgo v0.27.1 - github.com/dlclark/regexp2 v1.10.0 + github.com/bwmarrin/discordgo v0.28.1 + github.com/dlclark/regexp2 v1.11.0 github.com/joho/godotenv v1.5.1 ) @@ -15,7 +15,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/vmihailenco/msgpack/v5 v5.4.0 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index c0ae596..1cefc04 100644 --- a/go.sum +++ b/go.sum @@ -2,11 +2,15 @@ github.com/SevereCloud/vksdk/v2 v2.16.1 h1:UiazL3vTy7lMm33oIXRMxXg8S5I8bQuqEdLtb github.com/SevereCloud/vksdk/v2 v2.16.1/go.mod h1:UfVcBt8qh5+gIflQO6L+CWwrXcpwhOl5hKvKf8sXUd8= github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY= github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4= +github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -28,15 +32,21 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index e13d1d5..799b5db 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { defer discordbot.Close() vkbot.WallPostNew(func(ctx context.Context, obj events.WallPostNewObject) { - sortedtext := utils.SortTags(string(obj.Text), int(obj.OwnerID)) + sortedtext := utils.SortTags(obj.Text, obj.OwnerID) group, err := vkbot.VK.GroupsGetByID(api.Params{"group_id": -obj.OwnerID}) if err != nil { log.Fatalf("Error getting group name: %s", err) diff --git a/utils/log.go b/utils/log.go index e0cfd14..430cc24 100644 --- a/utils/log.go +++ b/utils/log.go @@ -49,3 +49,7 @@ func (l *CustomLogger) Errorf(format string, args ...interface{}) { func (l *CustomLogger) Warnf(format string, args ...interface{}) { l.Entry.Warnf(format, args...) } + +func (l *CustomLogger) Fatalf(format string, args ...interface{}) { + l.Entry.Fatalf(format, args...) +}