#include "../client.h" #include "../data_bucket.h" void command_databuckets(Client *c, const Seperator *sep) { if (sep->arg[1][0] == 0) { c->Message(Chat::Yellow, "Usage: #databuckets view (partial key)|(limit) OR #databuckets delete (key)"); return; } if (strcasecmp(sep->arg[1], "view") == 0) { std::string key_filter; uint8 limit = 50; for (int i = 2; i < 4; i++) { if (sep->arg[i][0] == '\0') { break; } if (strcasecmp(sep->arg[i], "limit") == 0) { limit = (uint8) atoi(sep->arg[i + 1]); continue; } } if (sep->arg[2]) { key_filter = Strings::ToLower(sep->arg[2]); } std::string query = "SELECT `id`, `key`, `value`, `expires` FROM data_buckets"; if (!key_filter.empty()) { query += StringFormat(" WHERE `key` LIKE '%%%s%%'", key_filter.c_str()); } query += StringFormat(" LIMIT %u", limit); auto results = database.QueryDatabase(query); if (!results.Success()) { return; } if (results.RowCount() == 0) { c->Message(Chat::Yellow, "No data_buckets found"); return; } int _ctr = 0; // put in window for easier readability in case want command line for something else std::string window_title = "Data Buckets"; std::string window_text = "
| ID | " "Expires | " "Key | " "Value | " "
| %u | " "%s | " "%s | " "%s | " "