This commit is contained in:
KLIPFEL Arthur 2018-07-25 11:57:15 +02:00
parent 54c3bc8f59
commit d5a7922779
13 changed files with 360 additions and 37 deletions

30
commands/dice.go Normal file
View file

@ -0,0 +1,30 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 20:50:04
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 21:00:59
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
"math/rand"
"strconv"
"strings"
)
func Dice(m *tb.Message) {
split := strings.Split(m.Text, " ")
if len(split) < 2 {
shared.Bot.Send(m.Chat, "Pour lancer un dé, il faut préciser combien de faces il a.")
return
}
up, err := strconv.Atoi(split[1])
if err != nil || up <= 0 {
shared.Bot.Send(m.Chat, split[1]+" n'est pas un nombre valide.")
return
}
shared.Bot.Send(m.Chat, strconv.Itoa(rand.Intn(up+1)))
}

17
commands/framapad.go Normal file
View file

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:11:26
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:12:58
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Framapad(m *tb.Message) {
shared.Bot.Send(m.Chat, "Venez participer à mon développement en posant vos idées ici : https://mensuel.framapad.org/p/ALFRED2LERETOUR.")
}

68
commands/gender.go Normal file
View file

@ -0,0 +1,68 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 14:55:33
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 20:29:36
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
"strings"
)
func SetGender(m *tb.Message) {
if m.Sender.Username == "" {
shared.Bot.Send(m.Chat, "Il faut avoir enregistré un username pour pouvoir utiliser cette fonction")
return
}
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.Username, "gender", data)
shared.Bot.Send(m.Chat, "Votre genre est enregistré, je vous considère maintenant comme « "+data+" ».")
}
func Gender(m *tb.Message) {
split := strings.Split(m.Text, " ")
if len(split) > 1 {
// Username asked
username := split[1]
username = strings.Replace(username, "@", "", 1)
data, exists := shared.Users.Get(username, "gender")
if !exists {
shared.Bot.Send(m.Chat, username+" n'est pas un utilisateur existant ou n'a pas renseigné son genre.")
return
}
shared.Bot.Send(m.Chat, "L'utilisateur "+username+" a pour genre « "+data+" ».")
} else {
data, exists := shared.Users.Get(m.Sender.Username, "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 := range slice {
clean := false
for !clean {
clean = true
if strings.HasPrefix(slice[i], "@") {
slice[i] = strings.Replace(slice[i], "@", "", 1)
clean = false
} else if strings.HasPrefix(slice[i], "/") {
slice[i] = strings.Replace(slice[i], "/", "", 1)
clean = false
}
}
}
return slice
}

17
commands/git.go Normal file
View file

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:07:34
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:08:49
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Git(m *tb.Message) {
shared.Bot.Send(m.Chat, "Mon code source est accessible librement à l'adresse https://git.klmp200.net/ALFRED/ALFRED. Venez contribuer :)")
}

17
commands/hello.go Normal file
View file

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:05:45
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:06:39
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func Hello(m *tb.Message) {
shared.Bot.Send(m.Chat, "Bonjour "+m.Sender.Username)
}

17
commands/on_text.go Normal file
View file

@ -0,0 +1,17 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 12:09:37
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 12:10:26
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
)
func OnText(m *tb.Message) {
shared.History.AddMessage(m.Chat.ID, m.Text)
}

27
commands/sponge.go Normal file
View file

@ -0,0 +1,27 @@
/*
* @Author: Bartuccio Antoine
* @Date: 2018-07-24 11:52:11
* @Last Modified by: klmp200
* @Last Modified time: 2018-07-24 11:58:42
*/
package commands
import (
"../shared"
tb "gopkg.in/tucnak/telebot.v2"
"strings"
)
func Sponge(m *tb.Message) {
message := ""
for i, char := range shared.History.LastMessage(m.Chat.ID) {
if i%2 == 0 {
message += strings.ToLower(string(char))
} else {
message += strings.ToUpper(string(char))
}
}
shared.Bot.Send(m.Chat, message)
}