muc_log.vala
author Stiletto <blasux@blasux.ru>
Mon, 05 Nov 2012 23:54:44 +0400
changeset 12 d3e36b368fc5
parent 9 d3260253f0bd
permissions -rw-r--r--
iq, commands, makefile up
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     1
using Gee;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     2
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     3
class ModuleMucLog : Module {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     4
    protected weak ModuleMuc muc;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     5
    protected HashMap<string,RoomLog> rooms;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     6
    class RoomLog : Object {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     7
        public string jid;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     8
        public string logpath;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     9
        public string filename;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    10
        protected weak ModuleMucLog muclog;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    11
        protected FileStream file;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    12
        public string getid(Time time) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    13
            return time.format("%s");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    14
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    15
        protected int lastday;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    16
        protected int lastyear;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    17
        protected int lastmonth;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    18
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    19
        public RoomLog(ModuleMucLog muclog, string jid) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    20
            this.jid = jid;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    21
            this.muclog = muclog;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    22
            logpath = muclog.getconf(jid, "log-path", null);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    23
            filename = null;
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    24
            write(Time.local(time_t()), "logstart", "", "Log started");
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    25
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    26
        ~RoomLog() {
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    27
            write(Time.local(time_t()), "logstop", "", "Log stopped");
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    28
        }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    29
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    30
        public static uint nick_hash(string s) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    31
            uint sum = 0;
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    32
            const uint k = 102, m = 54, l = 140;
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    33
            for( var j = 0, iTop = s.length; j < iTop; j++ ) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    34
                sum += k ^ s[j];
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    35
            }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    36
            return ((sum ^ m)+l)%10;
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    37
        }
12
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    38
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    39
        protected void real_write(Time time, string _class, string nick, string str) {
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    40
            var id = getid(time);
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    41
            var times = time.format("%H:%M:%S");
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    42
            var nicklass = (_class=="message") ? (" nick%u".printf(nick_hash(nick))) : "";
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    43
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    44
            file.printf("<tr id='l_%s' class='%s'><td class='time'><a id='i_%s' href='#i_%s'>%s</a></td>", id, _class, id, id, times);
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    45
            file.printf("<td class='nick%s'>%s</td><td class='text'>%s</td></tr>\n", nicklass, nick, str);
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    46
            file.flush();
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    47
        }
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    48
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    49
        public void write(Time time, string _class, string nick, string str) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    50
            if ((lastday != time.day)||(lastmonth != time.month)||(lastyear!=time.year)) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    51
                var fname = time.format(logpath).replace("<muc>",jid);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    52
                log("muc_log", LogLevelFlags.LEVEL_INFO, "Switching log file '%s' to '%s'", filename, fname);
