Changeset 207:09e1aad6ac77

Show
Ignore:
Timestamp:
05/12/2008 07:49:55 PM (4 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

!word: list of all known words

Location:
src/plugins/word
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/plugins/word/wordlist.cpp

    r140 r207  
    116116                return 0; 
    117117        QSqlQuery query=DataStorage::instance() 
    118                 ->prepareQuery("SELECT COUNT(DISTINCTROW name) FROM words WHERE plugin=? AND storage=?"); 
     118                ->prepareQuery("SELECT COUNT(*) FROM (SELECT name FROM words WHERE plugin=1 AND storage=1 GROUP BY NAME) AS ul"); 
    119119        query.addBindValue(storage[0]); 
    120120        query.addBindValue(storage[1]); 
     
    138138} 
    139139 
     140QStringList WordList::getNames(const QList<int>& storage) 
     141{ 
     142        if (storage.count()!=2) 
     143                return QStringList(); 
     144        QSqlQuery query=DataStorage::instance() 
     145                ->prepareQuery("select name from words where plugin=? and storage=? group by name ORDER BY name"); 
     146        query.addBindValue(storage[0]); 
     147        query.addBindValue(storage[1]); 
     148        if (!query.exec()) 
     149                return QStringList(); 
     150        QStringList res; 
     151        while (query.next()) 
     152                res.append(query.value(0).toString()); 
     153        return res; 
     154} 
  • src/plugins/word/wordlist.h

    r11 r207  
    1717        int count(const QList<int>& storage); 
    1818        bool remove(const QList<int>& storage, const QString& name); 
     19        QStringList getNames(const QList<int>& storage); 
    1920}; 
    2021 
  • src/plugins/word/wordplugin.cpp

    r199 r207  
    1010        BasePlugin(parent) 
    1111{ 
    12         commands << "ADD" << "COUNT" << "CLEAR" << "SHOW" << "SHOWPRIV" << "SHOWJID" << "DEL"; 
     12        commands << "ADD" << "COUNT" << "NAMES" << "CLEAR" << "SHOW" << "SHOWPRIV" << "SHOWJID" << "DEL"; 
    1313} 
    1414 
     
    2727        { 
    2828                reply(s, QString("Currently I know %1 words").arg(words.count(bot()->getStorage(s)))); 
     29                return true; 
     30        } 
     31         
     32        if (cmd=="NAMES") 
     33        { 
     34                QStringList list=words.getNames(bot()->getStorage(s)); 
     35                if (list.isEmpty()) 
     36                        reply(s,"I don't know any words"); 
     37                else 
     38                        reply(s, QString("I know followed words: %1").arg(list.join(", "))); 
    2939                return true; 
    3040        }