mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 18:46:44 +01:00
Basic save feature
This commit is contained in:
parent
14a3bc27d7
commit
dea2b4cfb4
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,6 +11,9 @@
|
|||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
*.out
|
*.out
|
||||||
|
|
||||||
|
#swap files
|
||||||
|
*~
|
||||||
|
|
||||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||||
.glide/
|
.glide/
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ func main() {
|
|||||||
"/chaos": commands.TwitterSJW,
|
"/chaos": commands.TwitterSJW,
|
||||||
"/apero": commands.AperoTime,
|
"/apero": commands.AperoTime,
|
||||||
"/quote": commands.Quote,
|
"/quote": commands.Quote,
|
||||||
|
"/save": commands.Save,
|
||||||
|
"/getsaved": commands.GetSaved,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
||||||
@ -61,6 +63,7 @@ func main() {
|
|||||||
b.Handle(key, value)
|
b.Handle(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("token : " + settings.Settings["token"].(string))
|
||||||
log.Println("Starting bot")
|
log.Println("Starting bot")
|
||||||
b.Start()
|
b.Start()
|
||||||
}
|
}
|
||||||
|
42
commands/save.go
Normal file
42
commands/save.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user