D Paste by Chris Miller
Description: IRC client example; dirclib + splat
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
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  
import irclib.all, irclib.splatclient, splat;
import std.random, std.string, std.stdio;

class IrcBot: SplatIrcClient
{
    this(char[] server, ushort port = 6667)
    {
        super(server, port);
    }
    
    
    protected override void onLoggedIn()
    {
        writefln("Logged in");
        sendLine("JOIN #dbot");
    }
    
    
    protected override void onChannelMessageReceived(IrcChannelMessage imsg)
    {
        writefln("<%s> %s", imsg.fromNick, imsg.message);
    }
    
    
    protected override void onChannelActionReceived(IrcChannelMessage imsg)
    {
        writefln("* %s %s", imsg.fromNick, imsg.message);
    }
}

void main()
{
    auto ircbot = new IrcBot("irc.freenode.net", 6667);
    ircbot.nick = "splatbot" ~ std.string.toString(std.random.rand() % 1000);
    
    ircbot.connect();
    
    splat.run();
}

Replies:
Reply by Chris Miller

Reply by Anonymous
The above code is Phobos-only.

Reply by Anonymous
Here is an updated example that works on both Phobos and Tango: http://paste.dprogramming.com/dpoav42y

Reply by patrik
iMEPRE jr39ug7djalfgpitg94gbvm

    (some replies deleted)