Debian Codegraph @

modules/update/update.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package update
2
3 import (
4 "math"
5 "strconv"
6 "strings"
7
8 "github.com/bettercap/bettercap/session"
9
10 "github.com/google/go-github/github"
11
12 )
13
14 type UpdateModule struct {
15 session.SessionModule
16 client *github.Client
17 }
18
19 func NewUpdateModule(s *session.Session) *UpdateModule {
20 mod := &UpdateModule{
21 SessionModule: session.NewSessionModule("update", s),
22 client: github.NewClient(nil),
23 }
24
25 mod.AddHandler(session.NewModuleHandler("update.check on", "",
26 "Check latest available stable version and compare it with the one being used.",
27 func(args []string) error {
28 return mod.Start()
29 }))
30
31 return mod
32 }
33
34 func (mod *UpdateModule) Name() string {
35 return "update"
36 }
37
38 func (mod *UpdateModule) Description() string {
39 return "A module to check for bettercap's updates."
40 }
41
42 func (mod *UpdateModule) Author() string {
43 return "Simone Margaritelli <[email protected]>"
44 }
45
46 func (mod *UpdateModule) Configure() error {
47 return nil
48 }
49
50 func (mod *UpdateModule) Stop() error {
51 return nil
52 }
53
54 func (mod *UpdateModule) versionToNum(ver string) float64 {
55 if ver[0] == 'v' {
56 ver = ver[1:]
57 }
58
59 n := 0.0
60 parts := strings.Split(ver, ".")
61 nparts := len(parts)
62
63 // reverse
64 for i := nparts/2 - 1; i >= 0; i-- {
65 opp := nparts - 1 - i
66 parts[i], parts[opp] = parts[opp], parts[i]
67 }
68
69 for i, e := range parts {
70 ev, _ := strconv.Atoi(e)
71 n += float64(ev) * math.Pow10(i)
72 }
73
74 return n
75 }
76
77 func (mod *UpdateModule) Start() error {
78 return mod.SetRunning(true, func() {
79 defer mod.SetRunning(false, nil)
80
•81 mod.Info("this command is inactive in Debian.")
82 })
83 }