autoop: add "dump" command from *watch #913

Open
opened 2026-10-05 04:52:25 +02:00 by adam · 1 comment
Owner

You are on IRCnet, find yourself op on some channel and start discussing automagics for keeping the ops opped. Then you decide to configure your *autoop so everything is fine for you and afterwards think that it would be nice to be able to share your ruleset in case someone else is also using ZNC.

This is the situation I found myself in, I have 10 users and 12 hostmasks and I wish *autoop had the dump command from *watch and *alias so I could just pastebin my list erasing irrelevant users and the potential other ZNC users could just add the ones they find useful.

I think the command would be portable on *autoop as there is no playing around with numeric IDs unlike with *watch which dump starts by clearing the config.

You are on IRCnet, find yourself op on some channel and start discussing automagics for keeping the ops opped. Then you decide to configure your `*autoop` so everything is fine for you and afterwards think that it would be nice to be able to share your ruleset in case someone else is also using ZNC. This is the situation I found myself in, I have 10 users and 12 hostmasks and I wish `*autoop` had the `dump` command from `*watch` and `*alias` so I could just pastebin my list erasing irrelevant users and the potential other ZNC users could just add the ones they find useful. I think the command would be portable on `*autoop` as there is no playing around with numeric IDs unlike with `*watch` which `dump` starts by clearing the config. <!-- github-sync-id:454698488 -->
Author
Owner

I just made this, no testing other than what you see below so run at own risk. I tried adding the CLEAR command, but I could not figure that out.

$ git diff
diff --git a/modules/autoop.cpp b/modules/autoop.cpp
index 619ab433..b53f1efc 100644
--- a/modules/autoop.cpp
+++ b/modules/autoop.cpp
@@ -171,6 +171,10 @@ class CAutoOpMod : public CModule {
                    [=](const CString& sLine) { OnAddUserCommand(sLine); });
         AddCommand("DelUser", t_d("<user>"), t_d("Removes a user"),
                    [=](const CString& sLine) { OnDelUserCommand(sLine); });
+        AddCommand("Dump", t_d(""), t_d("Dump a list of all current entries to be used later."),
+                   [=](const CString& sLine) { OnDumpCommand(); });
+        AddCommand("Clear", t_d(""), t_d("Delete all entries."),
+                   [=](const CString& sLine) { OnClearCommand(); });
     }
 
     bool OnLoad(const CString& sArgs, CString& sMessage) override {
@@ -422,6 +426,31 @@ class CAutoOpMod : public CModule {
         }
     }
 
