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