Skip to content

Commit

Permalink
BREAKING CHANGE: fuck mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
oddyamill committed Aug 27, 2024
1 parent f755be8 commit c317bd2
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 233 deletions.
6 changes: 3 additions & 3 deletions cmd/discord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/kiasuo/bot/internal/commands"
"github.com/kiasuo/bot/internal/helpers"
"github.com/kiasuo/bot/internal/users_sql"
"github.com/kiasuo/bot/internal/users"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -45,7 +45,7 @@ func main() {
}

userID := GetUserID(interaction)
user := users_sql.GetByDiscordID(userID)
user := users.GetByDiscordID(userID)

responder := commands.DiscordResponder{
Interaction: *interaction.Interaction,
Expand All @@ -57,7 +57,7 @@ func main() {
return
}

if user.State != users_sql.Ready {
if user.State != users.Ready {
responder.Respond("Пошел нахуй.")
return
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/telegram/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/kiasuo/bot/internal/commands"
"github.com/kiasuo/bot/internal/helpers"
"github.com/kiasuo/bot/internal/users_sql"
"github.com/kiasuo/bot/internal/users"
"log"
"strings"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {

func handleMessage(update tgbotapi.Update) {
var (
user *users_sql.User
user *users.User
command string
)

Expand All @@ -56,7 +56,7 @@ func handleMessage(update tgbotapi.Update) {
return
}

user = users_sql.GetByTelegramID(update.Message.ForwardFrom.ID)
user = users.GetByTelegramID(update.Message.ForwardFrom.ID)

if user == nil {
responder.Respond("Пользователь не зарегистрирован")
Expand All @@ -65,14 +65,14 @@ func handleMessage(update tgbotapi.Update) {

command = commands.AdminCommandName
} else if update.Message.IsCommand() {
user = users_sql.GetByTelegramID(update.Message.From.ID)
user = users.GetByTelegramID(update.Message.From.ID)

if user == nil {
responder.Respond("Ты кто такой? Уйди.")
return
}

if user.State != users_sql.Ready {
if user.State != users.Ready {
responder.Respond("Пошел отсюда.")
return
}
Expand Down Expand Up @@ -101,12 +101,12 @@ func handleCallbackQuery(update tgbotapi.Update) {
return
}

var user *users_sql.User
var user *users.User

if data[0] == commands.AdminCommandName {
user = users_sql.GetByID(data[2])
user = users.GetByID(data[2])
} else {
user = users_sql.GetByTelegramID(update.CallbackQuery.From.ID)
user = users.GetByTelegramID(update.CallbackQuery.From.ID)
}

context := commands.Context{
Expand Down
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ services:
- .env
expose:
- 5432
ports:
- 5432:5432
healthcheck:
test: [ "CMD", "pg_isready", "-U", "$POSTGRES_USER" ]
interval: 10s
Expand Down
10 changes: 0 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ require (
github.com/bwmarrin/discordgo v0.28.1
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/lib/pq v1.10.9
go.mongodb.org/mongo-driver v1.16.1
)

require (
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
43 changes: 0 additions & 43 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,61 +1,18 @@
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
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/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
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=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4 changes: 2 additions & 2 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bytes"
"encoding/json"
"errors"
"github.com/kiasuo/bot/internal/users_sql"
"github.com/kiasuo/bot/internal/users"
"net/http"
)

const BaseUrl = "https://kiasuo-proxy.oddya.ru/diary"

type Client struct {
User users_sql.User
User users.User
}

func httpRequest[T any](client Client, request *http.Request) (*http.Response, *T, error) {
Expand Down
18 changes: 9 additions & 9 deletions internal/commands/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package commands

import (
"github.com/kiasuo/bot/internal/helpers"
"github.com/kiasuo/bot/internal/users_sql"
"github.com/kiasuo/bot/internal/users"
"strconv"
)

Expand All @@ -11,11 +11,11 @@ const AdminCommandName string = "-internal-admin"
func AdminCommand(context Context, responder Responder, formatter Formatter) {
user := context.User

state := map[users_sql.UserState]string{
users_sql.Unknown: "неизвестно",
users_sql.Ready: "готов",
users_sql.Pending: "ожидает",
users_sql.Blacklisted: "заблокирован",
state := map[users.UserState]string{
users.Unknown: "неизвестно",
users.Ready: "готов",
users.Pending: "ожидает",
users.Blacklisted: "заблокирован",
}[user.State]

template := formatter.Title("Панель управления") +
Expand All @@ -26,7 +26,7 @@ func AdminCommand(context Context, responder Responder, formatter Formatter) {
keyboard := Keyboard{
KeyboardRow{
KeyboardButton{
Text: helpers.If(user.State == users_sql.Blacklisted, "Разблокировать", "Заблокировать"),
Text: helpers.If(user.State == users.Blacklisted, "Разблокировать", "Заблокировать"),
Callback: AdminCommandName + ":blacklist:" + string(rune(user.ID)),
},
},
Expand All @@ -44,8 +44,8 @@ func AdminCommand(context Context, responder Responder, formatter Formatter) {
func AdminCallback(context Context, responder Responder, formatter Formatter, data []string) {
switch data[1] {
case "blacklist":
isBlacklisted := context.User.State == users_sql.Blacklisted
context.User.UpdateState(helpers.If(isBlacklisted, users_sql.Ready, users_sql.Blacklisted))
isBlacklisted := context.User.State == users.Blacklisted
context.User.UpdateState(helpers.If(isBlacklisted, users.Ready, users.Blacklisted))
default:
responder.Respond("Неизвестная команда. Меню устарело?")
return
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package commands

import (
"github.com/kiasuo/bot/internal/client"
"github.com/kiasuo/bot/internal/users_sql"
"github.com/kiasuo/bot/internal/users"
)

type Context struct {
Command string
User users_sql.User
User users.User
}

func (c Context) GetClient() client.Client {
Expand Down
Loading

0 comments on commit c317bd2

Please sign in to comment.