Browse Source

Add mlock setting and op_channel option

Add a mode option, which is passed through to mlock to set the modes
on channels.  Individual channels can override the global setting.

Because you must be an operator in the channel you are forwarding to
when using the +f mode, add a op_channel option that pre-joins a given
channel and promotes ourselves to ops in there.

[1] https://wiki.swiftirc.net/wiki/Chanserv#Mlock

Change-Id: Ic3ea018f1dd3032a628030ed56cfd863de2f159d
changes/34/588134/1
Ian Wienand 9 months ago
parent
commit
78f18d9b0e
1 changed files with 25 additions and 2 deletions
  1. 25
    2
      files/accessbot.py

+ 25
- 2
files/accessbot.py View File

@@ -81,6 +81,11 @@ class SetAccess(irc.client.SimpleIRCClient):
81 81
         if auth == '+' and nick == 'NickServ' and not self.identified:
82 82
             if msg.startswith('You are now identified'):
83 83
                 self.identified = True
84
+                # Prejoin and set ourselves as op in these channels,
85
+                # to facilitate +f forwarding.
86
+                for channel in self.config.get('op_channels', []):
87
+                    c.join("#%s" % channel)
88
+                    c.privmsg("chanserv", "op #%s" % channel)
84 89
                 self.advance()
85 90
                 return
86 91
         if auth != '+' or nick != 'ChanServ':
@@ -93,6 +98,7 @@ class SetAccess(irc.client.SimpleIRCClient):
93 98
     def _get_access_list(self, channel_name):
94 99
         ret = {}
95 100
         alumni = []
101
+        mode = ''
96 102
         channel = None
97 103
         for c in self.config['channels']:
98 104
             if c['name'] == channel_name:
@@ -108,12 +114,15 @@ class SetAccess(irc.client.SimpleIRCClient):
108 114
             if access == 'alumni':
109 115
                 alumni += nicks
110 116
                 continue
117
+            if access == 'mode':
118
+                mode = nicks
119
+                continue
111 120
             flags = self.config['access'].get(access)
112 121
             if flags is None:
113 122
                 continue
114 123
             for nick in nicks:
115 124
                 ret[nick] = flags
116
-        return mask, ret, alumni
125
+        return mask, ret, alumni, mode
117 126
 
118 127
     def _get_access_change(self, current, target, mask):
119 128
         remove = ''
@@ -140,11 +149,12 @@ class SetAccess(irc.client.SimpleIRCClient):
140 149
         return change
141 150
 
142 151
     def _get_access_changes(self):
143
-        mask, target, alumni = self._get_access_list(self.current_channel)
152
+        mask, target, alumni, mode = self._get_access_list(self.current_channel)
144 153
         self.log.debug("Mask for %s: %s" % (self.current_channel, mask))
145 154
         self.log.debug("Target for %s: %s" % (self.current_channel, target))
146 155
         all_nicks = set()
147 156
         global_alumni = self.config.get('alumni', {})
157
+        global_mode = self.config.get('mode', '')
148 158
         current = {}
149 159
         changes = []
150 160
         for nick, flags, msg in self.current_list:
@@ -162,6 +172,19 @@ class SetAccess(irc.client.SimpleIRCClient):
162 172
             if change:
163 173
                 changes.append('access #%s add %s %s' % (self.current_channel,
164 174
                                                          nick, change))
175
+
176
+        # Set the mode.  Note we always just hard-set the mode for
177
+        # simplicity (per the man page mlock always clears and sets
178
+        # anyway).  Channel mode overrides global mode.
179
+        #
180
+        # Note for +f you need to be op in the target channel; see
181
+        # op_channel option.
182
+        if not mode and global_mode:
183
+            mode = global_mode
184
+        self.log.debug("Setting mode to : %s" % mode)
185
+        if mode:
186
+            changes.append('set #%s mlock %s' % (self.current_channel, mode))
187
+
165 188
         return changes
166 189
 
167 190
     def advance(self, msg=None):

Loading…
Cancel
Save