-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added finals as a new game or voting
- Loading branch information
d.pikaliuk
committed
Feb 23, 2024
1 parent
e9f3f7c
commit 8f2df66
Showing
9 changed files
with
151 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package listener | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
) | ||
|
||
func (rcv *InstaBotService) cmdLetsPlayFinalsHandler(update tgbotapi.Update) { | ||
chatID := update.Message.Chat.ID | ||
|
||
args := strings.Fields(update.Message.CommandArguments()) | ||
|
||
var timeToPlay string | ||
if len(args) != 0 { | ||
_, err := time.Parse("15:04", args[0]) | ||
if err == nil { | ||
timeToPlay = args[0] | ||
} | ||
} | ||
|
||
// ---> Check if chat is registered not to spam in usual chats | ||
chatRegistered, err := rcv.storage.ChatExists(FinalsContext, chatID) | ||
if err != nil { | ||
rcv.SendError(chatID, ErrInternalServerError) | ||
rcv.log.WithError(err).Error("[cmdLetsPlayFinalsHandler] get chat exists") | ||
return | ||
} | ||
if !chatRegistered { | ||
rcv.SendError(chatID, ErrNoFinalsPlayers) | ||
return | ||
} | ||
|
||
members, err := rcv.storage.GetChatMembers(FinalsContext, chatID) | ||
if err != nil { | ||
rcv.SendError(chatID, ErrInternalServerError) | ||
rcv.log.WithError(err).Error("[cmdLetsPlayFinalsHandler] get chat members") | ||
return | ||
} | ||
|
||
if len(members) == 0 { | ||
rcv.SendError(chatID, ErrNoFinalsPlayers) | ||
return | ||
} | ||
|
||
var message string | ||
for _, m := range members { | ||
message += fmt.Sprintf("@%s ", m) | ||
} | ||
|
||
var voteCaption = "Галасаваніє!" | ||
|
||
if timeToPlay != "" { | ||
voteCaption = fmt.Sprintf("%s The Finals в %s?", voteCaption, timeToPlay) | ||
message += fmt.Sprintf("\nХто буде в The Finals в %s? Галасуєм!", timeToPlay) | ||
} else { | ||
message += "\nХто буде в The Finals? Галасуєм!" | ||
} | ||
message = strings.ReplaceAll(message, "_", "\\_") | ||
|
||
if err := rcv.SendMessageWithoutMarkdown(chatID, message); err != nil { | ||
logrus.WithError(err).Println("[cmdLetsPlayFinalsHandler] send message to chat") | ||
} | ||
|
||
options := []string{ | ||
"(+) Звичайно, я справжній козак!", | ||
"(-) Нііі, ні я не ту кохав, не ті слова..., в общем лох я!", | ||
} | ||
|
||
_, err = rcv.CreatePoll(chatID, voteCaption, false, options...) | ||
if err != nil { | ||
logrus.WithError(err).Println("[cmdLetsPlayFinalsHandler] create poll to chat") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package listener | ||
|
||
import ( | ||
"github.com/haski007/insta-bot/pkg/emoji" | ||
"github.com/sirupsen/logrus" | ||
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
) | ||
|
||
func (rcv *InstaBotService) cmdPurgeFinalsPlayersHandler(update tgbotapi.Update) { | ||
chatID := update.Message.Chat.ID | ||
|
||
if err := rcv.storage.DeleteChat(FinalsContext, chatID); err != nil { | ||
rcv.SendError(chatID, ErrInternalServerError) | ||
rcv.log.WithError(err).Error("[cmdPurgeFinalsPlayersHandler] delete finals chat with members") | ||
return | ||
} | ||
|
||
message := "Successfully deleted stopped to listen The Finals triggers " | ||
if err := rcv.SendMessage(chatID, message+emoji.Basket); err != nil { | ||
logrus.WithError(err).Println("[cmdPurgeFinalsPlayersHandler] send message to chat") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package listener | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/haski007/insta-bot/pkg/emoji" | ||
"github.com/sirupsen/logrus" | ||
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
) | ||
|
||
func (rcv *InstaBotService) cmdRegFinalsPlayersHandler(update tgbotapi.Update) { | ||
chatID := update.Message.Chat.ID | ||
|
||
members := strings.Fields(update.Message.CommandArguments()) | ||
if len(members) == 0 { | ||
rcv.SendError(chatID, ErrNoArguments) | ||
return | ||
} | ||
|
||
if err := rcv.storage.AddChatWithMembers(FinalsContext, chatID, members); err != nil { | ||
rcv.SendError(chatID, ErrInternalServerError) | ||
rcv.log.WithError(err).Error("[cmdRegFinalsPlayersHandler] add chat with members") | ||
return | ||
} | ||
|
||
message := fmt.Sprintf("Added listener of CSGO triggers for *%d* users ", len(members)) | ||
if err := rcv.SendMessage(chatID, message+emoji.Check); err != nil { | ||
logrus.WithError(err).Println("[cmdRegFinalsPlayersHandler] send message to chat") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters