Merge branch 'normalization' of ALFRED/ALFRED into master
All checks were successful
the build was successful
All checks were successful
the build was successful
This commit is contained in:
commit
daa77fcfc4
@ -1,16 +1,18 @@
|
||||
pipeline:
|
||||
build:
|
||||
image: golang
|
||||
image: golang:1.11
|
||||
group: build
|
||||
commands:
|
||||
- export GOPATH=/drone
|
||||
- go get -v -d ./...
|
||||
- go build .
|
||||
test:
|
||||
image: golang
|
||||
group: build
|
||||
image: golang:1.11
|
||||
group: test
|
||||
secrets: [ test_api_token ]
|
||||
environment: [ test_api_token ]
|
||||
commands:
|
||||
- export GOPATH=/drone
|
||||
- go get -v -d ./...
|
||||
- go test ./...
|
||||
publish:
|
||||
|
10
Dockerfile
10
Dockerfile
@ -1,11 +1,15 @@
|
||||
FROM golang:1.10 AS builder
|
||||
FROM golang:1.11 AS builder
|
||||
|
||||
# Download and install the latest release of dep
|
||||
# ADD https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 /usr/bin/dep
|
||||
# RUN chmod +x /usr/bin/dep
|
||||
|
||||
# Copy the code from the host and compile it
|
||||
COPY . ./
|
||||
RUN mkdir -p src/git.klmp200.net/ALFRED/ALFRED
|
||||
|
||||
COPY . src/git.klmp200.net/ALFRED/ALFRED
|
||||
|
||||
WORKDIR "src/git.klmp200.net/ALFRED/ALFRED"
|
||||
|
||||
RUN go get -v -d ./...
|
||||
|
||||
@ -20,7 +24,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /app .
|
||||
FROM alpine:3.4
|
||||
RUN apk add --no-cache ca-certificates apache2-utils
|
||||
COPY --from=builder /app ./
|
||||
COPY --from=builder /go/res ./
|
||||
COPY --from=builder /go/src/git.klmp200.net/ALFRED/ALFRED/res ./
|
||||
|
||||
|
||||
ENTRYPOINT ["./app"]
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:22
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-02 22:58:03
|
||||
* @Last Modified time: 2019-01-04 10:52:37
|
||||
*/
|
||||
|
||||
package main
|
||||
@ -11,9 +11,10 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"./commands"
|
||||
"./settings"
|
||||
"./shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/commands"
|
||||
"git.klmp200.net/ALFRED/ALFRED/settings"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
|
@ -1,19 +1,22 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-27 19:53:09
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-28 13:17:05
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:36:16
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"net/http"
|
||||
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// AperoTime checks if it's time to drink on an external website
|
||||
func AperoTime(m *tb.Message) {
|
||||
response, err := http.Get("http://estcequecestbientotlapero.fr")
|
||||
if err != nil {
|
||||
@ -27,13 +30,4 @@ func AperoTime(m *tb.Message) {
|
||||
return
|
||||
}
|
||||
shared.Bot.Send(m.Chat, doc.Find("h2").First().Text())
|
||||
// doc.Find("h2").Each(func(i int, s *goquery.Selection) {
|
||||
// log.Println(s.Text())
|
||||
// })
|
||||
// node, err := html.Parse(response.Body)
|
||||
// if err != nil {
|
||||
// shared.Bot.Send(m.Chat, "La réponse qui m'a été fournit est incohérente.")
|
||||
// return
|
||||
// }
|
||||
// log.Println(node.NextSibling)
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 20:50:04
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 21:00:59
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:37:39
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// Dice rolls a dice
|
||||
func Dice(m *tb.Message) {
|
||||
split := strings.Split(m.Text, " ")
|
||||
if len(split) < 2 {
|
||||
|
@ -1,17 +1,18 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 12:11:26
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 12:12:58
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:38:07
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// Framapad send a link to the ALFRED framapad
|
||||
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.")
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 14:55:33
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-25 01:29:53
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:38:32
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"strings"
|
||||
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// SetGender register your gender on ALFRED
|
||||
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")
|
||||
|
@ -1,17 +1,19 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 12:07:34
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 12:08:49
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:39:07
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// Git sends a link to the git repo
|
||||
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 :)")
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 12:05:45
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 12:06:39
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:39:24
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// Hello makes ALFRED say hello
|
||||
func Hello(m *tb.Message) {
|
||||
shared.Bot.Send(m.Chat, "Bonjour "+m.Sender.Username)
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 12:09:37
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 12:10:26
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:39:50
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// OnText saves chat history
|
||||
func OnText(m *tb.Message) {
|
||||
shared.History.AddMessage(m.Chat.ID, m.Text)
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-11-14 00:15:43
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-11-14 00:31:48
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:40:01
|
||||
*/
|
||||
|
||||
package commands
|
||||
@ -13,7 +13,7 @@ import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
@ -2,13 +2,14 @@
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2019-01-02 22:46:05
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-03 22:00:09
|
||||
* @Last Modified time: 2019-01-04 10:40:28
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 11:52:11
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 11:58:42
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:40:38
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../shared"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"strings"
|
||||
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
func Sponge(m *tb.Message) {
|
||||
|
@ -15,7 +15,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"../shared"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
|
@ -1,21 +1,23 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-25 18:51:38
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-27 16:49:59
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:47:25
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"../settings"
|
||||
"../shared"
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
"github.com/dghubble/oauth1"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.klmp200.net/ALFRED/ALFRED/settings"
|
||||
"git.klmp200.net/ALFRED/ALFRED/shared"
|
||||
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
"github.com/dghubble/oauth1"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
var client *twitter.Client
|
||||
@ -44,6 +46,7 @@ func twitterCommunicationError(m *tb.Message) {
|
||||
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
||||
}
|
||||
|
||||
// LastTrumpTweet sends the last tweet of Donald Trump
|
||||
func LastTrumpTweet(m *tb.Message) {
|
||||
testOrInitTwitter()
|
||||
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
||||
@ -70,6 +73,7 @@ func LastTrumpTweet(m *tb.Message) {
|
||||
shared.Bot.Send(m.Chat, strings.Join(response, " "))
|
||||
}
|
||||
|
||||
// TwitterTrends sends the french twitter trends
|
||||
func TwitterTrends(m *tb.Message) {
|
||||
testOrInitTwitter()
|
||||
trends, _, err := client.Trends.Place(int64(615702), nil)
|
||||
@ -84,17 +88,24 @@ func TwitterTrends(m *tb.Message) {
|
||||
shared.Bot.Send(m.Chat, message)
|
||||
}
|
||||
|
||||
// TwitterSJW sends lasts messages with #SJW
|
||||
func TwitterSJW(m *tb.Message) {
|
||||
testOrInitTwitter()
|
||||
last_use, exists := shared.ChatData.Get(m.Chat.ID, "last chaos use")
|
||||
lastUse, exists := shared.ChatData.Get(m.Chat.ID, "last chaos use")
|
||||
if exists {
|
||||
var date time.Time
|
||||
if _, is_string := last_use.(string); is_string {
|
||||
date, _ = time.Parse(time.RFC3339, last_use.(string))
|
||||
} else {
|
||||
date = last_use.(time.Time)
|
||||
var date *time.Time
|
||||
if lastUseConverted, isString := lastUse.(string); isString {
|
||||
parsedDate, err := time.Parse(time.RFC3339, lastUseConverted)
|
||||
if err == nil {
|
||||
date = &parsedDate
|
||||
}
|
||||
}
|
||||
if time.Now().Before(date.Add(time.Hour * 24)) {
|
||||
|
||||
if lastUseConverted, isDate := lastUse.(time.Time); isDate {
|
||||
date = &lastUseConverted
|
||||
}
|
||||
|
||||
if date != nil || time.Now().Before(date.Add(time.Hour*24)) {
|
||||
shared.Bot.Send(m.Chat, "Arioch ne répondra pas à votre appel.")
|
||||
return
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 11:56:47
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 11:58:34
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:48:26
|
||||
*/
|
||||
|
||||
package shared
|
||||
@ -11,4 +11,5 @@ import (
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
// Bot contains telebot instance
|
||||
var Bot *tb.Bot
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-27 15:37:59
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-27 16:06:51
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:49:45
|
||||
*/
|
||||
|
||||
package shared
|
||||
@ -24,10 +24,11 @@ type chatDataFile struct {
|
||||
path string
|
||||
}
|
||||
|
||||
// ChatData manage access to stored data about a chat
|
||||
var ChatData chatData
|
||||
var cdf chatDataFile
|
||||
|
||||
// Init chat data meant to store infos about a chat.
|
||||
// InitChatData is meant to store infos about a chat.
|
||||
func InitChatData(path string) {
|
||||
cdf = chatDataFile{path: path}
|
||||
ChatData = chatData{data: make(map[int64]map[string]interface{})}
|
||||
@ -37,6 +38,7 @@ func InitChatData(path string) {
|
||||
|
||||
}
|
||||
|
||||
// Set stores data about a chat
|
||||
func (c chatData) Set(chat int64, key string, data interface{}) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
@ -47,6 +49,7 @@ func (c chatData) Set(chat int64, key string, data interface{}) {
|
||||
go cdf.write()
|
||||
}
|
||||
|
||||
// Get retrieves data about a chat
|
||||
func (c chatData) Get(chat int64, key string) (interface{}, bool) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 01:27:11
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 12:54:21
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-04 10:51:32
|
||||
*/
|
||||
|
||||
package shared
|
||||
@ -24,10 +24,11 @@ type historyFile struct {
|
||||
path string
|
||||
}
|
||||
|
||||
// History manages acces to chat history
|
||||
var History history
|
||||
var hf historyFile
|
||||
|
||||
// Init a chat history of a given size
|
||||
// InitHistory init a chit history of a given size
|
||||
func InitHistory(size int, history_file_path string) {
|
||||
hf = historyFile{}
|
||||
hf.path = history_file_path
|
||||
@ -39,14 +40,14 @@ func InitHistory(size int, history_file_path string) {
|
||||
hf.read()
|
||||
}
|
||||
|
||||
// Get the number of messages saved in the history
|
||||
// Size get the number of messages saved in the history
|
||||
func (h history) Size() int {
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
return h.size
|
||||
}
|
||||
|
||||
// Get a selected message in a chat history
|
||||
// Message get a selected message in a chat history
|
||||
func (h history) Message(chatID int64, n int) string {
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
@ -57,7 +58,7 @@ func (h history) Message(chatID int64, n int) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Append a message to a given chat
|
||||
// AddMessage append a message to a given chat
|
||||
func (h history) AddMessage(chatID int64, m string) {
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
@ -67,7 +68,7 @@ func (h history) AddMessage(chatID int64, m string) {
|
||||
h.append(chatID, m)
|
||||
}
|
||||
|
||||
// Get the last message of a given chat
|
||||
// LastMessage get the last message of a given chat
|
||||
func (h history) LastMessage(chatID int64) string {
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
@ -77,7 +78,7 @@ func (h history) LastMessage(chatID int64) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Get a copy of a given chat history
|
||||
// ChatHistory get a copy of a given chat history
|
||||
func (h history) ChatHistory(chatID int64) []string {
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-24 14:41:03
|
||||
* @Last Modified by: Bartuccio Antoine
|
||||
* @Last Modified time: 2019-01-02 22:37:58
|
||||
* @Last Modified time: 2019-01-04 10:52:13
|
||||
*/
|
||||
|
||||
package shared
|
||||
@ -30,6 +30,7 @@ type usersFile struct {
|
||||
var Users users
|
||||
var uf usersFile
|
||||
|
||||
// InitUsers inits the User info storage
|
||||
func InitUsers(users_file_path string) {
|
||||
uf = usersFile{}
|
||||
uf.path = users_file_path
|
||||
@ -54,7 +55,7 @@ func (u users) Get(username string, key string) (string, bool) {
|
||||
return user[key], true
|
||||
}
|
||||
|
||||
// Add an info about a given user
|
||||
// Set add an info about a given user
|
||||
func (u users) Set(username string, key, data string) {
|
||||
u.mutex.Lock()
|
||||
defer u.mutex.Unlock()
|
||||
@ -65,12 +66,12 @@ func (u users) Set(username string, key, data string) {
|
||||
go uf.write()
|
||||
}
|
||||
|
||||
// GetUsernames all usernames stored in settings
|
||||
// GetUsernames get all usernames stored in settings
|
||||
func (u users) GetUsernames() []string {
|
||||
u.mutex.Lock()
|
||||
defer u.mutex.Unlock()
|
||||
var usernames []string
|
||||
for username, _ := range u.data {
|
||||
for username := range u.data {
|
||||
usernames = append(usernames, username)
|
||||
}
|
||||
return usernames
|
||||
|
Loading…
Reference in New Issue
Block a user