1
1
package main
2
2
3
3
import (
4
- "encoding/json"
5
- "fmt"
6
4
"os"
7
5
"strings"
8
6
9
- "github.com/cooper/quiki/wiki"
10
7
"github.com/cooper/quiki/wikifier"
11
8
hbot "github.com/whyrusleeping/hellabot"
12
9
)
@@ -37,7 +34,7 @@ func main() {
37
34
38
35
// warnings
39
36
for _ , warning := range page .Warnings {
40
- reply += "\n Warning " + warning .Position .String () + ": " + warning .Message
37
+ reply += "\n Warning " + warning .Position .String () + " " + warning .Message
41
38
}
42
39
43
40
// css
@@ -47,9 +44,10 @@ func main() {
47
44
48
45
// keywords
49
46
if kw := page .Keywords (); len (kw ) != 0 {
50
- reply += "\n \n Keywords:\n " + strings .Join (kw , ", " )
47
+ reply += "\n \n Keywords: " + strings .Join (kw , ", " )
51
48
}
52
49
50
+ // reply
53
51
for _ , line := range strings .Split (reply , "\n " ) {
54
52
irc .Send ("PRIVMSG " + mes .To + " :" + line )
55
53
}
@@ -58,142 +56,5 @@ func main() {
58
56
},
59
57
})
60
58
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 ()
199
60
}
0 commit comments