mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 10:36:44 +01:00
Simplify Retrieve function
This commit is contained in:
parent
a47c016c62
commit
e9b3dabd10
@ -22,7 +22,7 @@ import (
|
|||||||
// Subscribe user sending the command to the current chat
|
// Subscribe user sending the command to the current chat
|
||||||
// Command syntax : /subscribe
|
// Command syntax : /subscribe
|
||||||
func Subscribe(m *tb.Message) {
|
func Subscribe(m *tb.Message) {
|
||||||
if m.Chat.Type != "group" && m.Chat.Type != "supergroup" {
|
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup {
|
||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func Subscribe(m *tb.Message) {
|
|||||||
// Unsubscribe user sending the command from the current chat
|
// Unsubscribe user sending the command from the current chat
|
||||||
// Command syntax : /unsubscribe
|
// Command syntax : /unsubscribe
|
||||||
func Unsubscribe(m *tb.Message) {
|
func Unsubscribe(m *tb.Message) {
|
||||||
if m.Chat.Type != "group" && m.Chat.Type != "supergroup" {
|
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup {
|
||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func Unsubscribe(m *tb.Message) {
|
|||||||
// ListSubscribers List all subscribers of the current chat
|
// ListSubscribers List all subscribers of the current chat
|
||||||
// Command syntax : /listsubscribers
|
// Command syntax : /listsubscribers
|
||||||
func ListSubscribers(m *tb.Message) {
|
func ListSubscribers(m *tb.Message) {
|
||||||
if m.Chat.Type != "group" && m.Chat.Type != "supergroup" {
|
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup {
|
||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -99,8 +99,11 @@ func Publish(m *tb.Message) {
|
|||||||
shared.ChatData.Set(m.Chat.ID, "published_messages", messageList)
|
shared.ChatData.Set(m.Chat.ID, "published_messages", messageList)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
shared.ChatData.Set(m.Chat.ID, "published_messages",
|
shared.ChatData.Set(
|
||||||
append(savedMessages.([]interface{}), m.ReplyTo.Text))
|
m.Chat.ID,
|
||||||
|
"published_messages",
|
||||||
|
append(savedMessages.([]interface{}), m.ReplyTo.Text),
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,38 +138,55 @@ func Unpublish(m *tb.Message) {
|
|||||||
// If performed in Group Chat : retrieved all published messages for this chat
|
// If performed in Group Chat : retrieved all published messages for this chat
|
||||||
// Command syntax : /retrieve
|
// Command syntax : /retrieve
|
||||||
func Retrieve(m *tb.Message) {
|
func Retrieve(m *tb.Message) {
|
||||||
if m.Chat.Type == "group" || m.Chat.Type == "supergroup" {
|
chatList := []int64{}
|
||||||
savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "published_messages")
|
messageList := []string{}
|
||||||
fmt.Println(savedMessages)
|
|
||||||
if !exists || len(savedMessages.([]interface{})) == 0 {
|
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup && m.Chat.Type != tb.ChatPrivate {
|
||||||
shared.Bot.Send(m.Chat, "Aucun message publié")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
||||||
return
|
|
||||||
}
|
|
||||||
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
|
||||||
for index, message := range savedMessages.([]interface{}) {
|
|
||||||
shared.Bot.Send(m.Chat, strconv.Itoa(index)+" : "+message.(string))
|
|
||||||
}
|
|
||||||
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Chat.Type == "private" {
|
|
||||||
|
if m.Chat.Type == tb.ChatPrivate {
|
||||||
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
||||||
if !exists || len(userSubscribedChats) == 0 {
|
if !exists || len(userSubscribedChats) == 0 {
|
||||||
shared.Bot.Send(m.Chat, "Aucun abonnement")
|
shared.Bot.Send(m.Chat, "Aucun abonnements")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, chat := range strings.Split(userSubscribedChats, ":") {
|
for _, chat := range strings.Split(userSubscribedChats, ":") {
|
||||||
chatID, _ := strconv.ParseInt(chat, 10, 64)
|
chatID, err := strconv.ParseInt(chat, 10, 64)
|
||||||
savedMessages, _ := shared.ChatData.Get(chatID, "published_messages")
|
if err != nil {
|
||||||
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
shared.Bot.Send(m.Chat, "Erreur lors de la récupération de vos évènements")
|
||||||
for index, message := range savedMessages.([]interface{}) {
|
return
|
||||||
shared.Bot.Send(m.Chat, strconv.Itoa(index)+" : "+message.(string))
|
|
||||||
}
|
}
|
||||||
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
chatList = append(chatList, chatID)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.Chat.Type == tb.ChatGroup || m.Chat.Type == tb.ChatSuperGroup {
|
||||||
|
chatList = append(chatList, m.Chat.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, chatID := range chatList {
|
||||||
|
if savedMessages, exists := shared.ChatData.Get(chatID, "published_messages"); exists {
|
||||||
|
for _, message := range savedMessages.([]interface{}) {
|
||||||
|
if message, ok := message.(string); ok {
|
||||||
|
messageList = append(messageList, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(messageList) == 0 {
|
||||||
|
shared.Bot.Send(m.Chat, "Aucun message publié")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
|
||||||
|
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
||||||
|
for index, message := range messageList {
|
||||||
|
shared.Bot.Send(m.Chat, fmt.Sprintf("%d : %s", index, message))
|
||||||
|
}
|
||||||
|
shared.Bot.Send(m.Chat, "--- Messages publiés ---")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all users subscribed to the provided channel
|
// Get all users subscribed to the provided channel
|
||||||
|
Loading…
Reference in New Issue
Block a user