forked from muesli/beehive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircbeefactory.go
287 lines (273 loc) · 6.96 KB
/
ircbeefactory.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
* Copyright (C) 2014-2017 Christian Muehlhaeuser
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
*/
package ircbee
import (
"github.com/muesli/beehive/bees"
)
// IrcBeeFactory is a factory for IrcBees.
type IrcBeeFactory struct {
bees.BeeFactory
}
// New returns a new Bee instance configured with the supplied options.
func (factory *IrcBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface {
bee := IrcBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
}
// ID returns the ID of this Bee.
func (factory *IrcBeeFactory) ID() string {
return "ircbee"
}
// Name returns the name of this Bee.
func (factory *IrcBeeFactory) Name() string {
return "IRC"
}
// Description returns the description of this Bee.
func (factory *IrcBeeFactory) Description() string {
return "Connects to IRC"
}
// Image returns the filename of an image for this Bee.
func (factory *IrcBeeFactory) Image() string {
return factory.ID() + ".png"
}
// LogoColor returns the preferred logo background color (used by the admin interface).
func (factory *IrcBeeFactory) LogoColor() string {
return "#ef3e56"
}
// Options returns the options available to configure this Bee.
func (factory *IrcBeeFactory) Options() []bees.BeeOptionDescriptor {
opts := []bees.BeeOptionDescriptor{
{
Name: "address",
Description: "Hostname of IRC server, eg: irc.example.org:6667",
Type: "address",
Mandatory: true,
},
{
Name: "nick",
Description: "Nickname to use for IRC",
Type: "string",
Default: "beehive",
Mandatory: true,
},
{
Name: "password",
Description: "Password to use to connect to IRC server",
Type: "password",
},
{
Name: "channels",
Description: "Which channels to join",
Type: "[]string",
Mandatory: true,
},
{
Name: "ssl",
Description: "Use SSL for IRC connection",
Default: false,
Type: "bool",
},
}
return opts
}
// Events describes the available events provided by this Bee.
func (factory *IrcBeeFactory) Events() []bees.EventDescriptor {
events := []bees.EventDescriptor{
{
Namespace: factory.Name(),
Name: "message",
Description: "A message was received over IRC, either in a channel or a private query",
Options: []bees.PlaceholderDescriptor{
{
Name: "text",
Description: "The message that was received",
Type: "string",
},
{
Name: "channel",
Description: "The channel the message was received in",
Type: "string",
},
{
Name: "user",
Description: "The user that sent the message",
Type: "string",
},
{
Name: "hostmask",
Description: "Hostmask of the user that sent the message",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "join",
Description: "A user joined a channel",
Options: []bees.PlaceholderDescriptor{
{
Name: "user",
Description: "The user that joined the channel",
Type: "string",
},
{
Name: "channel",
Description: "The channel the user joined",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "part",
Description: "A user left a channel",
Options: []bees.PlaceholderDescriptor{
{
Name: "user",
Description: "The user that left the channel",
Type: "string",
},
{
Name: "channel",
Description: "The channel the user left",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "quit",
Description: "A user quits",
Options: []bees.PlaceholderDescriptor{
{
Name: "user",
Description: "The user that quit",
Type: "string",
},
{
Name: "channel",
Description: "The channel where the quit was recognized",
Type: "string",
},
},
},
}
return events
}
// Actions describes the available actions provided by this Bee.
func (factory *IrcBeeFactory) Actions() []bees.ActionDescriptor {
actions := []bees.ActionDescriptor{
{
Namespace: factory.Name(),
Name: "send",
Description: "Sends a message to a channel or a private query",
Options: []bees.PlaceholderDescriptor{
{
Name: "channel",
Description: "Which channel to send the message to",
Type: "string",
Mandatory: true,
},
{
Name: "text",
Description: "Content of the message",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "notice",
Description: "Sends a notice to a channel or a private query",
Options: []bees.PlaceholderDescriptor{
{
Name: "channel",
Description: "Which channel to send the message to",
Type: "string",
Mandatory: true,
},
{
Name: "text",
Description: "Content of the message",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "join",
Description: "Joins a channel",
Options: []bees.PlaceholderDescriptor{
{
Name: "channel",
Description: "Channel to join",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "part",
Description: "Parts a channel",
Options: []bees.PlaceholderDescriptor{
{
Name: "channel",
Description: "Channel to part",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "kick",
Description: "Kicks a user from a channel",
Options: []bees.PlaceholderDescriptor{
{
Name: "user",
Description: "User to kick",
Type: "string",
Mandatory: true,
},
{
Name: "channel",
Description: "Channel to kick from",
Type: "string",
Mandatory: true,
},
{
Name: "message",
Description: "Kick message",
Type: "string",
},
},
},
}
return actions
}
func init() {
f := IrcBeeFactory{}
bees.RegisterFactory(&f)
}