mirror of
https://github.com/anope/anope.git
synced 2026-07-09 20:03:13 +02:00
Fixed up cs_set_misc and ns_set_misc
This commit is contained in:
@@ -57,28 +57,11 @@ cs_entrymsg
|
||||
* cs_set_misc
|
||||
*
|
||||
* Allows you to create misc /chanserv set commands, and have the data
|
||||
* show up in /chanserv info
|
||||
* show up in /chanserv info.
|
||||
*/
|
||||
module { name = "cs_set_misc" }
|
||||
cs_set_misc
|
||||
{
|
||||
/* The name of the command */
|
||||
name = "OINFO"
|
||||
/* A short description of the command */
|
||||
desc = "Associate oper only information to this channel"
|
||||
/* Set to yes if only opers and privileged users can set it and see it */
|
||||
privileged = yes
|
||||
}
|
||||
cs_set_misc
|
||||
{
|
||||
name = "URL"
|
||||
desc = "Associate a URL with the channel"
|
||||
}
|
||||
cs_set_misc
|
||||
{
|
||||
name = "EMAIL"
|
||||
desc = "Associate an EMail with the channel"
|
||||
}
|
||||
command { service = "ChanServ"; name = "SET URL"; command = "chanserv/set/misc"; }
|
||||
command { service = "ChanServ"; name = "SET EMAIL"; command = "chanserv/set/misc"; }
|
||||
|
||||
/*
|
||||
* cs_sync
|
||||
@@ -424,25 +407,11 @@ ns_maxemail
|
||||
* ns_set_misc
|
||||
*
|
||||
* Allows you to create misc /nickserv set commands, and have the data
|
||||
* show up in /nickserv info
|
||||
* show up in /nickserv info.
|
||||
*/
|
||||
module { name = "ns_set_misc" }
|
||||
ns_set_misc
|
||||
{
|
||||
name = "OINFO"
|
||||
desc = "Associate oper only information to this nick"
|
||||
privileged = yes
|
||||
}
|
||||
ns_set_misc
|
||||
{
|
||||
name = "URL"
|
||||
desc = "Associate a URL with the nick"
|
||||
}
|
||||
ns_set_misc
|
||||
{
|
||||
name = "ICQ"
|
||||
desc = "Associate an ICQ number with the nick"
|
||||
}
|
||||
command { service = "NickServ"; name = "SET URL"; command = "nickserv/set/misc"; }
|
||||
command { service = "NickServ"; name = "SET ICQ"; command = "nickserv/set/misc"; }
|
||||
|
||||
/*
|
||||
* os_defcon
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
|
||||
class CommandCSSetMisc : public Command
|
||||
{
|
||||
Anope::string Desc;
|
||||
public:
|
||||
CommandCSSetMisc(Module *creator, const Anope::string &cname, const Anope::string &cdesc, const Anope::string &cpermission = "") : Command(creator, "chanserv/set/" + cname, 1, 2, cpermission), Desc(cdesc)
|
||||
CommandCSSetMisc(Module *creator, const Anope::string &cname = "chanserv/set/misc", const Anope::string &cpermission = "") : Command(creator, cname, 1, 2, cpermission)
|
||||
{
|
||||
this->SetDesc(cdesc);
|
||||
this->SetSyntax(_("\037channel\037 \037parameters\037"));
|
||||
}
|
||||
|
||||
@@ -31,119 +29,79 @@ class CommandCSSetMisc : public Command
|
||||
return;
|
||||
}
|
||||
|
||||
ci->Shrink("chanserv:" + this->name);
|
||||
ci->Shrink("cs_set_misc:" + source.command.replace_all_cs(" ", "_"));
|
||||
if (params.size() > 1)
|
||||
{
|
||||
ci->Extend("chanserv:" + this->name, new ExtensibleItemRegular<Anope::string>(params[1]));
|
||||
source.Reply(CHAN_SETTING_CHANGED, this->name.c_str(), ci->name.c_str(), params[1].c_str());
|
||||
ci->Extend("cs_set_misc:" + source.command.replace_all_cs(" ", "_"), new ExtensibleItemRegular<Anope::string>(params[1]));
|
||||
source.Reply(CHAN_SETTING_CHANGED, source.command.c_str(), ci->name.c_str(), params[1].c_str());
|
||||
}
|
||||
else
|
||||
source.Reply(CHAN_SETTING_UNSET, this->name.c_str(), ci->name.c_str());
|
||||
|
||||
return;
|
||||
source.Reply(CHAN_SETTING_UNSET, source.command.c_str(), ci->name.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class CommandCSSASetMisc : public CommandCSSetMisc
|
||||
{
|
||||
public:
|
||||
CommandCSSASetMisc(Module *creator, const Anope::string &cname, const Anope::string &cdesc) : CommandCSSetMisc(creator, cname, cdesc, "chanserv/saset/" + cname)
|
||||
CommandCSSASetMisc(Module *creator) : CommandCSSetMisc(creator, "chanserv/saset/misc", "chanserv/saset/misc")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CSSetMisc : public Module
|
||||
{
|
||||
struct CommandInfo
|
||||
{
|
||||
Anope::string Name;
|
||||
Anope::string Desc;
|
||||
bool ShowHidden;
|
||||
Command *c;
|
||||
|
||||
CommandInfo(const Anope::string &name, const Anope::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { }
|
||||
};
|
||||
|
||||
std::map<Anope::string, CommandInfo *> Commands;
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
delete it->second;
|
||||
this->Commands.clear();
|
||||
}
|
||||
CommandCSSetMisc commandcssetmisc;
|
||||
CommandCSSASetMisc commandcssasetmisc;
|
||||
|
||||
public:
|
||||
CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED)
|
||||
CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
|
||||
commandcssetmisc(this), commandcssasetmisc(this)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnReload, I_OnChanInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata };
|
||||
ModuleManager::Attach(i, this, 4);
|
||||
Implementation i[] = { I_OnChanInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata };
|
||||
ModuleManager::Attach(i, this, 3);
|
||||
|
||||
OnReload();
|
||||
}
|
||||
|
||||
~CSSetMisc()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
void OnReload()
|
||||
{
|
||||
RemoveAll();
|
||||
|
||||
ConfigReader config;
|
||||
|
||||
for (int i = 0, num = config.Enumerate("cs_set_misc"); i < num; ++i)
|
||||
{
|
||||
Anope::string cname = config.ReadValue("cs_set_misc", "name", "", i);
|
||||
if (cname.empty())
|
||||
continue;
|
||||
Anope::string desc = config.ReadValue("cs_set_misc", "desc", "", i);
|
||||
bool showhidden = config.ReadFlag("cs_set_misc", "privileged", "no", i);
|
||||
|
||||
CommandInfo *info = new CommandInfo(cname, desc, showhidden);
|
||||
if (!this->Commands.insert(std::make_pair(cname, info)).second)
|
||||
{
|
||||
Log() << "cs_set_misc: Warning, unable to add duplicate entry " << cname;
|
||||
delete info;
|
||||
continue;
|
||||
}
|
||||
|
||||
ModuleManager::RegisterService(new CommandCSSetMisc(this, cname, desc));
|
||||
ModuleManager::RegisterService(new CommandCSSASetMisc(this, cname, desc));
|
||||
}
|
||||
ModuleManager::RegisterService(&this->commandcssetmisc);
|
||||
ModuleManager::RegisterService(&this->commandcssasetmisc);
|
||||
}
|
||||
|
||||
void OnChanInfo(CommandSource &source, ChannelInfo *ci, bool ShowHidden)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
{
|
||||
if (!ShowHidden && it->second->ShowHidden)
|
||||
continue;
|
||||
std::deque<Anope::string> list;
|
||||
ci->GetExtList(list);
|
||||
|
||||
for (unsigned i = 0; i < list.size(); ++i)
|
||||
{
|
||||
if (list[i].find("cs_set_misc:") != 0)
|
||||
continue;
|
||||
|
||||
Anope::string value;
|
||||
if (ci->GetExtRegular("chanserv:" + it->first, value))
|
||||
source.Reply(" %s: %s", it->first.c_str(), value.c_str());
|
||||
if (ci->GetExtRegular(list[i], value))
|
||||
source.Reply(" %s: %s", list[i].substr(12).replace_all_cs("_", " ").c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), ChannelInfo *ci)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
std::deque<Anope::string> list;
|
||||
ci->GetExtList(list);
|
||||
|
||||
for (unsigned i = 0; i < list.size(); ++i)
|
||||
{
|
||||
if (list[i].find("cs_set_misc:") != 0)
|
||||
continue;
|
||||
|
||||
Anope::string value;
|
||||
if (ci->GetExtRegular("chanserv:" + it->first, value))
|
||||
WriteMetadata(it->first, ":" + value);
|
||||
if (ci->GetExtRegular(list[i], value))
|
||||
WriteMetadata(list[i], ":" + value);
|
||||
}
|
||||
}
|
||||
|
||||
EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
if (key == it->first)
|
||||
ci->Extend("chanserv:" + it->first, new ExtensibleItemRegular<Anope::string>(params[0]));
|
||||
if (key.find("cs_set_misc:") == 0)
|
||||
ci->Extend(key, new ExtensibleItemRegular<Anope::string>(params[0]));
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
class CommandNSSetMisc : public Command
|
||||
{
|
||||
public:
|
||||
CommandNSSetMisc(Module *creator, const Anope::string &cname, const Anope::string &cdesc, const Anope::string &cpermission = "", size_t min = 1) : Command(owner, "nickserv/set/" + cname, min, min + 1, cpermission)
|
||||
CommandNSSetMisc(Module *creator, const Anope::string &cname = "nickserv/set/misc", const Anope::string &cpermission = "", size_t min = 1) : Command(creator, cname, min, min + 1, cpermission)
|
||||
{
|
||||
this->SetDesc(cdesc);
|
||||
this->SetSyntax(_("\037parameter\037"));
|
||||
}
|
||||
|
||||
@@ -32,14 +31,14 @@ class CommandNSSetMisc : public Command
|
||||
}
|
||||
NickCore *nc = na->nc;
|
||||
|
||||
nc->Shrink("nickserv:" + this->name);
|
||||
nc->Shrink("ns_set_misc:" + source.command.replace_all_cs(" ", "_"));
|
||||
if (!param.empty())
|
||||
{
|
||||
nc->Extend("nickserv:" + this->name, new ExtensibleItemRegular<Anope::string>(param));
|
||||
source.Reply(CHAN_SETTING_CHANGED, this->name.c_str(), nc->display.c_str(), param.c_str());
|
||||
nc->Extend("ns_set_misc:" + source.command.replace_all_cs(" ", "_"), new ExtensibleItemRegular<Anope::string>(param));
|
||||
source.Reply(CHAN_SETTING_CHANGED, source.command.c_str(), nc->display.c_str(), param.c_str());
|
||||
}
|
||||
else
|
||||
source.Reply(CHAN_SETTING_UNSET, this->name.c_str(), nc->display.c_str());
|
||||
source.Reply(CHAN_SETTING_UNSET, source.command.c_str(), nc->display.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -53,8 +52,10 @@ class CommandNSSetMisc : public Command
|
||||
class CommandNSSASetMisc : public CommandNSSetMisc
|
||||
{
|
||||
public:
|
||||
CommandNSSASetMisc(Module *creator, const Anope::string &cname, const Anope::string &cdesc) : CommandNSSetMisc(creator, "nickserv/saset/" + cname, cdesc, "nickserv/saset/" + cname, 2)
|
||||
CommandNSSASetMisc(Module *creator) : CommandNSSetMisc(creator, "nickserv/saset/misc", "nickserv/saset/misc", 2)
|
||||
{
|
||||
this->ClearSyntax();
|
||||
this->SetSyntax(_("\037nickname\037 \037parameter\037"));
|
||||
}
|
||||
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
@@ -65,95 +66,58 @@ class CommandNSSASetMisc : public CommandNSSetMisc
|
||||
|
||||
class NSSetMisc : public Module
|
||||
{
|
||||
struct CommandInfo
|
||||
{
|
||||
Anope::string Name;
|
||||
Anope::string Desc;
|
||||
bool ShowHidden;
|
||||
|
||||
CommandInfo(const Anope::string &name, const Anope::string &cdesc, bool showhidden) : Name(name), Desc(cdesc), ShowHidden(showhidden) { }
|
||||
};
|
||||
|
||||
std::map<Anope::string, CommandInfo *> Commands;
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
delete it->second;
|
||||
this->Commands.clear();
|
||||
}
|
||||
CommandNSSetMisc commandnssetmisc;
|
||||
CommandNSSASetMisc commandnssasetmisc;
|
||||
|
||||
public:
|
||||
NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED)
|
||||
NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
|
||||
commandnssetmisc(this), commandnssasetmisc(this)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnReload, I_OnNickInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata };
|
||||
ModuleManager::Attach(i, this, 4);
|
||||
Implementation i[] = { I_OnNickInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata };
|
||||
ModuleManager::Attach(i, this, 3);
|
||||
|
||||
OnReload();
|
||||
}
|
||||
|
||||
~NSSetMisc()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
void OnReload()
|
||||
{
|
||||
RemoveAll();
|
||||
|
||||
ConfigReader config;
|
||||
|
||||
for (int i = 0, num = config.Enumerate("ns_set_misc"); i < num; ++i)
|
||||
{
|
||||
Anope::string cname = config.ReadValue("ns_set_misc", "name", "", i);
|
||||
if (cname.empty())
|
||||
continue;
|
||||
Anope::string desc = config.ReadValue("ns_set_misc", "desc", "", i);
|
||||
bool showhidden = config.ReadFlag("ns_set_misc", "privileged", "no", i);
|
||||
|
||||
CommandInfo *info = new CommandInfo(cname, desc, showhidden);
|
||||
if (!this->Commands.insert(std::make_pair(cname, info)).second)
|
||||
{
|
||||
Log() << "ns_set_misc: Warning, unable to add duplicate entry " << cname;
|
||||
delete info;
|
||||
continue;
|
||||
}
|
||||
|
||||
ModuleManager::RegisterService(new CommandNSSetMisc(this, cname, desc));
|
||||
ModuleManager::RegisterService(new CommandNSSASetMisc(this, cname, desc));
|
||||
}
|
||||
ModuleManager::RegisterService(&this->commandnssetmisc);
|
||||
ModuleManager::RegisterService(&this->commandnssasetmisc);
|
||||
}
|
||||
|
||||
void OnNickInfo(CommandSource &source, NickAlias *na, bool ShowHidden)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
std::deque<Anope::string> list;
|
||||
na->nc->GetExtList(list);
|
||||
|
||||
for (unsigned i = 0; i < list.size(); ++i)
|
||||
{
|
||||
if (!ShowHidden && it->second->ShowHidden)
|
||||
if (list[i].find("ns_set_misc:") != 0)
|
||||
continue;
|
||||
|
||||
Anope::string value;
|
||||
if (na->nc->GetExtRegular("nickserv:" + it->first, value))
|
||||
source.Reply(" %s: %s", it->first.c_str(), value.c_str());
|
||||
if (na->nc->GetExtRegular(list[i], value))
|
||||
source.Reply(" %s: %s", list[i].substr(12).replace_all_cs("_", " ").c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), NickCore *nc)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
std::deque<Anope::string> list;
|
||||
nc->GetExtList(list);
|
||||
|
||||
for (unsigned i = 0; i < list.size(); ++i)
|
||||
{
|
||||
if (list[i].find("ns_set_misc:") != 0)
|
||||
continue;
|
||||
|
||||
Anope::string value;
|
||||
if (nc->GetExtRegular("nickserv:" + it->first, value))
|
||||
WriteMetadata(it->first, ":" + value);
|
||||
if (nc->GetExtRegular(list[i], value))
|
||||
WriteMetadata(list[i], ":" + value);
|
||||
}
|
||||
}
|
||||
|
||||
EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
for (std::map<Anope::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it)
|
||||
if (key == it->first)
|
||||
nc->Extend("nickserv:" + it->first, new ExtensibleItemRegular<Anope::string>(params[0]));
|
||||
if (key.find("ns_set_misc:") == 0)
|
||||
nc->Extend(key, new ExtensibleItemRegular<Anope::string>(params[0]));
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user