Changeset 415:c17256e1dc79

Show
Ignore:
Timestamp:
06/21/2010 03:18:21 PM (20 months ago)
Author:
Sidgyck <sidgyck@…>
Branch:
default
Message:

[NEW]: "!muc visits[ex] [from] [to]" show conference visits

Location:
src/plugins/muc
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/plugins/muc/conference.cpp

    r414 r415  
    156156        myVisitor->removeExpired(); 
    157157        myModerator->removeExpired(); 
     158} 
     159 
     160QStringList  
     161Conference::visits(const QDateTime& from, const QDateTime& to, bool ext, int limit) 
     162{ 
     163        QSqlQuery query=DataStorage::instance() 
     164                ->prepareQuery("SELECT nick, lastaction FROM conference_nicks WHERE conference_id=? " 
     165                                "AND lastaction BETWEEN ? AND ? ORDER BY lastaction LIMIT ?"); 
     166        query.addBindValue(id()); 
     167        query.addBindValue(from); 
     168        query.addBindValue(to); 
     169        query.addBindValue(limit); 
     170 
     171        QStringList list; 
     172        if (!query.exec()) 
     173                return list; 
     174 
     175        while (query.next()) 
     176        { 
     177                list.append((ext) ? query.value(0).toString()+" (" 
     178                            + query.value(1).toDateTime().toString("dd.MM.yyyy HH:mm") 
     179                            + ")" : query.value(0).toString()); 
     180        } 
     181        return list; 
    158182} 
    159183 
  • src/plugins/muc/conference.h

    r414 r415  
    4444        QString seen(const QString& nick, bool ext = false, bool byjid = false); 
    4545        QString clientStat(); 
     46        QStringList visits(const QDateTime& from, const QDateTime& to, bool ext = false, int limit = 100); 
    4647        void setNick(const QString& name); 
    4748        void setLazyLeave(bool value); 
  • src/plugins/muc/mucplugin.cpp

    r414 r415  
    4242        commands << "REPORT" << "MISSING" << "STAT"; 
    4343 
    44         commands << "POKE" << "REALJID" << "INVITE" << "CLEAN" << "TOPIC"; 
     44        commands << "POKE" << "REALJID" << "INVITE" << "CLEAN" << "TOPIC" << "VISITS"; 
    4545        pluginId=1; 
    4646 
     
    631631                myShouldIgnoreError=1; 
    632632                return false; 
     633        } 
     634 
     635        if (cmd=="VISITS" || cmd=="VISITSEX") 
     636        { 
     637                Conference* conf = getConf(s); 
     638                if (!conf) { 
     639                        reply(s, "You are not in conference!"); 
     640                        return true; 
     641                } 
     642                QString arg2 = parser.nextToken(); 
     643                QStringList list; 
     644                QDateTime from = QDateTime::fromString(arg, Qt::ISODate); 
     645                QDateTime to   = QDateTime::fromString(arg2, Qt::ISODate); 
     646                if (!to.isValid()) 
     647                        to = QDateTime::currentDateTime(); 
     648                if (!from.isValid()) 
     649                        from = QDateTime(to.date()); 
     650 
     651                if (from > to) 
     652                { 
     653                        QDateTime tmp = from; 
     654                        from = to; 
     655                        to   = tmp; 
     656                } 
     657                list = conf->visits(from, to, cmd.endsWith("EX")); 
     658                reply(s, QString("over the past %1 there was %2 user%3: %4") 
     659                      .arg(secsToString(from.secsTo(to))) 
     660                      .arg( list.count() ) 
     661                      .arg( list.count() > 1 ?"s":"" ) 
     662                      .arg( list.join(", ")) ); 
     663                return true; 
    633664        } 
    634665