forked from git.klmp200.net/ALFRED
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
/*
|
|
* @Author: Bartuccio Antoine
|
|
* @Date: 2018-07-24 14:55:33
|
|
* @Last Modified by: klmp200
|
|
* @Last Modified time: 2018-07-24 17:26:57
|
|
*/
|
|
|
|
package commands
|
|
|
|
import (
|
|
"../shared"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
"strings"
|
|
)
|
|
|
|
func SetGender(m *tb.Message) {
|
|
split := cleanGender(strings.Split(m.Text, " ")[1:])
|
|
if len(split) == 0 {
|
|
shared.Bot.Send(m.Chat, "Désolé, mais je n'ai pas compris.")
|
|
return
|
|
}
|
|
data := strings.Join(split, " ")
|
|
shared.Users.Set(m.Sender.ID, "gender", data)
|
|
shared.Bot.Send(m.Chat, "Votre genre est enregistré, je vous considère maintenant comme « "+data+" ».")
|
|
}
|
|
|
|
func Gender(m *tb.Message) {
|
|
data, exists := shared.Users.Get(m.Sender.ID, "gender")
|
|
if !exists {
|
|
shared.Bot.Send(m.Chat, "Vous n'avez pas enregistré votre genre, je ne voudrais pas l'assumer.")
|
|
} else {
|
|
shared.Bot.Send(m.Chat, data)
|
|
}
|
|
}
|
|
|
|
func cleanGender(slice []string) []string {
|
|
for i, value := range slice {
|
|
if strings.HasPrefix(value, "@") {
|
|
slice[i] = strings.Replace(value, "@", "@ ", 1)
|
|
} else if strings.HasPrefix(value, "/") {
|
|
slice[i] = strings.Replace(value, "/", "/ ", 1)
|
|
}
|
|
}
|
|
return slice
|
|
}
|