diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | active_client.go | 2 | ||||
| -rw-r--r-- | api_client.go | 18 | ||||
| -rw-r--r-- | api_client_test.go | 10 | ||||
| -rw-r--r-- | client.go | 12 | ||||
| -rw-r--r-- | cmd/kamusku-telegram-bot/main.go | 2 | ||||
| -rw-r--r-- | dictionary.go | 23 | ||||
| -rw-r--r-- | dictionary_test.go | 4 | ||||
| -rw-r--r-- | go.mod | 15 | ||||
| -rw-r--r-- | go.sum | 41 | ||||
| -rw-r--r-- | internal/cmd/mergedic/main.go | 4 | ||||
| -rw-r--r-- | kamusd.go | 2 | ||||
| -rw-r--r-- | kamusd_test.go | 2 | ||||
| -rw-r--r-- | memfs.go | 2 | ||||
| -rw-r--r-- | server.go | 55 | ||||
| -rw-r--r-- | telegram_bot.go | 16 |
16 files changed, 56 insertions, 154 deletions
@@ -12,7 +12,7 @@ BIN_LINUX_AMD64 := _bin/linux_amd64 all: test check test: - go test -race -p=1 ./... + CGO_ENABLED=1 go test -race -p=1 ./... check: golangci-lint run ./... diff --git a/active_client.go b/active_client.go index 6e9dbc5..c7228cb 100644 --- a/active_client.go +++ b/active_client.go @@ -8,9 +8,7 @@ import ( "git.sr.ht/~shulhan/kamusku" ) -// // activeClient define an interface for an active client. -// type activeClient interface { Lookup(words []string) (res kamusku.LookupResponse, err error) ListRootWords() (rootWords kamusku.Words, err error) diff --git a/api_client.go b/api_client.go index 10e487a..95b1a63 100644 --- a/api_client.go +++ b/api_client.go @@ -7,7 +7,7 @@ package kamusd import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -15,18 +15,14 @@ import ( "git.sr.ht/~shulhan/kamusku" ) -// // apiClient is client that connect to cached server API. -// type apiClient struct { url string conn *http.Client } -// // newAPIClient create a new client for server API. // If url is empty it will use default server API. -// func newAPIClient(url string) (client *apiClient) { if len(url) == 0 { url = defServerAPI @@ -42,12 +38,8 @@ func newAPIClient(url string) (client *apiClient) { return client } -// // Lookup the definition of words through server API. -// -func (client *apiClient) Lookup(words []string) ( - res kamusku.LookupResponse, err error, -) { +func (client *apiClient) Lookup(words []string) (res kamusku.LookupResponse, err error) { if len(words) == 0 { return nil, nil } @@ -67,7 +59,9 @@ func (client *apiClient) Lookup(words []string) ( return nil, fmt.Errorf("Lookup: %w", err) } - resBody, err := ioutil.ReadAll(httpRes.Body) + var resBody []byte + + resBody, err = io.ReadAll(httpRes.Body) if err != nil { return nil, fmt.Errorf("Lookup: %w", err) } @@ -86,9 +80,7 @@ func (client *apiClient) Lookup(words []string) ( return res, nil } -// // ListRootWords list all of the root words in dictionary. -// func (client *apiClient) ListRootWords() (res kamusku.Words, err error) { //TODO: return cached list. return res, nil diff --git a/api_client_test.go b/api_client_test.go index 46dac0c..e3d21c5 100644 --- a/api_client_test.go +++ b/api_client_test.go @@ -8,7 +8,7 @@ import ( "testing" "git.sr.ht/~shulhan/kamusku" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestApiClient_Lookup_offline(t *testing.T) { @@ -45,11 +45,11 @@ func TestApiClient_Lookup_offline(t *testing.T) { got, err := client.Lookup(c.words) if err != nil { - test.Assert(t, "error", c.expError, err.Error(), true) + test.Assert(t, `error`, c.expError, err.Error()) continue } - test.Assert(t, "kamusku.LookupResponse", c.exp, got, true) + test.Assert(t, `kamusku.LookupResponse`, c.exp, got) } } @@ -98,7 +98,7 @@ func TestApiClient_Lookup_online(t *testing.T) { got, err := client.Lookup(c.words) if err != nil { - test.Assert(t, "error", c.expError, err.Error(), true) + test.Assert(t, `error`, c.expError, err.Error()) continue } @@ -106,6 +106,6 @@ func TestApiClient_Lookup_online(t *testing.T) { t.Logf("got: %s = %+v", k, v) } - test.Assert(t, "LookupResponse", c.exp, got, true) + test.Assert(t, `LookupResponse`, c.exp, got) } } @@ -10,18 +10,14 @@ import ( "git.sr.ht/~shulhan/kamusku" ) -// // Client for dictionary API and official KBBI server. -// type Client struct { active activeClient api *apiClient kbbic *kamusku.KbbiClient } -// // NewClient create and initialize new client. -// func NewClient() (cl *Client, err error) { cl = &Client{} @@ -41,9 +37,7 @@ func NewClient() (cl *Client, err error) { return cl, nil } -// // Lookup lookup definition of words. -// func (cl *Client) Lookup(words []string) (res kamusku.LookupResponse, err error) { if cl.active != nil { return cl.active.Lookup(words) @@ -57,17 +51,13 @@ func (cl *Client) Lookup(words []string) (res kamusku.LookupResponse, err error) return res, nil } -// // IsAuthenticated will return true if client has logged in to KBBI official // server. -// func (cl *Client) IsAuthenticated() bool { return cl.kbbic.IsAuthenticated() } -// // ListRootWords list all of the root words in dictionary. -// func (cl *Client) ListRootWords() (res kamusku.Words, err error) { if cl.active != nil { return cl.active.ListRootWords() @@ -81,10 +71,8 @@ func (cl *Client) ListRootWords() (res kamusku.Words, err error) { return res, nil } -// // Login authenticate the client using username and password to official KBBI // server. -// func (cl *Client) Login(user, pass string) (err error) { err = cl.kbbic.Login(user, pass) if err != nil { diff --git a/cmd/kamusku-telegram-bot/main.go b/cmd/kamusku-telegram-bot/main.go index f60f4f6..6443097 100644 --- a/cmd/kamusku-telegram-bot/main.go +++ b/cmd/kamusku-telegram-bot/main.go @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// // Program kamusku-telegram-bot adalah Telegram Bot yang melayani pencarian // definisi kata menggunakan perintah pesan di Telegram. -// package main import ( diff --git a/dictionary.go b/dictionary.go index 2dd309f..9164b25 100644 --- a/dictionary.go +++ b/dictionary.go @@ -8,22 +8,19 @@ import ( "bytes" "encoding/gob" "errors" - "io/ioutil" "log" "os" "sync" "git.sr.ht/~shulhan/kamusku" - libio "github.com/shuLhan/share/lib/io" + libos "git.sr.ht/~shulhan/pakakeh.go/lib/os" ) const ( defStorageName = "kamus.gob" ) -// // dictionary contains cache of words and its definitions. -// type dictionary struct { sync.Mutex cache map[string]*kamusku.Word @@ -31,9 +28,7 @@ type dictionary struct { storagePath string } -// // newDictionary create and initialize the cache for dictionary. -// func newDictionary(storagePath string) (dict *dictionary, err error) { if len(storagePath) == 0 { storagePath = defStorageName @@ -52,9 +47,7 @@ func newDictionary(storagePath string) (dict *dictionary, err error) { return dict, nil } -// // lookup the definition of word from cache or nil if not exist. -// func (dict *dictionary) lookup(word string) (kata *kamusku.Word) { dict.Lock() kata = dict.cache[word] @@ -62,24 +55,22 @@ func (dict *dictionary) lookup(word string) (kata *kamusku.Word) { return kata } -// // isChanging will return true if the last cache size is not equal with // current size. -// func (dict *dictionary) isChanging() bool { dict.Lock() defer dict.Unlock() return dict.lastSize != len(dict.cache) } -// // load the cached dictionary from storage. -// func (dict *dictionary) load() (err error) { dict.Lock() defer dict.Unlock() - v, err := ioutil.ReadFile(dict.storagePath) + var v []byte + + v, err = os.ReadFile(dict.storagePath) if err != nil { if errors.Is(err, os.ErrNotExist) { return nil @@ -113,9 +104,7 @@ func (dict *dictionary) load() (err error) { return nil } -// // set save the definition of word into cache. -// func (dict *dictionary) set(word string, kata *kamusku.Word) { if len(word) == 0 || kata == nil { return @@ -126,9 +115,7 @@ func (dict *dictionary) set(word string, kata *kamusku.Word) { dict.Unlock() } -// // store the cache to file only if the storage path is set. -// func (dict *dictionary) store() (err error) { if len(dict.storagePath) == 0 { return nil @@ -167,7 +154,7 @@ func (dict *dictionary) store() (err error) { log.Println("dictionary: store: ", err) } - err = libio.Copy(dict.storagePath, newStorage) + err = libos.Copy(dict.storagePath, newStorage) if err != nil { return err } diff --git a/dictionary_test.go b/dictionary_test.go index b9861fe..09a9a1a 100644 --- a/dictionary_test.go +++ b/dictionary_test.go @@ -7,7 +7,7 @@ package kamusd import ( "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestDictionary_store_load(t *testing.T) { @@ -28,5 +28,5 @@ func TestDictionary_store_load(t *testing.T) { t.Fatal(err) } - test.Assert(t, "store and load", exp, got, true) + test.Assert(t, `store and load`, exp, got) } @@ -1,12 +1,17 @@ module git.sr.ht/~shulhan/kamusd -go 1.15 +go 1.21 require ( - git.sr.ht/~shulhan/kamusku v0.0.0-00010101000000-000000000000 - github.com/shuLhan/share v0.22.1-0.20210124101421-f76dc891e371 + git.sr.ht/~shulhan/kamusku v0.1.0 + git.sr.ht/~shulhan/pakakeh.go v0.54.0 ) -//replace github.com/shuLhan/share => ../share +require ( + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect +) + +//replace git.sr.ht/~shulhan/kamusku => ../kamusku -replace git.sr.ht/~shulhan/kamusku => ../kamusku +//replace git.sr.ht/~shulhan/pakakeh.go => ../pakakeh.go @@ -1,33 +1,8 @@ -git.sr.ht/~shulhan/asciidoctor-go v0.0.0-20201205130914-be765f32b57b/go.mod h1:ejaxKeBMNL5EpP2zjRP4B8zuOr+MM4ZyGwE3y7807WI= -git.sr.ht/~shulhan/asciidoctor-go v0.0.0-20201226102329-36285ff15434/go.mod h1:ejaxKeBMNL5EpP2zjRP4B8zuOr+MM4ZyGwE3y7807WI= -git.sr.ht/~shulhan/ciigo v0.3.0/go.mod h1:Y5FvSiJg88qshoR1ktj4fLzM5sk1pZcV0kJGU8GAuTo= -git.sr.ht/~shulhan/ciigo v0.3.1-0.20210109200358-c23bd42ef521/go.mod h1:DLyaapVphRtqry80iqw+luWAKepHtbDmbvxqFmulcko= -github.com/shuLhan/share v0.20.2-0.20201122173411-e8b3bf5ee6e9/go.mod h1:oBv+CGHG6u4Sa71+nJJJji8mCgPAadywjsB3I3k/b0o= -github.com/shuLhan/share v0.20.2-0.20201205202022-66069b9e49fe/go.mod h1:oBv+CGHG6u4Sa71+nJJJji8mCgPAadywjsB3I3k/b0o= -github.com/shuLhan/share v0.22.0/go.mod h1:u9caerexlcxmPVDttj7PnkxCBDY6yBRTZ+gGR+1tO98= -github.com/shuLhan/share v0.22.1-0.20210109185915-0490a19341d9/go.mod h1:u9caerexlcxmPVDttj7PnkxCBDY6yBRTZ+gGR+1tO98= -github.com/shuLhan/share v0.22.1-0.20210124101421-f76dc891e371 h1:5UPgRXvrL9YmiydMG72xJYE8LuYS1EcjZQrBqhSX064= -github.com/shuLhan/share v0.22.1-0.20210124101421-f76dc891e371/go.mod h1:y4+p5vUmKNNhMMhU6yGgE6QxTgJxA4nv6OOq+cIf7wU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210108172913-0df2131ae363/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +git.sr.ht/~shulhan/kamusku v0.1.0 h1:ri2tquQ5y9dQ2UMgkwZxC/XMURKdoGR4T3UvE7nOG9Y= +git.sr.ht/~shulhan/kamusku v0.1.0/go.mod h1:MVu5y/PKsG6r29S9oNECDmlDfQ0/GaX6+DNUF3XbVj8= +git.sr.ht/~shulhan/pakakeh.go v0.54.0 h1:pwTQiJSyE5xTaWNR0FnWsszJ+0Z5hB2ufNLXcy8z0y8= +git.sr.ht/~shulhan/pakakeh.go v0.54.0/go.mod h1:ys7WNtXm03x0M59oqrqBjXnc+wRCX8JBXyE/W8+KVbw= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/internal/cmd/mergedic/main.go b/internal/cmd/mergedic/main.go index d9612ca..a962aba 100644 --- a/internal/cmd/mergedic/main.go +++ b/internal/cmd/mergedic/main.go @@ -2,15 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// // Program mergedic merge daftar kata from KBBI with hunspell-id dictionary. -// package main import ( "log" - "github.com/shuLhan/share/lib/hunspell" + "git.sr.ht/~shulhan/pakakeh.go/lib/hunspell" ) func main() { @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// // Package kamusd provide HTTP server API for Kamusku client and Kamusku // Telegram bot. -// package kamusd import "time" diff --git a/kamusd_test.go b/kamusd_test.go index ba71aac..c2140c9 100644 --- a/kamusd_test.go +++ b/kamusd_test.go @@ -17,7 +17,7 @@ const ( testKamusStorage = "testdata/kamus.gob" ) -//nolint: gochecknoglobals +// nolint: gochecknoglobals var ( testServer *Server @@ -4,6 +4,6 @@ package kamusd -import "github.com/shuLhan/share/lib/memfs" +import "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" var memfsWWW *memfs.MemFS @@ -9,23 +9,17 @@ import ( "encoding/json" "fmt" "log" - "math/rand" - "net/http" "os" "strings" "sync" "time" "git.sr.ht/~shulhan/kamusku" - "github.com/shuLhan/share/lib/ascii" - "github.com/shuLhan/share/lib/debug" - libhttp "github.com/shuLhan/share/lib/http" - "github.com/shuLhan/share/lib/memfs" + "git.sr.ht/~shulhan/pakakeh.go/lib/ascii" + libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http" ) -// // Server for kamusku with caching and spell checking functionalities. -// type Server struct { httpd *libhttp.Server kamus *dictionary @@ -41,22 +35,18 @@ type Server struct { offline bool } -// // NewServer create and initialize the server with optional path to dictionary // storage. -// func NewServer(dictionaryStorage string) (server *Server, err error) { + var logp = `NewServer` + address := defListen port := os.Getenv(envPort) if len(port) > 0 { address = ":" + port } - httpdOpts := &libhttp.ServerOptions{ - Options: memfs.Options{ - Root: "_www", - Development: debug.Value >= 2, - }, + var httpdOpts = libhttp.ServerOptions{ Memfs: memfsWWW, Address: address, } @@ -67,22 +57,22 @@ func NewServer(dictionaryStorage string) (server *Server, err error) { server.kamus, err = newDictionary(dictionaryStorage) if err != nil { - return nil, fmt.Errorf("NewServer: %w", err) + return nil, fmt.Errorf(`%s: %w`, logp, err) } server.httpd, err = libhttp.NewServer(httpdOpts) if err != nil { - return nil, fmt.Errorf("NewServer: %w", err) + return nil, fmt.Errorf(`%s: %w`, logp, err) } server.kbbic, err = kamusku.NewKbbiClient() if err != nil { - return nil, fmt.Errorf("NewServer: %w", err) + return nil, fmt.Errorf(`%s: %w`, logp, err) } err = server.registerEndpoints() if err != nil { - return nil, fmt.Errorf("NewServer: %w", err) + return nil, fmt.Errorf(`%s: %w`, logp, err) } if !server.kbbic.IsAuthenticated() { @@ -99,9 +89,7 @@ func NewServer(dictionaryStorage string) (server *Server, err error) { return server, nil } -// // Start the HTTP server. -// func (server *Server) Start() (err error) { go server.dumpCacheJob() @@ -110,9 +98,7 @@ func (server *Server) Start() (err error) { return server.httpd.Start() } -// // Shutdown the HTTP server and save the cache for future use. -// func (server *Server) Shutdown() (err error) { err = server.httpd.Shutdown(context.TODO()) @@ -124,9 +110,7 @@ func (server *Server) Shutdown() (err error) { return err } -// // dumpCacheJob periodically save the cache or when the server stopped. -// func (server *Server) dumpCacheJob() { ticker := time.NewTicker(1 * time.Hour) @@ -142,9 +126,7 @@ func (server *Server) dumpCacheJob() { } } -// // dumpCache to storage to be loaded later. -// func (server *Server) dumpCache() { if !server.kamus.isChanging() { return @@ -155,19 +137,13 @@ func (server *Server) dumpCache() { } } -// // handleAdmin is endpoint to manage dictionary cache on the web. -// -func (server *Server) handleAdmin( - _ http.ResponseWriter, _ *http.Request, _ []byte, -) (resBody []byte, err error) { +func (server *Server) handleAdmin(_ *libhttp.EndpointRequest) (resBody []byte, err error) { return resBody, nil } -func (server *Server) handleDefinisi( - _ http.ResponseWriter, httpReq *http.Request, _ []byte, -) (resBody []byte, err error) { - paramKata := httpReq.Form.Get(paramNameKata) +func (server *Server) handleDefinisi(epr *libhttp.EndpointRequest) (resBody []byte, err error) { + paramKata := epr.HTTPRequest.Form.Get(paramNameKata) if len(paramKata) == 0 { return []byte(jsonEmptyObject), nil } @@ -215,11 +191,9 @@ func (server *Server) handleDefinisi( return json.Marshal(res) } -// // registerEndpoints register the API endpoints. -// func (server *Server) registerEndpoints() (err error) { - epDefinisi := &libhttp.Endpoint{ + var epDefinisi = libhttp.Endpoint{ Method: libhttp.RequestMethodGet, Path: pathAPIDefinisi, RequestType: libhttp.RequestTypeQuery, @@ -233,10 +207,9 @@ func (server *Server) registerEndpoints() (err error) { err) } - rand.Seed(time.Now().Unix()) pathAdmin := string(ascii.Random([]byte(ascii.LettersNumber), 16)) - epAdmin := &libhttp.Endpoint{ + var epAdmin = libhttp.Endpoint{ Method: libhttp.RequestMethodGet, Path: pathAdmin, RequestType: libhttp.RequestTypeQuery, diff --git a/telegram_bot.go b/telegram_bot.go index 3892ece..0d83fa2 100644 --- a/telegram_bot.go +++ b/telegram_bot.go @@ -12,7 +12,7 @@ import ( "strings" "git.sr.ht/~shulhan/kamusku" - "github.com/shuLhan/share/api/telegram/bot" + "git.sr.ht/~shulhan/pakakeh.go/api/telegram/bot" ) const ( @@ -22,17 +22,13 @@ const ( commandStart = "start" ) -// // TelegramBot implement Telegram Bot for KBBI. -// type TelegramBot struct { *bot.Bot apiClient *apiClient } -// // NewTelegramBot create and initialize new Telegram Bot. -// func NewTelegramBot(token, webhookURL string) (tgbot *TelegramBot, err error) { tgbot = &TelegramBot{ apiClient: newAPIClient(""), @@ -77,9 +73,7 @@ func NewTelegramBot(token, webhookURL string) (tgbot *TelegramBot, err error) { return tgbot, nil } -// // handleUpdate process the Update information send by Telegram server. -// func (tgbot *TelegramBot) handleUpdate(update bot.Update) { if update.Message == nil { return @@ -94,9 +88,7 @@ func (tgbot *TelegramBot) handleUpdate(update bot.Update) { } } -// // handleCommandDefinisi lookup the words definition and reply back to client. -// func (tgbot *TelegramBot) handleCommandDefinisi(update bot.Update) { msgReq := update.Message @@ -126,11 +118,9 @@ func (tgbot *TelegramBot) handleCommandDefinisi(update bot.Update) { } } -// // handleCommandStart handle the "/start" command by welcoming the user. -// func (tgbot *TelegramBot) handleCommandStart(update bot.Update) { - //nolint: lll + //nolint:lll text := `Selamat datang <b>` + update.Message.From.FirstName + `</b>, Untuk mencari definisi kata ketikan perintah <code>/definisi</code> diikuti dengan spasi dan kata yang ingin dicari. Pisahkan kata dengan koma untuk mencari lebih dari satu kata. @@ -151,7 +141,7 @@ func (tgbot *TelegramBot) sendError(msg *bot.Message, parseMode, errMsg string) } } -//nolint: unused +//nolint:unused func (tgbot *TelegramBot) sendShutdownNotice(msg *bot.Message) { text := `Mohon maaf, KamuskuBot untuk sementara berhenti beroperasi dulu karena masalah legalitas. |
