mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 02:26:44 +01:00
Basic save feature
This commit is contained in:
parent
14a3bc27d7
commit
dea2b4cfb4
5
.gitignore
vendored
5
.gitignore
vendored
@ -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
|
||||
|
@ -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
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