+    void OnDumpCommand() {
+        if (m_msUsers.empty()) {
+            PutModule(t_s("You have no entries."));
+            return;
+        }
+
+        PutModule("---------------");
+        PutModule("/msg " + GetModNick() + " CLEAR");
+        for (const auto& it : m_msUsers) {
+            VCString vsHostmasks;
+            it.second->GetHostmasks().Split(",", vsHostmasks);
+                PutModule("/msg " + GetModNick() + " ADDUSER "
+                    + it.second->GetUsername() + " "
+                    + it.second->GetHostmasks() + " "
+                    + it.second->GetUserKey() + " "
+                    + it.second->GetChannels());
+        }
+
+        PutModule("---------------");
+    }
+
+    void OnClearCommand() {
+         // Someone should make this command work.
+    }
+
     CAutoOpUser* FindUser(const CString& sUser) {
         map<CString, CAutoOpUser*>::iterator it =
             m_msUsers.find(sUser.AsLower());


05:36:32 <KindOne> listusers
05:36:32 <*autoop> There are no users defined
05:36:39 <KindOne> adduser KindOne *!*@unaffiliated/kindone  __NOKEY__ #znc
05:36:39 <*autoop> User KindOne added with hostmask(s) *!*@unaffiliated/kindone
05:36:45 <KindOne> adduser GrumpyCat *!*@grumpycat/. pa$$word #znc-dev
05:36:45 <*autoop> User GrumpyCat added with hostmask(s) *!*@grumpycat/.
05:36:52 <KindOne> addmasks KindOne *!*@*/kindone,*!ident@ip.address.goes.here
05:36:52 <*autoop> Hostmasks(s) added to user KindOne
05:36:59 <KindOne> addchans GrumpyCat #foobar
05:36:59 <*autoop> Channel(s) added to user GrumpyCat
05:37:06 <KindOne> adduser LordHelmet *!*@ludicrous.speed 12345 #PlanetDruidia
05:37:06 <*autoop> User LordHelmet added with hostmask(s) *!*@ludicrous.speed
05:37:13 <KindOne> adduser DwightSchrute dwight!the@office. password1 #the.office
05:37:13 <*autoop> User DwightSchrute added with hostmask(s) dwight!the@office.
05:37:16 <KindOne> listusers
05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+
05:37:16 <*autoop> | User          | Hostmasks                    | Key       | Channels         |
05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+
05:37:16 <*autoop> | DwightSchrute | dwight!the@office.           | password1 | #the.office      |
05:37:16 <*autoop> | GrumpyCat     | *!*@grumpycat/.              | pa$$word  | #foobar #znc-dev |
05:37:16 <*autoop> | KindOne       | *!*@*/kindone                | __NOKEY__ | #znc             |
05:37:16 <*autoop> | |-            | *!*@unaffiliated/kindone     |           |                  |
05:37:16 <*autoop> | `-            | *!ident@ip.address.goes.here |           |                  |
05:37:16 <*autoop> | LordHelmet    | *!*@ludicrous.speed          | 12345     | #planetdruidia   |
05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+
05:37:25 <KindOne> dump
05:37:25 <*autoop> ---------------
05:37:25 <*autoop> /msg *autoop CLEAR
05:37:25 <*autoop> /msg *autoop ADDUSER DwightSchrute dwight!the@office. password1 #the.office
05:37:25 <*autoop> /msg *autoop ADDUSER GrumpyCat *!*@grumpycat/. pa$$word #foobar #znc-dev
05:37:25 <*autoop> /msg *autoop ADDUSER KindOne *!*@*/kindone,*!*@unaffiliated/kindone,*!ident@ip.address.goes.here __NOKEY__ #znc
05:37:25 <*autoop> /msg *autoop ADDUSER LordHelmet *!*@ludicrous.speed 12345 #planetdruidia
05:37:25 <*autoop> ---------------


I just made this, no testing other than what you see below so run at own risk. I tried adding the ```CLEAR``` command, but I could not figure that out. ``` $ git diff diff --git a/modules/autoop.cpp b/modules/autoop.cpp index 619ab433..b53f1efc 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -171,6 +171,10 @@ class CAutoOpMod : public CModule { [=](const CString& sLine) { OnAddUserCommand(sLine); }); AddCommand("DelUser", t_d("<user>"), t_d("Removes a user"), [=](const CString& sLine) { OnDelUserCommand(sLine); }); + AddCommand("Dump", t_d(""), t_d("Dump a list of all current entries to be used later."), + [=](const CString& sLine) { OnDumpCommand(); }); + AddCommand("Clear", t_d(""), t_d("Delete all entries."), + [=](const CString& sLine) { OnClearCommand(); }); } bool OnLoad(const CString& sArgs, CString& sMessage) override { @@ -422,6 +426,31 @@ class CAutoOpMod : public CModule { } } + void OnDumpCommand() { + if (m_msUsers.empty()) { + PutModule(t_s("You have no entries.")); + return; + } + + PutModule("---------------"); + PutModule("/msg " + GetModNick() + " CLEAR"); + for (const auto& it : m_msUsers) { + VCString vsHostmasks; + it.second->GetHostmasks().Split(",", vsHostmasks); + PutModule("/msg " + GetModNick() + " ADDUSER " + + it.second->GetUsername() + " " + + it.second->GetHostmasks() + " " + + it.second->GetUserKey() + " " + + it.second->GetChannels()); + } + + PutModule("---------------"); + } + + void OnClearCommand() { + // Someone should make this command work. + } + CAutoOpUser* FindUser(const CString& sUser) { map<CString, CAutoOpUser*>::iterator it = m_msUsers.find(sUser.AsLower()); ``` ``` 05:36:32 <KindOne> listusers 05:36:32 <*autoop> There are no users defined 05:36:39 <KindOne> adduser KindOne *!*@unaffiliated/kindone __NOKEY__ #znc 05:36:39 <*autoop> User KindOne added with hostmask(s) *!*@unaffiliated/kindone 05:36:45 <KindOne> adduser GrumpyCat *!*@grumpycat/. pa$$word #znc-dev 05:36:45 <*autoop> User GrumpyCat added with hostmask(s) *!*@grumpycat/. 05:36:52 <KindOne> addmasks KindOne *!*@*/kindone,*!ident@ip.address.goes.here 05:36:52 <*autoop> Hostmasks(s) added to user KindOne 05:36:59 <KindOne> addchans GrumpyCat #foobar 05:36:59 <*autoop> Channel(s) added to user GrumpyCat 05:37:06 <KindOne> adduser LordHelmet *!*@ludicrous.speed 12345 #PlanetDruidia 05:37:06 <*autoop> User LordHelmet added with hostmask(s) *!*@ludicrous.speed 05:37:13 <KindOne> adduser DwightSchrute dwight!the@office. password1 #the.office 05:37:13 <*autoop> User DwightSchrute added with hostmask(s) dwight!the@office. 05:37:16 <KindOne> listusers 05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+ 05:37:16 <*autoop> | User | Hostmasks | Key | Channels | 05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+ 05:37:16 <*autoop> | DwightSchrute | dwight!the@office. | password1 | #the.office | 05:37:16 <*autoop> | GrumpyCat | *!*@grumpycat/. | pa$$word | #foobar #znc-dev | 05:37:16 <*autoop> | KindOne | *!*@*/kindone | __NOKEY__ | #znc | 05:37:16 <*autoop> | |- | *!*@unaffiliated/kindone | | | 05:37:16 <*autoop> | `- | *!ident@ip.address.goes.here | | | 05:37:16 <*autoop> | LordHelmet | *!*@ludicrous.speed | 12345 | #planetdruidia | 05:37:16 <*autoop> +---------------+------------------------------+-----------+------------------+ 05:37:25 <KindOne> dump 05:37:25 <*autoop> --------------- 05:37:25 <*autoop> /msg *autoop CLEAR 05:37:25 <*autoop> /msg *autoop ADDUSER DwightSchrute dwight!the@office. password1 #the.office 05:37:25 <*autoop> /msg *autoop ADDUSER GrumpyCat *!*@grumpycat/. pa$$word #foobar #znc-dev 05:37:25 <*autoop> /msg *autoop ADDUSER KindOne *!*@*/kindone,*!*@unaffiliated/kindone,*!ident@ip.address.goes.here __NOKEY__ #znc 05:37:25 <*autoop> /msg *autoop ADDUSER LordHelmet *!*@ludicrous.speed 12345 #planetdruidia 05:37:25 <*autoop> --------------- ``` <!-- github-comment-id:501204496 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#913