mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Convert admin to the new CModCommand interface
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -31,36 +31,7 @@ class CAdminMod : public CModule {
|
|||||||
using CModule::PutModule;
|
using CModule::PutModule;
|
||||||
|
|
||||||
void PrintHelp(const CString&) {
|
void PrintHelp(const CString&) {
|
||||||
CTable CmdTable;
|
HandleHelpCommand();
|
||||||
CmdTable.AddColumn("Command");
|
|
||||||
CmdTable.AddColumn("Arguments");
|
|
||||||
CmdTable.AddColumn("Description");
|
|
||||||
static const char* help[][3] = {
|
|
||||||
{"Get", "variable [username]", "Prints the variable's value for the given or current user"},
|
|
||||||
{"Set", "variable username value", "Sets the variable's value for the given user (use $me for the current user)"},
|
|
||||||
{"GetChan", "variable [username] chan", "Prints the variable's value for the given channel"},
|
|
||||||
{"SetChan", "variable username chan value", "Sets the variable's value for the given channel"},
|
|
||||||
{"ListUsers", "", "Lists users"},
|
|
||||||
{"AddUser", "username password [ircserver]", "Adds a new user"},
|
|
||||||
{"DelUser", "username", "Deletes a user"},
|
|
||||||
{"CloneUser", "oldusername newusername", "Clones a user"},
|
|
||||||
{"AddServer", "[username] server", "Adds a new IRC server for the given or current user"},
|
|
||||||
{"Reconnect", "username", "Cycles the user's IRC server connection"},
|
|
||||||
{"Disconnect", "username", "Disconnects the user from their IRC server"},
|
|
||||||
{"LoadModule", "username modulename", "Loads a Module for a user"},
|
|
||||||
{"UnLoadModule", "username modulename", "Removes a Module of a user"},
|
|
||||||
{"ListMods", "username", "Get the list of modules for a user"},
|
|
||||||
{"ListCTCPs", "username", "List the configured CTCP replies"},
|
|
||||||
{"AddCTCP", "username ctcp [reply]", "Configure a new CTCP reply"},
|
|
||||||
{"DelCTCP", "username ctcp", "Remove a CTCP reply"}
|
|
||||||
};
|
|
||||||
for (unsigned int i = 0; i != ARRAY_SIZE(help); ++i) {
|
|
||||||
CmdTable.AddRow();
|
|
||||||
CmdTable.SetCell("Command", help[i][0]);
|
|
||||||
CmdTable.SetCell("Arguments", help[i][1]);
|
|
||||||
CmdTable.SetCell("Description", help[i][2]);
|
|
||||||
}
|
|
||||||
PutModule(CmdTable);
|
|
||||||
|
|
||||||
PutModule("The following variables are available when using the Set/Get commands:");
|
PutModule("The following variables are available when using the Set/Get commands:");
|
||||||
|
|
||||||
@@ -860,45 +831,47 @@ class CAdminMod : public CModule {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (CAdminMod::* fn)(const CString&);
|
|
||||||
typedef std::map<CString, fn> function_map;
|
|
||||||
function_map fnmap_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MODCONSTRUCTOR(CAdminMod) {
|
MODCONSTRUCTOR(CAdminMod) {
|
||||||
fnmap_["help"] = &CAdminMod::PrintHelp;
|
AddCommand("Help", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::PrintHelp),
|
||||||
fnmap_["get"] = &CAdminMod::Get;
|
"", "Generates this output");
|
||||||
fnmap_["set"] = &CAdminMod::Set;
|
AddCommand("Get", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::Get),
|
||||||
fnmap_["getchan"] = &CAdminMod::GetChan;
|
"variable [username]", "Prints the variable's value for the given or current user");
|
||||||
fnmap_["setchan"] = &CAdminMod::SetChan;
|
AddCommand("Set", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::Set),
|
||||||
fnmap_["listusers"] = &CAdminMod::ListUsers;
|
"variable username value", "Sets the variable's value for the given user (use $me for the current user)");
|
||||||
fnmap_["adduser"] = &CAdminMod::AddUser;
|
AddCommand("GetChan", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::GetChan),
|
||||||
fnmap_["deluser"] = &CAdminMod::DelUser;
|
"variable [username] chan", "Prints the variable's value for the given channel");
|
||||||
fnmap_["cloneuser"] = &CAdminMod::CloneUser;
|
AddCommand("SetChan", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::SetChan),
|
||||||
fnmap_["addserver"] = &CAdminMod::AddServer;
|
"variable username chan value", "Sets the variable's value for the given channel");
|
||||||
fnmap_["reconnect"] = &CAdminMod::ReconnectUser;
|
AddCommand("ListUsers", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListUsers),
|
||||||
fnmap_["disconnect"] = &CAdminMod::DisconnectUser;
|
"", "Lists users");
|
||||||
fnmap_["loadmodule"] = &CAdminMod::LoadModuleForUser;
|
AddCommand("AddUser", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::AddUser),
|
||||||
fnmap_["unloadmodule"] = &CAdminMod::UnLoadModuleForUser;
|
"username password [ircserver]", "Adds a new user");
|
||||||
fnmap_["listmods"] = &CAdminMod::ListModuleForUser;
|
AddCommand("DelUser", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::DelUser),
|
||||||
fnmap_["listctcps"] = &CAdminMod::ListCTCP;
|
"username", "Deletes a user");
|
||||||
fnmap_["addctcp"] = &CAdminMod::AddCTCP;
|
AddCommand("CloneUser", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::CloneUser),
|
||||||
fnmap_["delctcp"] = &CAdminMod::DelCTCP;
|
"oldusername newusername", "Clones a user");
|
||||||
|
AddCommand("AddServer", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::AddServer),
|
||||||
|
"[username] server", "Adds a new IRC server for the given or current user");
|
||||||
|
AddCommand("Reconnect", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ReconnectUser),
|
||||||
|
"username", "Cycles the user's IRC server connection");
|
||||||
|
AddCommand("Disconnect", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::DisconnectUser),
|
||||||
|
"username", "Disconnects the user from their IRC server");
|
||||||
|
AddCommand("LoadModule", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::LoadModuleForUser),
|
||||||
|
"username modulename", "Loads a Module for a user");
|
||||||
|
AddCommand("UnLoadModule", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::UnLoadModuleForUser),
|
||||||
|
"username modulename", "Removes a Module of a user");
|
||||||
|
AddCommand("ListMods", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListModuleForUser),
|
||||||
|
"username", "Get the list of modules for a user");
|
||||||
|
AddCommand("ListCTCPs", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::ListCTCP),
|
||||||
|
"username", "List the configured CTCP replies");
|
||||||
|
AddCommand("AddCTCP", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::AddCTCP),
|
||||||
|
"username ctcp [reply]", "Configure a new CTCP reply");
|
||||||
|
AddCommand("DelCTCP", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::DelCTCP),
|
||||||
|
"username ctcp", "Remove a CTCP reply");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~CAdminMod() {}
|
virtual ~CAdminMod() {}
|
||||||
|
|
||||||
virtual void OnModCommand(const CString& sLine) {
|
|
||||||
if (!m_pUser)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const CString cmd = sLine.Token(0).AsLower();
|
|
||||||
function_map::iterator it = fnmap_.find(cmd);
|
|
||||||
if (it != fnmap_.end())
|
|
||||||
(this->*it->second)(sLine);
|
|
||||||
else
|
|
||||||
PutModule("Unknown command");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MODULEDEFS(CAdminMod, "Dynamic configuration of users/settings through IRC")
|
MODULEDEFS(CAdminMod, "Dynamic configuration of users/settings through IRC")
|
||||||
|
|||||||
Reference in New Issue
Block a user