Fixed a bug where persitence would cause publish module failures
the build was successful Details

This commit is contained in:
Amalvy Arthur 2018-12-31 15:59:34 +01:00
parent ff91955361
commit 29add0224c
2 changed files with 15 additions and 13 deletions

1
commands/.#subscribe.go Symbolic link
View File

@ -0,0 +1 @@
aethor@pc60.home.13981:1546264820

View File

@ -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 ---")
}