D Paste by Chris Miller
Description: IRC client example; dirclib + splat (Phobos and Tango)
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  
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  
import irclib.all, irclib.splatclient, splat;

version(Tango)
{
    import tango.stdc.stdio, tango.math.Random;
    
    char[] uitostr(uint ui) { char[16] buf; return tango.text.convert.Integer.format!(char, uint)(buf, ui).dup; }
    uint randnum() { return tango.math.Random.Random.shared.next(); }
}
else
{
    import std.c.stdio, std.string, std.random;
    
    alias std.string.toString uitostr;
    alias std.random.rand randnum;
}


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

void main()
{
    auto ircbot = new IrcBot("irc.freenode.net", 6667);
    ircbot.nick = "splatt" ~ uitostr(randnum() % 1000);
    with(new Timer())
    {
        interval = 2500;
        start();
    }
    
    ircbot.connect();
    
    splat.run();
}

Replies:
Reply by Anonymous
Here is the old Phobos-only version of the above example code: http://paste.dprogramming.com/dpqp3zwm.php

Reply by Anonymous
ourrznocoahptdhaugrhkiytaljleg

    (some replies deleted)