12
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    53
                bool wasntnull = false;
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    54
                if (file!=null) {
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    55
                    wasntnull = true;
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    56
                    real_write(time, "logstop", "", "Log stopped. See you in the next episode.");
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    57
                }
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    58
                //try {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    59
                    file = FileStream.open(fname,"a");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    60
                if (file==null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    61
                    int start = 0;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    62
                    int length = fname.length;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    63
                    while (true) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    64
                        var pos = fname.index_of("/", start);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    65
                        if (pos==-1)
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    66
                            break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    67
                        stderr.printf("--------------------- %s\n", fname[0:pos]);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    68
                        Posix.mkdir(fname[0:pos],0777);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    69
                        start = pos+1;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    70
                    } 
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    71
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    72
                    file = FileStream.open(fname,"a");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    73
                    if (file == null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    74
                        log("muc_log", LogLevelFlags.LEVEL_WARNING, "Failed to create log file '%s'", fname);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    75
                        return;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    76
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    77
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    78
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    79
                if (file.tell()==0) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    80
                    var loghead = muclog.getconf(jid, "log-head",null);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    81
                    if (loghead!="null") {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    82
                        try {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    83
                            var headfile = new IOChannel.file(loghead,"r");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    84
                            string head;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    85
                            size_t length;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    86
                            headfile.read_to_end(out head, out length);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    87
                            headfile.shutdown(false);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    88
                            file.printf("%s\n", head.replace("<muc>",jid).replace("<date>",time.format("%d.%m.%Y")));
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    89
                        } catch (FileError fe) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    90
                            log("muc_log", LogLevelFlags.LEVEL_WARNING, "Failed to read head");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    91
                        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    92
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    93
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    94
                filename = fname;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    95
                lastyear = time.year; lastmonth = time.month; lastday = time.day;
12
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    96
                if (wasntnull)
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
    97
                    real_write(time, "logstart", "", "Log started. This soap opera will never end.");
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    98
            }
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
    99
12
d3e36b368fc5 iq, commands, makefile up
Stiletto <blasux@blasux.ru>
parents: 9
diff changeset
   100
            real_write(time, _class, nick, str);
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   101
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   102
            
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   103
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   104
    public string getconf(string jid, string key, string? def) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   105
        var res = cfg["muc "+jid, key];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   106
        if (res==null) res = cfg["muc", key];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   107
        if (res==null) res = def;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   108
        return res;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   109
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   110
    public ModuleMucLog(Config cfg, Connection conn) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   111
        base(cfg, conn);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   112
        rooms = new HashMap<string,RoomLog>();
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   113
        muc = null;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   114
        foreach (var module in conn.modules) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   115
            if (module.name()=="muc")
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   116
                muc = (ModuleMuc)module;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   117
        }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   118
        if (muc==null)
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   119
            log("muc_log", LogLevelFlags.LEVEL_ERROR, "Module 'muc' is not loaded");
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   120
        muc.state_changed.connect( (conf, olds, news, desc) => {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   121
            switch (news) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   122
                case ModuleMuc.State.CONNECTED:
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   123
                    if (getconf(conf.jid, "log", "no")=="yes") {
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   124
                        var room = new RoomLog(this, conf.jid); 
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   125
                        rooms[conf.jid] = room;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   126
                        var sb = new StringBuilder();
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   127
                        var notfirst = false;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   128
                        sb.append("Participants: ");
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   129
                        foreach (var occupant in conf.occupants.values) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   130
                            if (notfirst)
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   131
                                sb.append(", ");
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   132
                            else
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   133
                                notfirst=true;
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   134
                            sb.append(Markup.escape_text(occupant.nick).replace(" ","&nbsp;"));
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   135
                        }
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   136
                        room.write(Time.local(time_t()), "userlist", "", sb.str);
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   137
                    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   138
                    break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   139
                case ModuleMuc.State.DISCONNECTED:
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   140
                    rooms.unset(conf.jid);
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   141
                    break;
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   142
            }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   143
        });
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   144
        muc.on_message.connect( (conf, user, message, body) => {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   145
            if ((user!=null)&&(body!=null)&&(message.get_child("delay")==null)) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   146
                var room = rooms[conf.jid];
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   147
                if (room!=null) {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   148
                    var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   149
                    if (body.has_prefix("/me ")) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   150
                        room.write(Time.local(time_t()), "action", "*", nick+Markup.escape_text(body[3:body.length]).replace("\n","<br/>"));
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   151
                    } else
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   152
                        room.write(Time.local(time_t()), "message", nick, Markup.escape_text(body).replace("\n","<br/>"));
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   153
                }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   154
            }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   155
        });
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   156
        muc.on_join.connect( (conf, user) => {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   157
            var room = rooms[conf.jid];
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   158
            if (room!=null) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   159
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   160
                room.write(Time.local(time_t()), "join", "*", nick+" has joined the room");
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   161
            }
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   162
        });
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   163
        muc.on_part.connect( (conf, user, status) => {
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   164
            var room = rooms[conf.jid];
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   165
            if (room!=null) {
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   166
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
9
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   167
                room.write(Time.local(time_t()), "part", "*",
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   168
                    nick+" has left the room"+((status!=null) ? (": "+Markup.escape_text(status)) : ""));
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   169
            }
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   170
        });
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   171
        muc.on_nick.connect( (conf, user, prev) => {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   172
            var room = rooms[conf.jid];
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   173
            if (room!=null) {
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   174
                var nick = Markup.escape_text(user.nick).replace(" ","&nbsp;");
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   175
                var nickp = Markup.escape_text(prev).replace(" ","&nbsp;"); 
d3260253f0bd Moved nick colors to vala code
Stiletto <blasux@blasux.ru>
parents: 8
diff changeset
   176
                room.write(Time.local(time_t()), "nickchange", "*", nickp+" is now known as "+nick);
8
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   177
            }
dfd274c668f9 Join, part and participant list
Stiletto <blasux@blasux.ru>
parents: 4
diff changeset
   178
        });
3
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   179
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   180
    public override string name() {
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   181
        return "muc_log";
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   182
    }
dd7a02c6d476 muc log, updated example config
Stiletto <blasux@blasux.ru>
parents:
diff changeset
   183
}