1 /**
2 Copyright 2018 Mark Fisher
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in 
5 the Software without restriction, including without limitation the rights to 
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
7 of the Software, and to permit persons to whom the Software is furnished to do 
8 so, subject to the following conditions:
9 The above copyright notice and this permission notice shall be included in all 
10 copies or substantial portions of the Software.
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
14 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
15 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
16 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
17 SOFTWARE.
18 **/
19 module dxx.services.net.irc;
20 
21 import ircbod.client, ircbod.message;
22 
23 import dxx.util;
24 
25 class IRCClientService : SyncNotificationSource {
26 
27     IRCClient bot;
28     this() {
29         bot = new IRCClient("irc.freenode.net", 6667, "ircbod", null, ["#ircbod"]);
30     //}
31     //void bot(string[] args)
32     //{
33         //bot.on(IRCMessage.Type.MESSAGE, r"^hello (\S+)$", (msg, args) {
34         //    msg.reply("Hello to you, too " ~ msg.nickname ~ "! You greeted: " ~ args[0]);
35         //});
36         //
37         bot.on(IRCMessage.Type.PRIV_MESSAGE, r"^!quit$", (msg) {
38             msg.reply("Yes, master.");
39             bot.broadcast("My master told me to quit. Bye!");
40             bot.quit();
41         });
42 
43         bot.on(IRCMessage.Type.JOIN, (msg) {
44 //            writeln("User joined: ", msg.nickname);
45             if(msg.nickname != bot.name)
46                 msg.reply("Welcome to the channel, " ~ msg.nickname);
47         });
48 
49         bot.on(IRCMessage.Type.CHAN_MESSAGE, (msg) {
50 //            writeln("got chan message: ", msg.text);
51         });
52 
53         bot.on(IRCMessage.Type.PRIV_MESSAGE, (msg) {
54 //            writeln("got private message: ", msg.text);
55         });
56     
57         bot.run();
58 }
59 }