Basic save feature
the build was successful Details

This commit is contained in:
Amalvy Arthur 2018-12-30 19:31:56 +01:00
parent 14a3bc27d7
commit dea2b4cfb4
3 changed files with 49 additions and 1 deletions

5
.gitignore vendored
View File

@ -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
chat_data.json

View File

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

42
commands/save.go Normal file
View File

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