diff --git a/.envSETUP b/.envSETUP deleted file mode 100644 index 0ac1ef5..0000000 --- a/.envSETUP +++ /dev/null @@ -1,12 +0,0 @@ -BOT_TOKEN=(your bot API here) -RESET_DB=(boolean: wipes data regarding the queue bot if needed - 'true' during testing to clear junk data, 'false' otherwise.) -BASE_ADMIN_ACCOUNT=(place the person that is to be the first admin of the bot. If your handle is @abc, type abc without the @.) - -# Postgres access details -## named to allow remote deployment override -# see https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables -POSTGRES_USER=postgres -POSTGRES_DB=postgres -POSTGRES_PASSWORD=postgres -PGHOST=localhost -PGPORT=5432 \ No newline at end of file diff --git a/internal/botaccess/admincommands.go b/internal/botaccess/admincommands.go index 91625c1..e55eb5a 100644 --- a/internal/botaccess/admincommands.go +++ b/internal/botaccess/admincommands.go @@ -76,6 +76,36 @@ var AdminCommands = []types.AcceptedCommands{ Description: "Explains the main functionalities of the bot.", Handler: AdminHelpCommand, }, + { + Command: "delay", + Description: "Notifies users of a delay", + Handler: DelayCommand, + }, +} + +func DelayCommand(userMessage tgbotapi.Update, bot *tgbotapi.BotAPI) (feedback string) { + queueUsers, err := dbaccess.DelayQueue() + + if err != nil { + feedback = delayQueueFeedback + log.Printf("Error sending message %v\n", err) + return feedback + } + + for _, user := range queueUsers { + telegramHandle := user.UserHandle + msg := tgbotapi.NewMessage(user.ChatID, delayQueueFeedback) + _, err = bot.Send(msg) + + if err != nil { + feedback = "You failed to send delay message to " + telegramHandle + " : " + err.Error() + log.Printf("Error sending message to @%s", telegramHandle) + return feedback + } + } + + feedback = "Delay message sent to all users." + return feedback } func AddDummyCommand(userMessage tgbotapi.Update, bot *tgbotapi.BotAPI) (feedback string) { diff --git a/internal/botaccess/settings.go b/internal/botaccess/settings.go index a1cb220..0671c55 100644 --- a/internal/botaccess/settings.go +++ b/internal/botaccess/settings.go @@ -38,6 +38,8 @@ const ( /help - view all available functions for this bot. + /delay - send a delay message to all users. + Bot controls (users): /join - join the photobooth queue. @@ -105,4 +107,5 @@ const ( thirdInQueueFeedback string = "2 groups left in front of you - please head down to the photobooth!" kickedFromQueueFeedback string = "You have been kicked from the queue." + delayQueueFeedback string = "We are experiencing some delay. Thank you for being patient!" ) diff --git a/internal/dbaccess/queue.go b/internal/dbaccess/queue.go index 41e66d9..574f36a 100644 --- a/internal/dbaccess/queue.go +++ b/internal/dbaccess/queue.go @@ -103,3 +103,15 @@ func NotifyQueue(position int64) (chatID int64, err error) { return user.ChatID, nil } + +func DelayQueue() ([]types.QueueUser, error) { + queue := []types.QueueUser{} + if err := db.Select(&queue, ` + SELECT + queue_id, user_handle, chat_id, (joined_at AT TIME ZONE 'UTC-8') AS joined_at + FROM queue;`); err != nil { + return nil, fmt.Errorf("failed to get users. %v", err) + } + + return queue, nil +}