mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-05-24 12:51:16 +02:00
Remove relative path and follow gometalinter guide lines
This commit is contained in:
parent
94313b4819
commit
541ab556d7
17 changed files with 107 additions and 78 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue