Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Beniamiiin committed Nov 15, 2023
1 parent c3589c1 commit 8657837
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func LoadTelegramAuthrozationBotConfig() (TelegramAuthrozationBotConfig, error)
type DiscordAuthrozationBotConfig struct {
App App
Logger Logger
AuthrozationBot Bot
AuthrozationBot Discord
}

func LoadDiscordAuthrozationBotConfig() (DiscordAuthrozationBotConfig, error) {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions configs/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
7 changes: 6 additions & 1 deletion internal/tg_bot/commands/authorization_bot/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}

Expand All @@ -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}
}

0 comments on commit 8657837

Please sign in to comment.