diff --git a/commands/.#subscribe.go b/commands/.#subscribe.go new file mode 120000 index 0000000..a0892a2 --- /dev/null +++ b/commands/.#subscribe.go @@ -0,0 +1 @@ +aethor@pc60.home.13981:1546264820 \ No newline at end of file diff --git a/commands/subscribe.go b/commands/subscribe.go index 01cc5dd..25a92ad 100644 --- a/commands/subscribe.go +++ b/commands/subscribe.go @@ -6,11 +6,12 @@ // It consists of a list of chatID as a string, chatID are separated by ":" (unix PATH style) // This module uses a property named "saved_messages" in the shared Chats structure -// It consists of a list of string +// It consists of a slice of string package commands import ( + "fmt" "strconv" "strings" @@ -99,7 +100,8 @@ func Publish(m *tb.Message) { return } shared.ChatData.Set(m.Chat.ID, "published_messages", - append(savedMessages.([]string), m.ReplyTo.Text)) + append(savedMessages.([]interface{}), m.ReplyTo.Text)) + } // Remove a message from published messages in the current chat @@ -116,16 +118,16 @@ func Unpublish(m *tb.Message) { return } savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "published_messages") - if !exists || len(savedMessages.([]string)) == 0 { + if !exists || len(savedMessages.([]interface{})) == 0 { shared.Bot.Send(m.Chat, "Aucun message publié") return } - if len(savedMessages.([]string)) <= index || index < 0 { + if len(savedMessages.([]interface{})) <= index || index < 0 { shared.Bot.Send(m.Chat, "Aucun message avec cet ID de publication n'existe") return } - savedMessages = append(savedMessages.([]string)[:index], savedMessages.([]string)[index+1:]...) - shared.ChatData.Set(m.Chat.ID, "published_messages", savedMessages.([]string)) + savedMessages = append(savedMessages.([]interface{})[:index], savedMessages.([]interface{})[index+1:]...) + shared.ChatData.Set(m.Chat.ID, "published_messages", savedMessages) shared.Bot.Send(m.Chat, "Message supprimé des publication") } @@ -135,20 +137,19 @@ func Unpublish(m *tb.Message) { func Retrieve(m *tb.Message) { if m.Chat.Type == "group" || m.Chat.Type == "supergroup" { savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "published_messages") - if !exists || len(savedMessages.([]string)) == 0 { + fmt.Println(savedMessages) + if !exists || len(savedMessages.([]interface{})) == 0 { shared.Bot.Send(m.Chat, "Aucun message publié") return } shared.Bot.Send(m.Chat, "--- Messages publiés ---") - for index, message := range savedMessages.([]string) { - shared.Bot.Send(m.Chat, strconv.Itoa(index)+" : "+message) + 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 } if m.Chat.Type == "private" { - // get subscribed sources - // get messages from those sources userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats") if !exists || len(userSubscribedChats) == 0 { shared.Bot.Send(m.Chat, "Aucun abonnement") @@ -158,8 +159,8 @@ func Retrieve(m *tb.Message) { chatID, _ := strconv.ParseInt(chat, 10, 64) savedMessages, _ := shared.ChatData.Get(chatID, "published_messages") shared.Bot.Send(m.Chat, "--- Messages publiés ---") - for index, message := range savedMessages.([]string) { - shared.Bot.Send(m.Chat, strconv.Itoa(index)+" : "+message) + for index, message := range savedMessages.([]interface{}) { + shared.Bot.Send(m.Chat, strconv.Itoa(index)+" : "+message.(string)) } shared.Bot.Send(m.Chat, "--- Messages publiés ---") }