From dea2b4cfb44674466d0ec7263976ef436bc6caa8 Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Sun, 30 Dec 2018 19:31:56 +0100 Subject: [PATCH 1/6] Basic save feature --- .gitignore | 5 ++++- alfred.go | 3 +++ commands/save.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 commands/save.go diff --git a/.gitignore b/.gitignore index eb5b34a..9a15d12 100644 --- a/.gitignore +++ b/.gitignore @@ -11,10 +11,13 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +#swap files +*~ + # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ settings_custom.json history.json users.json -chat_data.json \ No newline at end of file +chat_data.json diff --git a/alfred.go b/alfred.go index a52b950..6980b59 100644 --- a/alfred.go +++ b/alfred.go @@ -32,6 +32,8 @@ func main() { "/chaos": commands.TwitterSJW, "/apero": commands.AperoTime, "/quote": commands.Quote, + "/save": commands.Save, + "/getsaved": commands.GetSaved, } if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil { @@ -61,6 +63,7 @@ func main() { b.Handle(key, value) } + log.Println("token : " + settings.Settings["token"].(string)) log.Println("Starting bot") b.Start() } diff --git a/commands/save.go b/commands/save.go new file mode 100644 index 0000000..914859d --- /dev/null +++ b/commands/save.go @@ -0,0 +1,42 @@ +/* +* @Author: Amalvy Arthur + */ + +package commands + +import ( + "log" + + "../shared" + tb "gopkg.in/tucnak/telebot.v2" +) + +func Save(m *tb.Message) { + if m.ReplyTo == nil { + shared.Bot.Send(m.Chat, "Please reply to a message to save it") + return + } + + defer shared.Bot.Send(m.Chat, "Message sauvegardé : "+m.ReplyTo.Text) + savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages") + if !exists { + log.Println("no messages yet") + messageList := []string{m.ReplyTo.Text} + shared.ChatData.Set(m.Chat.ID, "saved_messages", messageList) + return + } + log.Println(append(savedMessages.([]string), m.ReplyTo.Text)) + shared.ChatData.Set(m.Chat.ID, "saved_messages", + append(savedMessages.([]string), m.ReplyTo.Text)) +} + +func GetSaved(m *tb.Message) { + if _, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages"); !exists { + shared.Bot.Send(m.Chat, "Aucun message sauvegardé") + } + shared.Bot.Send(m.Chat, "Some messages exists") + savedMessages, _ := shared.ChatData.Get(m.Chat.ID, "saved_messages") + for _, message := range savedMessages.([]string) { + shared.Bot.Send(m.Chat, "message : "+message) + } +} From ef2866e89b851add242e19e392dfedd203c60388 Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Mon, 31 Dec 2018 00:48:46 +0100 Subject: [PATCH 2/6] Added basic subscribe and unsubscribe --- alfred.go | 34 ++++++++------ commands/save.go | 42 ----------------- commands/subscribe.go | 106 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 57 deletions(-) delete mode 100644 commands/save.go create mode 100644 commands/subscribe.go diff --git a/alfred.go b/alfred.go index 6980b59..383d165 100644 --- a/alfred.go +++ b/alfred.go @@ -19,21 +19,25 @@ import ( func main() { registeredCommands := map[string]func(*tb.Message){ - tb.OnText: commands.OnText, - "/hello": commands.Hello, - "/sponge": commands.Sponge, - "/git": commands.Git, - "/framapad": commands.Framapad, - "/setgender": commands.SetGender, - "/gender": commands.Gender, - "/roll": commands.Dice, - "/trump": commands.LastTrumpTweet, - "/trends": commands.TwitterTrends, - "/chaos": commands.TwitterSJW, - "/apero": commands.AperoTime, - "/quote": commands.Quote, - "/save": commands.Save, - "/getsaved": commands.GetSaved, + tb.OnText: commands.OnText, + "/hello": commands.Hello, + "/sponge": commands.Sponge, + "/git": commands.Git, + "/framapad": commands.Framapad, + "/setgender": commands.SetGender, + "/gender": commands.Gender, + "/roll": commands.Dice, + "/trump": commands.LastTrumpTweet, + "/trends": commands.TwitterTrends, + "/chaos": commands.TwitterSJW, + "/apero": commands.AperoTime, + "/quote": commands.Quote, + "/subscribe": commands.Subscribe, + "/unsubscribe": commands.Unsubscribe, + "/listsubscribers": commands.ListSubscribers, + "/publish": commands.Publish, + "/unpublish": commands.Unpublish, + "/retrieve": commands.Retrieve, } if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil { diff --git a/commands/save.go b/commands/save.go deleted file mode 100644 index 914859d..0000000 --- a/commands/save.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @Author: Amalvy Arthur - */ - -package commands - -import ( - "log" - - "../shared" - tb "gopkg.in/tucnak/telebot.v2" -) - -func Save(m *tb.Message) { - if m.ReplyTo == nil { - shared.Bot.Send(m.Chat, "Please reply to a message to save it") - return - } - - defer shared.Bot.Send(m.Chat, "Message sauvegardé : "+m.ReplyTo.Text) - savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages") - if !exists { - log.Println("no messages yet") - messageList := []string{m.ReplyTo.Text} - shared.ChatData.Set(m.Chat.ID, "saved_messages", messageList) - return - } - log.Println(append(savedMessages.([]string), m.ReplyTo.Text)) - shared.ChatData.Set(m.Chat.ID, "saved_messages", - append(savedMessages.([]string), m.ReplyTo.Text)) -} - -func GetSaved(m *tb.Message) { - if _, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages"); !exists { - shared.Bot.Send(m.Chat, "Aucun message sauvegardé") - } - shared.Bot.Send(m.Chat, "Some messages exists") - savedMessages, _ := shared.ChatData.Get(m.Chat.ID, "saved_messages") - for _, message := range savedMessages.([]string) { - shared.Bot.Send(m.Chat, "message : "+message) - } -} diff --git a/commands/subscribe.go b/commands/subscribe.go new file mode 100644 index 0000000..fd08195 --- /dev/null +++ b/commands/subscribe.go @@ -0,0 +1,106 @@ +/* +* @Author: Amalvy Arthur + */ + +// This module use a property named "subscribed_chats" in the shared Users structure. +// It consists of a list of chatID as a string, chatID are separated by ":" (unix PATH style) + +package commands + +import ( + "strconv" + "strings" + + "../shared" + tb "gopkg.in/tucnak/telebot.v2" +) + +// Subscribe user sending the command to the current chat +// Command syntax : /subscribe +func Subscribe(m *tb.Message) { + if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { + shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat") + return + } + userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats") + if !exists { + shared.Bot.Send(m.Chat, "Abonnement au chat : "+m.Chat.Title) + shared.Users.Set(m.Sender.Username, "subscribed_chats", strconv.FormatInt(m.Chat.ID, 10)) + return + } + splittedChats := strings.Split(userSubscribedChats, ":") + for _, chatID := range splittedChats { + if chatID == strconv.FormatInt(m.Chat.ID, 10) { + shared.Bot.Send(m.Chat, "Vous êtes déjà abonné à ce chat : "+m.Chat.Title) + return + } + } + shared.Bot.Send(m.Chat, "Abonnement au chat : "+m.Chat.Title) + if len(userSubscribedChats) != 0 { + shared.Users.Set(m.Sender.Username, "subscribed_chats", userSubscribedChats+":"+strconv.FormatInt(m.Chat.ID, 10)) + } else { + shared.Users.Set(m.Sender.Username, "subscribed_chats", strconv.FormatInt(m.Chat.ID, 10)) + } +} + +// Unsubscribe user sending the command from the current chat +// Command syntax : /unsubscribe +func Unsubscribe(m *tb.Message) { + if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { + shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat") + return + } + userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats") + if !exists || len(userSubscribedChats) == 0 { + shared.Bot.Send(m.Chat, "Vous n'êtes abonné à aucun chat") + return + } + splittedChats := strings.Split(userSubscribedChats, ":") + for i, chatID := range splittedChats { + if chatID == strconv.FormatInt(m.Chat.ID, 10) { + shared.Bot.Send(m.Chat, "désabonnement du chat : "+m.Chat.Title) + splittedChats = append(splittedChats[:i], splittedChats[i+1:]...) + break + } + } + shared.Users.Set(m.Sender.Username, "subscribed_chats", strings.Join(splittedChats, ":")) +} + +func ListSubscribers(m *tb.Message) { + // if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { + // shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat") + // return + // } +} + +func Publish(m *tb.Message) { + if m.ReplyTo == nil { + shared.Bot.Send(m.Chat, "Please reply to a message to save it") + return + } + + defer shared.Bot.Send(m.Chat, "Message publié : "+m.ReplyTo.Text) + savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages") + if !exists { + messageList := []string{m.ReplyTo.Text} + shared.ChatData.Set(m.Chat.ID, "saved_messages", messageList) + return + } + shared.ChatData.Set(m.Chat.ID, "saved_messages", + append(savedMessages.([]string), m.ReplyTo.Text)) +} + +func Unpublish(m *tb.Message) { + +} + +func Retrieve(m *tb.Message) { + if _, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages"); !exists { + shared.Bot.Send(m.Chat, "Aucun message sauvegardé") + return + } + savedMessages, _ := shared.ChatData.Get(m.Chat.ID, "saved_messages") + for _, message := range savedMessages.([]string) { + shared.Bot.Send(m.Chat, "message : "+message) + } +} From ff91955361c4066a533302b6458deaf93b02ce27 Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Mon, 31 Dec 2018 02:46:05 +0100 Subject: [PATCH 3/6] Added ListSubscriber, Unpublish and Retrieve commands --- commands/subscribe.go | 116 +++++++++++++++++++++++++++++++++++------- shared/users.go | 11 ++++ 2 files changed, 109 insertions(+), 18 deletions(-) diff --git a/commands/subscribe.go b/commands/subscribe.go index fd08195..01cc5dd 100644 --- a/commands/subscribe.go +++ b/commands/subscribe.go @@ -2,9 +2,12 @@ * @Author: Amalvy Arthur */ -// This module use a property named "subscribed_chats" in the shared Users structure. +// This module uses a property named "subscribed_chats" in the shared Users structure. // 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 + package commands import ( @@ -66,41 +69,118 @@ func Unsubscribe(m *tb.Message) { shared.Users.Set(m.Sender.Username, "subscribed_chats", strings.Join(splittedChats, ":")) } +// List all subscribers of the current chat +// Command syntax : /listsubscribers func ListSubscribers(m *tb.Message) { - // if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { - // shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat") - // return - // } + if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { + shared.Bot.Send(m.Chat, "Cette commande n'est pas authorisée pour ce type de chat") + return + } + subscribers := m.Chat.Title + " subscribers : \n\n" + for _, subscriber := range getSubscribers(m.Chat.ID) { + subscribers = subscribers + "- " + subscriber + "\n" + } + shared.Bot.Send(m.Chat, subscribers) } +// Publish a message from the current chat +// Command syntax (while repying to a message) : /publish func Publish(m *tb.Message) { if m.ReplyTo == nil { - shared.Bot.Send(m.Chat, "Please reply to a message to save it") + shared.Bot.Send(m.Chat, "Veuillez répondre à un message pour le publier") return } defer shared.Bot.Send(m.Chat, "Message publié : "+m.ReplyTo.Text) - savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages") + savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "published_messages") if !exists { messageList := []string{m.ReplyTo.Text} - shared.ChatData.Set(m.Chat.ID, "saved_messages", messageList) + shared.ChatData.Set(m.Chat.ID, "published_messages", messageList) return } - shared.ChatData.Set(m.Chat.ID, "saved_messages", + shared.ChatData.Set(m.Chat.ID, "published_messages", append(savedMessages.([]string), m.ReplyTo.Text)) } +// Remove a message from published messages in the current chat +// Command syntax : /unpublish [publication ID] func Unpublish(m *tb.Message) { - -} - -func Retrieve(m *tb.Message) { - if _, exists := shared.ChatData.Get(m.Chat.ID, "saved_messages"); !exists { - shared.Bot.Send(m.Chat, "Aucun message sauvegardé") + parsedCommand := strings.Split(m.Text, " ") + if len(parsedCommand) < 2 { + shared.Bot.Send(m.Chat, "syntaxe : /unpublish [publication ID]") return } - savedMessages, _ := shared.ChatData.Get(m.Chat.ID, "saved_messages") - for _, message := range savedMessages.([]string) { - shared.Bot.Send(m.Chat, "message : "+message) + index, err := strconv.Atoi(parsedCommand[1]) + if err != nil { + shared.Bot.Send(m.Chat, "ID de publication invalide") + return } + savedMessages, exists := shared.ChatData.Get(m.Chat.ID, "published_messages") + if !exists || len(savedMessages.([]string)) == 0 { + shared.Bot.Send(m.Chat, "Aucun message publié") + return + } + if len(savedMessages.([]string)) <= 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)) + shared.Bot.Send(m.Chat, "Message supprimé des publication") +} + +// If performed in MP : retrieve all messages from all subscribed sources for the user +// If performed in Group Chat : retrieved all published messages for this chat +// Command syntax : /retrieve +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 { + 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) + } + 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") + return + } + for _, chat := range strings.Split(userSubscribedChats, ":") { + 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) + } + shared.Bot.Send(m.Chat, "--- Messages publiés ---") + } + return + } + shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat") +} + +// Get all users subscribed to the provided channel +func getSubscribers(chatID int64) []string { + var subscribers []string + for _, username := range shared.Users.GetUsernames() { + userSubscribedChats, exists := shared.Users.Get(username, "subscribed_chats") + if exists { + splittedChats := strings.Split(userSubscribedChats, ":") + for _, splittedChatID := range splittedChats { + if splittedChatID == strconv.FormatInt(chatID, 10) { + subscribers = append(subscribers, username) + } + } + } + } + return subscribers } diff --git a/shared/users.go b/shared/users.go index ebb78f8..1105819 100644 --- a/shared/users.go +++ b/shared/users.go @@ -61,6 +61,17 @@ func (u users) Set(username string, key, data string) { go uf.write() } +// Get all known usernames +func (u users) GetUsernames() []string { + u.mutex.Lock() + defer u.mutex.Unlock() + var usernames []string + for username, _ := range u.data { + usernames = append(usernames, username) + } + return usernames +} + func (u usersFile) read() { u.mutex.Lock() defer u.mutex.Unlock() From 29add0224c2b853dc88f07e36857e96627f555cd Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Mon, 31 Dec 2018 15:59:34 +0100 Subject: [PATCH 4/6] Fixed a bug where persitence would cause publish module failures --- commands/.#subscribe.go | 1 + commands/subscribe.go | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) create mode 120000 commands/.#subscribe.go 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 ---") } From db421c828b7ae9f4ddd2f8fdfa89d191fe4d31df Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Mon, 31 Dec 2018 16:50:19 +0100 Subject: [PATCH 5/6] Codu quality patch in order to get merged with master --- alfred.go | 1 - commands/.#subscribe.go | 1 - commands/subscribe.go | 6 +++--- shared/users.go | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) delete mode 120000 commands/.#subscribe.go diff --git a/alfred.go b/alfred.go index 383d165..be6af5b 100644 --- a/alfred.go +++ b/alfred.go @@ -67,7 +67,6 @@ func main() { b.Handle(key, value) } - log.Println("token : " + settings.Settings["token"].(string)) log.Println("Starting bot") b.Start() } diff --git a/commands/.#subscribe.go b/commands/.#subscribe.go deleted file mode 120000 index a0892a2..0000000 --- a/commands/.#subscribe.go +++ /dev/null @@ -1 +0,0 @@ -aethor@pc60.home.13981:1546264820 \ No newline at end of file diff --git a/commands/subscribe.go b/commands/subscribe.go index 25a92ad..d0ac26c 100644 --- a/commands/subscribe.go +++ b/commands/subscribe.go @@ -70,7 +70,7 @@ func Unsubscribe(m *tb.Message) { shared.Users.Set(m.Sender.Username, "subscribed_chats", strings.Join(splittedChats, ":")) } -// List all subscribers of the current chat +// ListSubscribers List all subscribers of the current chat // Command syntax : /listsubscribers func ListSubscribers(m *tb.Message) { if m.Chat.Type != "group" && m.Chat.Type != "supergroup" { @@ -104,7 +104,7 @@ func Publish(m *tb.Message) { } -// Remove a message from published messages in the current chat +// Unpublish remove a message from published messages in the current chat // Command syntax : /unpublish [publication ID] func Unpublish(m *tb.Message) { parsedCommand := strings.Split(m.Text, " ") @@ -131,7 +131,7 @@ func Unpublish(m *tb.Message) { shared.Bot.Send(m.Chat, "Message supprimé des publication") } -// If performed in MP : retrieve all messages from all subscribed sources for the user +// Retrieve If performed in MP : retrieve all messages from all subscribed sources for the user // If performed in Group Chat : retrieved all published messages for this chat // Command syntax : /retrieve func Retrieve(m *tb.Message) { diff --git a/shared/users.go b/shared/users.go index 1105819..7eb47a2 100644 --- a/shared/users.go +++ b/shared/users.go @@ -61,7 +61,7 @@ func (u users) Set(username string, key, data string) { go uf.write() } -// Get all known usernames +// GetUsernames all usernames stored in settings func (u users) GetUsernames() []string { u.mutex.Lock() defer u.mutex.Unlock() From 704625e930e1e069e2c81d4737dc702046398c8f Mon Sep 17 00:00:00 2001 From: Amalvy Arthur Date: Mon, 31 Dec 2018 17:04:28 +0100 Subject: [PATCH 6/6] Added publish module documentation --- doc/publish.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 doc/publish.md diff --git a/doc/publish.md b/doc/publish.md new file mode 100644 index 0000000..84e4e4d --- /dev/null +++ b/doc/publish.md @@ -0,0 +1,65 @@ +# Publish system overview + +The publish module intend to be a "multi-pin" feature for chats, allowing users to retrieve importants messages in a crowded conversation. + +## Commands + + +### Subscribe + +**Description** : Subscribe to this group chat publications + +**Usage location** : Group chat only + +**Command syntax** : /subscribe + + +### Unsubscribe + +**Description** : Unsubscribe [target chat member] from this group chat publications. If no member is provided, unsubscribe yourself. + +**Usage location** : Group chat + +**Command syntax** : /unsubscribe [target chat member] + +*note* : parameter [target chat member] not implemented + + +### ListSubscribers + +**Description** : List all subscribers of this group chat + +**Usage location** : Group chat + +**Command syntax** : /listsubscribers + + +### Publish + +**Description** : Publish a message to Alfred for this group chat and sends this message via MP to every subscriber of the group chat. The message can then be retrieved using the *retrieve* command. + +**Usage location** : Group chat only + +**Usage conditions** : Reply to the message to publish + +**Command syntax** : /publish + +*note* : MP not implemented + +### Unpublish + +**Description** : Remove a published message from Alfred for this group chat + +**Usage location** : Group chat only + +**Command syntax** : /unpublish [publication ID] + + +### Retrieve + +**Description** : if MP, retrieve all messages from subscribed sources for user, if Group Chat, retrieve all published messages for this chat + +**Usage location** : Group Chat or MP + +**Command syntax** : /retrieve +