diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 014c9ff..59b89a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,7 @@ int main(int argc, char **argv) //Video video(500, 500, "https://www.youtube.com/watch?v=bs0-EX9mJmg"); Cache cache; + Cache::loadBindsFromFile(); Channel offlineChannel("Offline"); ChannelSidePanel::addChannel(&offlineChannel); @@ -422,6 +423,87 @@ int main(int argc, char **argv) printf("UI scaling set to %f\n", scaling); }); + Command::add("addbind", [](const vector<string> &args) + { + if(args.size() != 2) + { + string errMsg = "Expected 2 arguments for command addbind, got %u argument("; + errMsg += to_string(args.size()); + errMsg += ")"; + Channel::getCurrent()->addLocalMessage(errMsg, Channel::getCurrent()->getSystemUser()); + return; + } + + string key = ":"; + key += args[0]; + key += ":"; + + if(key.size() > 255) + { + // 253 = bind + two colons + Channel::getCurrent()->addLocalMessage("Bind is too long. Max size is 253 bytes", Channel::getCurrent()->getSystemUser()); + return; + } + + bool bindAdded = Chatbar::addBind(key, args[1]); + if(bindAdded) + Channel::getCurrent()->addLocalMessage("Bind added", Channel::getCurrent()->getSystemUser()); + else + Channel::getCurrent()->addLocalMessage("Bind already exists. Remove it first if you want to replace it", Channel::getCurrent()->getSystemUser()); + }); + + Command::add("removebind", [](const vector<string> &args) + { + if(args.size() != 1) + { + string errMsg = "Expected 1 argument for command removebind, got %u argument("; + errMsg += to_string(args.size()); + errMsg += ")"; + Channel::getCurrent()->addLocalMessage(errMsg, Channel::getCurrent()->getSystemUser()); + return; + } + + string key = ":"; + key += args[0]; + key += ":"; + + if(key.size() > 255) + { + // 253 = bind + two colons + Channel::getCurrent()->addLocalMessage("Bind is too long. Max size is 253 bytes", Channel::getCurrent()->getSystemUser()); + return; + } + + bool bindRemoved = Chatbar::removeBind(key); + if(bindRemoved) + Channel::getCurrent()->addLocalMessage("Bind removed", Channel::getCurrent()->getSystemUser()); + else + Channel::getCurrent()->addLocalMessage("Bind doesn't exist, nothing was removed", Channel::getCurrent()->getSystemUser()); + }); + + Command::add("binds", [](const vector<string> &args) + { + if(args.size() != 0) + { + string errMsg = "Expected 0 arguments for command removebind, got %u argument("; + errMsg += to_string(args.size()); + errMsg += ")"; + Channel::getCurrent()->addLocalMessage(errMsg, Channel::getCurrent()->getSystemUser()); + return; + } + + string msg = "Binds:"; + auto binds = Chatbar::getBinds(); + for(auto &bind : binds) + { + msg += "\n"; + msg += bind.first; + msg += " "; + msg += bind.second; + } + Channel::getCurrent()->addLocalMessage(msg, Channel::getCurrent()->getSystemUser()); + }); + // Get username and id (public key) Command::add("whoami", [¤tUserKeyPair, ¤tUserName](const vector<string> &args) { |