Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .envSETUP

This file was deleted.

30 changes: 30 additions & 0 deletions internal/botaccess/admincommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions internal/botaccess/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!"
)
12 changes: 12 additions & 0 deletions internal/dbaccess/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}