diff --git a/.env-example b/.env-example index 0160f93..0e14efa 100644 --- a/.env-example +++ b/.env-example @@ -16,6 +16,7 @@ TELEGRAM_VOTE_BOT_TOKEN=replace-me TELEGRAM_AUTHORIZATION_BOT_TOKEN=replace-me DISCORD_AUTHORIZATION_BOT_TOKEN=replace-me DISCORD_SERVER_ID=replace-me +DISCORD_GUEST_ROLE_ID=replace-me DISCORD_MEMBER_ROLE_ID=replace-me VOTE_API_URL=replace-me diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index cc02ed1..ac798b5 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -71,6 +71,7 @@ jobs: TELEGRAM_AUTHORIZATION_BOT_TOKEN=${{ secrets.TELEGRAM_AUTHORIZATION_BOT_TOKEN }} DISCORD_AUTHORIZATION_BOT_TOKEN=${{ secrets.DISCORD_AUTHORIZATION_BOT_TOKEN }} DISCORD_SERVER_ID=${{ secrets.DISCORD_SERVER_ID }} + DISCORD_GUEST_ROLE_ID=${{ secrets.DISCORD_GUEST_ROLE_ID }} DISCORD_MEMBER_ROLE_ID=${{ secrets.DISCORD_MEMBER_ROLE_ID }} push: true tags: ghcr.io/beniamiiin/access-governance-system:tab diff --git a/configs/config.go b/configs/config.go index 90ac6d3..b152435 100644 --- a/configs/config.go +++ b/configs/config.go @@ -79,7 +79,7 @@ func LoadTelegramAuthrozationBotConfig() (TelegramAuthrozationBotConfig, error) type DiscordAuthrozationBotConfig struct { App App Logger Logger - AuthrozationBot Bot + AuthrozationBot Discord } func LoadDiscordAuthrozationBotConfig() (DiscordAuthrozationBotConfig, error) { @@ -89,7 +89,6 @@ func LoadDiscordAuthrozationBotConfig() (DiscordAuthrozationBotConfig, error) { return DiscordAuthrozationBotConfig{}, fmt.Errorf("failed to parse config: %w", err) } - config.AuthrozationBot.Token = os.Getenv("DISCORD_AUTHORIZATION_BOT_TOKEN") config.Logger.AppName = "authorization-bot-discord" return config, nil diff --git a/configs/discord.go b/configs/discord.go index ccdc4bf..c01bfae 100644 --- a/configs/discord.go +++ b/configs/discord.go @@ -3,5 +3,6 @@ package configs type Discord struct { Token string `env:"DISCORD_AUTHORIZATION_BOT_TOKEN"` ChannelID string `env:"DISCORD_SERVER_ID"` + GuestRoleID string `env:"DISCORD_GUEST_ROLE_ID"` MemberRoleID string `env:"DISCORD_MEMBER_ROLE_ID"` } diff --git a/internal/tg_bot/commands/authorization_bot/start.go b/internal/tg_bot/commands/authorization_bot/start.go index 819ed78..b084fbf 100644 --- a/internal/tg_bot/commands/authorization_bot/start.go +++ b/internal/tg_bot/commands/authorization_bot/start.go @@ -49,7 +49,7 @@ func (c *startCommand) Handle(text, discordID string, user *models.User, chatID err := c.discord.GuildMemberRoleAdd(c.config.ChannelID, discordID, c.config.MemberRoleID) if err != nil { - c.logger.Errorw("failed to update user role", err) + c.logger.Errorw("failed to add a role", "error", err) return []tgbotapi.Chattable{extension.DefaultErrorMessage(chatID)} } @@ -65,6 +65,11 @@ func (c *startCommand) Handle(text, discordID string, user *models.User, chatID return []tgbotapi.Chattable{extension.DefaultErrorMessage(chatID)} } + err = c.discord.GuildMemberRoleRemove(c.config.ChannelID, discordID, c.config.GuestRoleID) + if err != nil { + c.logger.Warnw("failed to remove a role", "error", err) + } + message := tgbotapi.NewMessage(chatID, "Привет, ты успешно авторизован, можешь возвращаться в Discord") return []tgbotapi.Chattable{message} }