-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
handlers.go
76 lines (64 loc) · 2.05 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cli
import (
"fmt"
"log"
"github.com/evan-buss/openbooks/core"
"github.com/evan-buss/openbooks/dcc"
"github.com/schollz/progressbar/v3"
)
// DownloadSearchResults downloads the search results
// and sends user a response message
func (c Config) searchHandler(text string) {
download, err := dcc.ParseString(text)
if err != nil {
log.Println(err)
return
}
bar := progressbar.DefaultBytes(download.Size, download.Filename)
extractedPath, err := core.DownloadExtractDCCString(c.Dir, text, bar)
if err != nil {
fmt.Println(err)
}
fmt.Println("Results location: " + extractedPath)
}
// DownloadBookFile downloads the search results and sends
// a user a response message
func (c Config) downloadHandler(text string) {
download, err := dcc.ParseString(text)
if err != nil {
log.Println(err)
return
}
bar := progressbar.DefaultBytes(download.Size, download.Filename)
extractedPath, err := core.DownloadExtractDCCString(c.Dir, text, bar)
if err != nil {
fmt.Println(err)
}
fmt.Println("File location: " + extractedPath)
}
// NoResults is called when the user searches for something that
// is not available sends a CLI message
func (c Config) noResultsHandler(_ string) {
fmt.Println("No results returned for your search...")
}
// BadServer is called when the user tries to download a file from a
// server that is not available.
func (c Config) badServerHandler(_ string) {
fmt.Println("That server is not available. Try again...")
}
// SearchAccepted is called when the search has been accepted but the user
// must wait in the queue for the search to be executed.
func (c Config) searchAcceptedHandler(_ string) {
fmt.Println("Search has been accepted. Please wait.")
}
// MatchesFound is called when the search returns the number of results
// found. Server sends the client a status update
func (c Config) matchesFoundHandler(num string) {
fmt.Printf("Found %s search results.", num)
}
func (c Config) pingHandler(_ string) {
c.irc.Pong(c.Server)
}
func (c *Config) versionHandler(line string) {
core.SendVersionInfo(c.irc, line, c.Version)
}