Changeset 279:57864e38a85b
- Timestamp:
- 06/15/2008 03:17:34 PM (4 years ago)
- Author:
- Dmitry Nezhevenko <dion@…>
- Branch:
- default
- Message:
-
/global: Global aliases that can be accessed without "!" character
- Location:
- src/plugins/alias
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r0
|
r279
|
|
| 6 | 6 | |
| 7 | 7 | set (plugin_HDR |
| | 8 | alias.h |
| 8 | 9 | aliaslist.h |
| 9 | 10 | ) |
| 10 | 11 | |
| 11 | 12 | set (plugin_SRC |
| | 13 | alias.cpp |
| 12 | 14 | aliaslist.cpp |
| 13 | 15 | aliasplugin.cpp |
-
|
r260
|
r279
|
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | | int AliasList::append(const StorageKey& storage, const QString& name, const QString& value) |
| | 12 | int AliasList::append(const StorageKey& storage, const Alias& alias) |
| 13 | 13 | { |
| 14 | 14 | if (!storage.isValid()) |
| 15 | 15 | return 0; |
| 16 | 16 | QSqlQuery query=DataStorage::instance() |
| 17 | | ->prepareQuery("INSERT INTO aliases(plugin, storage, name, value) VALUES (?, ?, ?, ?)"); |
| | 17 | ->prepareQuery("INSERT INTO aliases(plugin, storage, global, name, value) VALUES (?, ?, ?, ?, ?)"); |
| 18 | 18 | query.addBindValue(storage.plugin()); |
| 19 | 19 | query.addBindValue(storage.storage()); |
| 20 | | query.addBindValue(name); |
| 21 | | query.addBindValue(value); |
| | 20 | query.addBindValue(alias.isGlobal()); |
| | 21 | query.addBindValue(alias.name()); |
| | 22 | query.addBindValue(alias.value()); |
| 22 | 23 | if (query.exec()) |
| 23 | 24 | return 1; |
| 24 | 25 | query.clear(); |
| 25 | | query.prepare("UPDATE aliases SET value=? WHERE plugin=? AND storage=? AND name=?"); |
| 26 | | query.addBindValue(value); |
| | 26 | query.prepare("UPDATE aliases SET global=?, value=? WHERE plugin=? AND storage=? AND name=?"); |
| | 27 | query.addBindValue(alias.isGlobal()); |
| | 28 | query.addBindValue(alias.value()); |
| 27 | 29 | query.addBindValue(storage.plugin()); |
| 28 | 30 | query.addBindValue(storage.storage()); |
| 29 | | query.addBindValue(name); |
| | 31 | query.addBindValue(alias.name()); |
| 30 | 32 | if (query.exec()) |
| 31 | 33 | return 2; |
| … |
… |
|
| 33 | 35 | } |
| 34 | 36 | |
| 35 | | QMap<QString,QString> AliasList::getAll(const StorageKey& storage) |
| | 37 | QMap<QString,Alias> AliasList::getAll(const StorageKey& storage) |
| 36 | 38 | { |
| 37 | | QMap<QString,QString> map; |
| | 39 | QMap<QString,Alias> map; |
| 38 | 40 | if (!storage.isValid()) |
| 39 | 41 | return map; |
| 40 | 42 | QSqlQuery query=DataStorage::instance() |
| 41 | | ->prepareQuery("SELECT name, value FROM aliases WHERE plugin=? AND storage=?"); |
| | 43 | ->prepareQuery("SELECT global, name, value FROM aliases WHERE plugin=? AND storage=?"); |
| 42 | 44 | query.addBindValue(storage.plugin()); |
| 43 | 45 | query.addBindValue(storage.storage()); |
| 44 | 46 | query.exec(); |
| 45 | 47 | while (query.next()) |
| 46 | | map[query.value(0).toString()]=query.value(1).toString(); |
| | 48 | { |
| | 49 | Alias alias(query.value(1).toString(),query.value(2).toString()); |
| | 50 | alias.setGlobal(query.value(0).toBool()); |
| | 51 | map[alias.name()]=alias; |
| | 52 | } |
| 47 | 53 | return map; |
| 48 | 54 | } |
| 49 | 55 | |
| 50 | | QString AliasList::get(const StorageKey& storage, const QString&name) |
| | 56 | Alias AliasList::get(const StorageKey& storage, const QString& name) |
| 51 | 57 | { |
| 52 | 58 | if (!storage.isValid()) |
| 53 | | return QString::null; |
| | 59 | return Alias(); |
| 54 | 60 | QSqlQuery query=DataStorage::instance() |
| 55 | | ->prepareQuery("SELECT value FROM aliases WHERE plugin=? AND storage=? AND name=?"); |
| | 61 | ->prepareQuery("SELECT global, value FROM aliases WHERE plugin=? AND storage=? AND name=?"); |
| 56 | 62 | query.addBindValue(storage.plugin()); |
| 57 | 63 | query.addBindValue(storage.storage()); |
| … |
… |
|
| 59 | 65 | query.exec(); |
| 60 | 66 | if (!query.next()) |
| 61 | | return QString::null; |
| 62 | | return query.value(0).toString(); |
| | 67 | return Alias(); |
| | 68 | Alias alias(name, query.value(1).toString()); |
| | 69 | alias.setGlobal(query.value(0).toBool()); |
| | 70 | return alias; |
| 63 | 71 | } |
| 64 | 72 | |
-
|
r260
|
r279
|
|
| 2 | 2 | #define ALIAS_LIST |
| 3 | 3 | |
| | 4 | #include "alias.h" |
| 4 | 5 | #include "base/config/storagekey.h" |
| 5 | 6 | |
| … |
… |
|
| 14 | 15 | AliasList(); |
| 15 | 16 | // 0 - err, 1 - added, 2 - updated |
| 16 | | int append(const StorageKey& storage, const QString& name, const QString& value); |
| 17 | | QMap<QString,QString> getAll(const StorageKey& storage); |
| 18 | | QString get(const StorageKey& storage, const QString&name); |
| | 17 | int append(const StorageKey& storage, const Alias& alias); |
| | 18 | QMap<QString,Alias> getAll(const StorageKey& storage); |
| | 19 | Alias get(const StorageKey& storage, const QString&name); |
| 19 | 20 | void clear(const StorageKey& storage); |
| 20 | 21 | int count(const StorageKey& storage); |
-
|
r233
|
r279
|
|
| 32 | 32 | if (s->hasAttribute("glooxbot_alias")) |
| 33 | 33 | return false; |
| 34 | | bool res=MessageParser(s,getMyNick(s)).isForMe(); |
| 35 | | return res; |
| | 34 | return true; |
| 36 | 35 | } |
| 37 | 36 | |
| … |
… |
|
| 44 | 43 | return parseCommands(s); |
| 45 | 44 | |
| 46 | | QString res=aliases.get(bot()->getStorage(s), cmd); |
| | 45 | Alias alias=aliases.get(bot()->getStorage(s), cmd); |
| | 46 | |
| | 47 | if (!parser.isForMe() && !alias.isGlobal()) |
| | 48 | { |
| | 49 | myShouldIgnoreError=1; |
| | 50 | return false; |
| | 51 | } |
| | 52 | |
| | 53 | QString res=alias.value(); |
| 47 | 54 | QString firstArg=res.section(' ',0,0).toUpper(); |
| 48 | 55 | |
| … |
… |
|
| 115 | 122 | { |
| 116 | 123 | QString res; |
| 117 | | QMap<QString, QString> all=aliases.getAll(bot()->getStorage(s)); |
| | 124 | QMap<QString, Alias> all=aliases.getAll(bot()->getStorage(s)); |
| 118 | 125 | int cnt=all.count(); |
| 119 | 126 | if (!cnt) |
| … |
… |
|
| 123 | 130 | } |
| 124 | 131 | for (int i=0; i<cnt; i++) |
| 125 | | res+=QString("\n%1) %2=%3").arg(i+1).arg(all.keys()[i].toLower()).arg(all.values()[i]); |
| | 132 | res+=QString("\n%1) %2%3=%4").arg(i+1).arg(all.values()[i].isGlobal() ? "[GLOBAL] ": "") |
| | 133 | .arg(all.keys()[i].toLower()).arg(all.values()[i].value()); |
| 126 | 134 | reply(s, QString("Aliases:%1").arg(res)); |
| 127 | 135 | return true; |
| … |
… |
|
| 129 | 137 | else |
| 130 | 138 | { |
| 131 | | QString value=aliases.get(bot()->getStorage(s),aliasName.toUpper()); |
| | 139 | Alias alias=aliases.get(bot()->getStorage(s),aliasName.toUpper()); |
| | 140 | QString value=alias.value(); |
| 132 | 141 | if (!value.isNull()) |
| 133 | | reply(s, QString("Alias: %1=%2").arg(aliasName).arg(value)); |
| | 142 | reply(s, QString("Alias: %1%2=%3").arg(alias.isGlobal() ? "[GLOBAL] " : "") |
| | 143 | .arg(aliasName).arg(value)); |
| 134 | 144 | else |
| 135 | 145 | reply(s, QString("No such alias: %1").arg(aliasName)); |
| … |
… |
|
| 154 | 164 | if (cmd=="ADD") |
| 155 | 165 | { |
| | 166 | bool global=false; |
| | 167 | const QString globalStr("/global "); |
| | 168 | if (value.toLower().startsWith(globalStr)) |
| | 169 | { |
| | 170 | global=true; |
| | 171 | value=value.remove(0,globalStr.length()).trimmed(); |
| | 172 | } |
| 156 | 173 | if (name.isEmpty() || value.isEmpty()) |
| 157 | 174 | { |
| … |
… |
|
| 161 | 178 | return true; |
| 162 | 179 | } |
| 163 | | int res=aliases.append(bot()->getStorage(s), name, value); |
| | 180 | Alias alias(name, value); |
| | 181 | alias.setGlobal(global); |
| | 182 | int res=aliases.append(bot()->getStorage(s), alias); |
| 164 | 183 | switch (res) |
| 165 | 184 | { |