Skip to content

Commit a7a4747

Browse files
committed
clean up irc.go
1 parent 21a23ad commit a7a4747

File tree

1 file changed

+4
-143
lines changed

1 file changed

+4
-143
lines changed

irc/irc.go

+4-143
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package main
22

33
import (
4-
"encoding/json"
5-
"fmt"
64
"os"
75
"strings"
86

9-
"github.com/cooper/quiki/wiki"
107
"github.com/cooper/quiki/wikifier"
118
hbot "github.com/whyrusleeping/hellabot"
129
)
@@ -37,7 +34,7 @@ func main() {
3734

3835
// warnings
3936
for _, warning := range page.Warnings {
40-
reply += "\nWarning " + warning.Position.String() + ": " + warning.Message
37+
reply += "\nWarning " + warning.Position.String() + " " + warning.Message
4138
}
4239

4340
// css
@@ -47,9 +44,10 @@ func main() {
4744

4845
// keywords
4946
if kw := page.Keywords(); len(kw) != 0 {
50-
reply += "\n\nKeywords:\n" + strings.Join(kw, ", ")
47+
reply += "\n\nKeywords: " + strings.Join(kw, ", ")
5148
}
5249

50+
// reply
5351
for _, line := range strings.Split(reply, "\n") {
5452
irc.Send("PRIVMSG " + mes.To + " :" + line)
5553
}
@@ -58,142 +56,5 @@ func main() {
5856
},
5957
})
6058

61-
mybot.AddTrigger(hbot.Trigger{
62-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
63-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".unique")
64-
},
65-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
66-
// line := strings.TrimLeft(strings.TrimPrefix(mes.Content, "quiku"), " ,:")
67-
68-
f, err := wikifier.UniqueFilesInDir("../standalone/", []string{"page"}, false)
69-
reply := fmt.Sprintf("err(%v) %v", err, f)
70-
71-
for _, line := range strings.Split(reply, "\n") {
72-
irc.Send("PRIVMSG " + mes.To + " :" + line)
73-
}
74-
75-
return false
76-
},
77-
})
78-
79-
mybot.AddTrigger(hbot.Trigger{
80-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
81-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".confvars")
82-
},
83-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
84-
w, err := wiki.NewWiki("../wikis/mywiki")
85-
86-
var reply string
87-
if err != nil {
88-
reply = err.Error()
89-
} else {
90-
reply = fmt.Sprintf("%+v", w.Opt)
91-
}
92-
93-
for _, line := range strings.Split(reply, "\n") {
94-
irc.Send("PRIVMSG " + mes.To + " :" + line)
95-
}
96-
97-
return false
98-
},
99-
})
100-
101-
mybot.AddTrigger(hbot.Trigger{
102-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
103-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".pageinfo")
104-
},
105-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
106-
var reply string
107-
page := wikifier.NewPage("../wikis/mywiki/pages/wikifier.page")
108-
109-
// parse
110-
if err := page.Parse(); err != nil {
111-
reply = err.Error()
112-
} else {
113-
val := page.Info()
114-
reply = fmt.Sprintf("%+v", val)
115-
}
116-
117-
for _, line := range strings.Split(reply, "\n") {
118-
irc.Send("PRIVMSG " + mes.To + " :" + line)
119-
}
120-
121-
return false
122-
},
123-
})
124-
125-
mybot.AddTrigger(hbot.Trigger{
126-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
127-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".displaypage")
128-
},
129-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
130-
var reply string
131-
w, err := wiki.NewWiki("../wikis/mywiki")
132-
133-
if err != nil {
134-
reply = err.Error()
135-
} else {
136-
j, _ := json.Marshal(w.DisplayPage("wikifier.page"))
137-
reply = fmt.Sprintf("%+v", string(j))
138-
}
139-
140-
for _, line := range strings.Split(reply, "\n") {
141-
irc.Send("PRIVMSG " + mes.To + " :" + line)
142-
}
143-
144-
return false
145-
},
146-
})
147-
148-
mybot.AddTrigger(hbot.Trigger{
149-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
150-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".displayimage")
151-
},
152-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
153-
line := strings.TrimLeft(strings.TrimPrefix(mes.Content, ".displayimage"), " ,:")
154-
155-
var reply string
156-
w, err := wiki.NewWiki("../wikis/mywiki")
157-
158-
if err != nil {
159-
reply = err.Error()
160-
} else {
161-
res := w.DisplayImage(line)
162-
reply = fmt.Sprintf("%+v", res)
163-
}
164-
165-
for _, line := range strings.Split(reply, "\n") {
166-
irc.Send("PRIVMSG " + mes.To + " :" + line)
167-
}
168-
169-
return false
170-
},
171-
})
172-
173-
mybot.AddTrigger(hbot.Trigger{
174-
Condition: func(bot *hbot.Bot, mes *hbot.Message) bool {
175-
return mes.Command == "PRIVMSG" && strings.HasPrefix(mes.Content, ".names ")
176-
},
177-
Action: func(irc *hbot.Bot, mes *hbot.Message) bool {
178-
pageName := strings.TrimPrefix(mes.Content, ".names ")
179-
w, _ := wiki.NewWiki("../wikis/mywiki")
180-
page := w.FindPage(pageName)
181-
reply := fmt.Sprintf("%+v", struct {
182-
Name, NameNE, RelName, RelNameNE, Path, RelPath string
183-
}{
184-
Name: page.Name(),
185-
NameNE: page.NameNE(),
186-
RelName: page.RelName(),
187-
RelNameNE: page.RelNameNE(),
188-
Path: page.Path(),
189-
RelPath: page.RelPath(),
190-
})
191-
for _, line := range strings.Split(reply, "\n") {
192-
irc.Send("PRIVMSG " + mes.To + " :" + line)
193-
}
194-
return false
195-
},
196-
})
197-
198-
mybot.Run() // Blocks until exit
59+
mybot.Run()
19960
}

0 commit comments

Comments
 (0)