Mercurial > irccd
comparison irccd-test/main.cpp @ 809:8460b4a34191
misc: reorganize namespaces, closes #952 @4h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 16 Nov 2018 12:25:00 +0100 |
parents | 2dfba38e93f0 |
children | 49fa22f0b4b9 |
comparison
equal
deleted
inserted
replaced
808:80bccab4a093 | 809:8460b4a34191 |
---|---|
34 | 34 |
35 #include <irccd/options.hpp> | 35 #include <irccd/options.hpp> |
36 #include <irccd/string_util.hpp> | 36 #include <irccd/string_util.hpp> |
37 | 37 |
38 #include <irccd/daemon/dynlib_plugin.hpp> | 38 #include <irccd/daemon/dynlib_plugin.hpp> |
39 #include <irccd/daemon/irccd.hpp> | 39 #include <irccd/daemon/bot.hpp> |
40 #include <irccd/daemon/plugin_service.hpp> | 40 #include <irccd/daemon/plugin_service.hpp> |
41 #include <irccd/daemon/server_service.hpp> | 41 #include <irccd/daemon/server_service.hpp> |
42 | 42 |
43 #include <irccd/test/debug_server.hpp> | 43 #include <irccd/test/debug_server.hpp> |
44 | 44 |
48 #endif | 48 #endif |
49 | 49 |
50 using boost::format; | 50 using boost::format; |
51 using boost::str; | 51 using boost::str; |
52 | 52 |
53 using irccd::string_util::split; | |
54 | |
55 using irccd::daemon::bot; | |
56 using irccd::daemon::names_event; | |
57 using irccd::daemon::plugin; | |
58 using irccd::daemon::server; | |
59 using irccd::daemon::whois_event; | |
60 using irccd::daemon::dynlib_plugin_loader; | |
61 | |
62 using irccd::js::js_plugin_loader; | |
63 using irccd::js::js_api; | |
64 | |
53 namespace irccd::test { | 65 namespace irccd::test { |
54 | 66 |
55 namespace su = string_util; | |
56 | |
57 namespace { | 67 namespace { |
58 | 68 |
59 boost::asio::io_service io; | 69 boost::asio::io_service io; |
60 | 70 |
61 std::unique_ptr<irccd> daemon; | 71 std::unique_ptr<bot> daemon; |
62 std::shared_ptr<plugin> plugin; | 72 std::shared_ptr<plugin> plugin; |
63 | 73 |
64 // {{{ function table | 74 // {{{ function table |
65 | 75 |
66 /* | 76 /* |
160 /* | 170 /* |
161 * onCommand server origin channel message | 171 * onCommand server origin channel message |
162 */ | 172 */ |
163 void on_command(const std::string& data) | 173 void on_command(const std::string& data) |
164 { | 174 { |
165 const auto args = su::split(data, " ", 4); | 175 const auto args = split(data, " ", 4); |
166 | 176 |
167 plugin->handle_command(*daemon, { | 177 plugin->handle_command(*daemon, { |
168 get_server(get_arg(args, 0)), | 178 get_server(get_arg(args, 0)), |
169 get_arg(args, 1), | 179 get_arg(args, 1), |
170 get_arg(args, 2), | 180 get_arg(args, 2), |
179 /* | 189 /* |
180 * onConnect server | 190 * onConnect server |
181 */ | 191 */ |
182 void on_connect(const std::string& data) | 192 void on_connect(const std::string& data) |
183 { | 193 { |
184 const auto args = su::split(data, " "); | 194 const auto args = split(data, " "); |
185 | 195 |
186 plugin->handle_connect(*daemon, {get_server(get_arg(args, 0))}); | 196 plugin->handle_connect(*daemon, {get_server(get_arg(args, 0))}); |
187 } | 197 } |
188 | 198 |
189 // }}} | 199 // }}} |
193 /* | 203 /* |
194 * onInvite server origin channel target | 204 * onInvite server origin channel target |
195 */ | 205 */ |
196 void on_invite(const std::string& data) | 206 void on_invite(const std::string& data) |
197 { | 207 { |
198 const auto args = su::split(data, " "); | 208 const auto args = split(data, " "); |
199 | 209 |
200 plugin->handle_invite(*daemon, { | 210 plugin->handle_invite(*daemon, { |
201 get_server(get_arg(args, 0)), | 211 get_server(get_arg(args, 0)), |
202 get_arg(args, 1), | 212 get_arg(args, 1), |
203 get_arg(args, 2), | 213 get_arg(args, 2), |
212 /* | 222 /* |
213 * onJoin server origin channel | 223 * onJoin server origin channel |
214 */ | 224 */ |
215 void on_join(const std::string& data) | 225 void on_join(const std::string& data) |
216 { | 226 { |
217 const auto args = su::split(data, " "); | 227 const auto args = split(data, " "); |
218 | 228 |
219 plugin->handle_join(*daemon, { | 229 plugin->handle_join(*daemon, { |
220 get_server(get_arg(args, 0)), | 230 get_server(get_arg(args, 0)), |
221 get_arg(args, 1), | 231 get_arg(args, 1), |
222 get_arg(args, 2) | 232 get_arg(args, 2) |
230 /* | 240 /* |
231 * onKick server origin channel reason | 241 * onKick server origin channel reason |
232 */ | 242 */ |
233 void on_kick(const std::string& data) | 243 void on_kick(const std::string& data) |
234 { | 244 { |
235 const auto args = su::split(data, " ", 5); | 245 const auto args = split(data, " ", 5); |
236 | 246 |
237 plugin->handle_kick(*daemon, { | 247 plugin->handle_kick(*daemon, { |
238 get_server(get_arg(args, 0)), | 248 get_server(get_arg(args, 0)), |
239 get_arg(args, 1), | 249 get_arg(args, 1), |
240 get_arg(args, 2), | 250 get_arg(args, 2), |
262 /* | 272 /* |
263 * onMe server origin channel message | 273 * onMe server origin channel message |
264 */ | 274 */ |
265 void on_me(const std::string& data) | 275 void on_me(const std::string& data) |
266 { | 276 { |
267 const auto args = su::split(data, " ", 4); | 277 const auto args = split(data, " ", 4); |
268 | 278 |
269 plugin->handle_me(*daemon, { | 279 plugin->handle_me(*daemon, { |
270 get_server(get_arg(args, 0)), | 280 get_server(get_arg(args, 0)), |
271 get_arg(args, 1), | 281 get_arg(args, 1), |
272 get_arg(args, 2), | 282 get_arg(args, 2), |
281 /* | 291 /* |
282 * onMessage server origin channel message | 292 * onMessage server origin channel message |
283 */ | 293 */ |
284 void on_message(const std::string& data) | 294 void on_message(const std::string& data) |
285 { | 295 { |
286 const auto args = su::split(data, " ", 4); | 296 const auto args = split(data, " ", 4); |
287 | 297 |
288 plugin->handle_message(*daemon, { | 298 plugin->handle_message(*daemon, { |
289 get_server(get_arg(args, 0)), | 299 get_server(get_arg(args, 0)), |
290 get_arg(args, 1), | 300 get_arg(args, 1), |
291 get_arg(args, 2), | 301 get_arg(args, 2), |
300 /* | 310 /* |
301 * onMode server origin channel mode limit user mask | 311 * onMode server origin channel mode limit user mask |
302 */ | 312 */ |
303 void on_mode(const std::string& data) | 313 void on_mode(const std::string& data) |
304 { | 314 { |
305 const auto args = su::split(data, " ", 7); | 315 const auto args = split(data, " ", 7); |
306 | 316 |
307 plugin->handle_mode(*daemon, { | 317 plugin->handle_mode(*daemon, { |
308 get_server(get_arg(args, 0)), | 318 get_server(get_arg(args, 0)), |
309 get_arg(args, 1), | 319 get_arg(args, 1), |
310 get_arg(args, 2), | 320 get_arg(args, 2), |
322 /* | 332 /* |
323 * onNames server channel nick1 nick2 nickN | 333 * onNames server channel nick1 nick2 nickN |
324 */ | 334 */ |
325 void on_names(const std::string& data) | 335 void on_names(const std::string& data) |
326 { | 336 { |
327 const auto args = su::split(data, " "); | 337 const auto args = split(data, " "); |
328 | 338 |
329 names_event ev; | 339 names_event ev; |
330 | 340 |
331 ev.server = get_server(get_arg(args, 0)); | 341 ev.server = get_server(get_arg(args, 0)); |
332 ev.channel = get_arg(args, 1); | 342 ev.channel = get_arg(args, 1); |
344 /* | 354 /* |
345 * onNick server origin nickname | 355 * onNick server origin nickname |
346 */ | 356 */ |
347 void on_nick(const std::string& data) | 357 void on_nick(const std::string& data) |
348 { | 358 { |
349 const auto args = su::split(data, " "); | 359 const auto args = split(data, " "); |
350 | 360 |
351 plugin->handle_nick(*daemon, { | 361 plugin->handle_nick(*daemon, { |
352 get_server(get_arg(args, 0)), | 362 get_server(get_arg(args, 0)), |
353 get_arg(args, 1), | 363 get_arg(args, 1), |
354 get_arg(args, 2) | 364 get_arg(args, 2) |
362 /* | 372 /* |
363 * onNotice server origin channel nickname | 373 * onNotice server origin channel nickname |
364 */ | 374 */ |
365 void on_notice(const std::string& data) | 375 void on_notice(const std::string& data) |
366 { | 376 { |
367 const auto args = su::split(data, " ", 4); | 377 const auto args = split(data, " ", 4); |
368 | 378 |
369 plugin->handle_notice(*daemon, { | 379 plugin->handle_notice(*daemon, { |
370 get_server(get_arg(args, 0)), | 380 get_server(get_arg(args, 0)), |
371 get_arg(args, 1), | 381 get_arg(args, 1), |
372 get_arg(args, 2), | 382 get_arg(args, 2), |
381 /* | 391 /* |
382 * onPart server origin channel reason | 392 * onPart server origin channel reason |
383 */ | 393 */ |
384 void on_part(const std::string& data) | 394 void on_part(const std::string& data) |
385 { | 395 { |
386 const auto args = su::split(data, " ", 4); | 396 const auto args = split(data, " ", 4); |
387 | 397 |
388 plugin->handle_part(*daemon, { | 398 plugin->handle_part(*daemon, { |
389 get_server(get_arg(args, 0)), | 399 get_server(get_arg(args, 0)), |
390 get_arg(args, 1), | 400 get_arg(args, 1), |
391 get_arg(args, 2), | 401 get_arg(args, 2), |
412 /* | 422 /* |
413 * onTopic server origin channel topic | 423 * onTopic server origin channel topic |
414 */ | 424 */ |
415 void on_topic(const std::string& data) | 425 void on_topic(const std::string& data) |
416 { | 426 { |
417 const auto args = su::split(data, " ", 4); | 427 const auto args = split(data, " ", 4); |
418 | 428 |
419 plugin->handle_topic(*daemon, { | 429 plugin->handle_topic(*daemon, { |
420 get_server(get_arg(args, 0)), | 430 get_server(get_arg(args, 0)), |
421 get_arg(args, 1), | 431 get_arg(args, 1), |
422 get_arg(args, 2), | 432 get_arg(args, 2), |
443 /* | 453 /* |
444 * onWhois server nick user host realname chan1 chan2 chanN | 454 * onWhois server nick user host realname chan1 chan2 chanN |
445 */ | 455 */ |
446 void on_whois(const std::string& data) | 456 void on_whois(const std::string& data) |
447 { | 457 { |
448 const auto args = su::split(data, " "); | 458 const auto args = split(data, " "); |
449 | 459 |
450 whois_event ev; | 460 whois_event ev; |
451 | 461 |
452 ev.server = get_server(get_arg(args, 0)); | 462 ev.server = get_server(get_arg(args, 0)); |
453 ev.whois.nick = get_arg(args, 1); | 463 ev.whois.nick = get_arg(args, 1); |
507 } | 517 } |
508 | 518 |
509 auto complete(EditLine* el, int) -> unsigned char | 519 auto complete(EditLine* el, int) -> unsigned char |
510 { | 520 { |
511 const auto* lf = el_line(el); | 521 const auto* lf = el_line(el); |
512 const auto args = su::split(std::string(lf->buffer, lf->cursor), " "); | 522 const auto args = split(std::string(lf->buffer, lf->cursor), " "); |
513 | 523 |
514 if (args.size() == 0U) | 524 if (args.size() == 0U) |
515 return CC_REFRESH; | 525 return CC_REFRESH; |
516 | 526 |
517 const auto found = matches(args[0]); | 527 const auto found = matches(args[0]); |
629 | 639 |
630 // {{{ load | 640 // {{{ load |
631 | 641 |
632 void load(int argc, char** argv) | 642 void load(int argc, char** argv) |
633 { | 643 { |
634 daemon = std::make_unique<irccd>(io); | 644 daemon = std::make_unique<bot>(io); |
635 daemon->plugins().add_loader(std::make_unique<dynlib_plugin_loader>()); | 645 daemon->plugins().add_loader(std::make_unique<dynlib_plugin_loader>()); |
636 | 646 |
637 #if defined(IRCCD_HAVE_JS) | 647 #if defined(IRCCD_HAVE_JS) |
638 auto loader = std::make_unique<js::js_plugin_loader>(*daemon); | 648 auto loader = std::make_unique<js_plugin_loader>(*daemon); |
639 | 649 |
640 for (const auto& f : js::js_api::registry) | 650 for (const auto& f : js_api::registry) |
641 loader->get_modules().push_back(f()); | 651 loader->get_modules().push_back(f()); |
642 | 652 |
643 daemon->plugins().add_loader(std::move(loader)); | 653 daemon->plugins().add_loader(std::move(loader)); |
644 #endif | 654 #endif |
645 | 655 |