Allow disabling the modification of channel permissions where a feed is made.
authorCMDR furrycat <elite@furrycat.net>
Thu, 3 Nov 2016 12:55:02 +0000 (12:55 +0000)
committerCMDR furrycat <elite@furrycat.net>
Thu, 3 Nov 2016 12:55:02 +0000 (12:55 +0000)
plugin/feeds/feeds.py

index e0187b6..1c5f857 100644 (file)
@@ -25,7 +25,7 @@ class Feeds(DBConnection):
 
   def create_tables(self):
     self.open_db()
-    cursor = self.query('create table if not exists feeds (id char(36) not null, bot_id varchar(32) not null, server_id varchar(32) not null, channel_id varchar(32) not null, description varchar(64), url varchar(128) not null, date boolean not null default true, summary boolean not null default false, link_json varchar(256), enabled boolean not null default true)')
+    cursor = self.query('create table if not exists feeds (id char(36) not null, bot_id varchar(32) not null, server_id varchar(32) not null, channel_id varchar(32) not null, description varchar(64), url varchar(128) not null, date boolean not null default true, summary boolean not null default false, link_json varchar(256), permissions boolean not null default true, enabled boolean not null default true)')
     cursor = self.query('create unique index if not exists feed_id on feeds (id)')
     cursor = self.query('create index if not exists feed_bot_id on feeds (bot_id)')
     self.dbh.commit()
@@ -35,7 +35,7 @@ class Feeds(DBConnection):
 
   def get_feeds(self, client):
     now = self.now()
-    cursor = self.query("select id, server_id, channel_id, url, date, summary, link_json, enabled from feeds where bot_id=?", [client.user.id])
+    cursor = self.query("select id, server_id, channel_id, url, date, summary, link_json, permissions, enabled from feeds where bot_id=?", [client.user.id])
     for row in cursor.fetchall():
       yield dict(row)
     self.close_db()
@@ -180,7 +180,8 @@ class Feeds(DBConnection):
         feeds.setdefault(feed['channel_id'], [])
         feeds[feed['channel_id']].append(feed)
       for channel_id in feeds.keys():
-        yield from self.set_rss_permissions(channel_id)
+        if any([bot.parse_boolean(feed['permissions']) for feed in feeds[channel_id]]):
+          yield from self.set_rss_permissions(channel_id)
         yield from self.do_rss(feeds[channel_id])
       yield from asyncio.sleep(rsstime.value)
 
@@ -309,6 +310,7 @@ class Feeds(DBConnection):
     text += ' in <#{}>'.format(feed['channel_id'])
     text += ' date {}'.format(feed['date'])
     text += ' summary {}'.format(feed['summary'])
+    text += ' permissions {}'.format(feed['permissions'])
     if feed['link_json']:
       text += "--link_json '{}'".format(feed['link_json'])
     lines.append(text)
@@ -357,7 +359,13 @@ class Feeds(DBConnection):
       elif arg == 'in':
         k = 'channel_id'
         if param:
-          channel = bot.parse_channel(param, voice_ok = False)
+          if param == 'here':
+            channel = message.channel
+            if channel.is_private:
+              log.warning('Requested feed to private channel!')
+              break
+          else:
+            channel = bot.parse_channel(param, voice_ok = False)
           if channel is not None:
             parsed[k] = channel.id
             ok = True
@@ -369,7 +377,7 @@ class Feeds(DBConnection):
           ok = True
         else:
           break
-      elif arg in ['date', 'summary']:
+      elif arg in ['date', 'permissions', 'summary']:
         k = arg
         if param in ['true', 'false']:
           parsed[k] = param
@@ -390,6 +398,9 @@ class Feeds(DBConnection):
       yield from bot.say(message.channel, '{}?'.format(arg))
       return None
 
+    if 'permissions' not in parsed:
+      parsed['permissions'] = True
+
     if 'channel_id' in parsed:
       channel = client.get_channel(parsed['channel_id'])
       if not channel:
@@ -535,6 +546,9 @@ class Feeds(DBConnection):
         '```summary true```',
         'Include part of the text from the feed in the post.',
         '',
+        '```permissions false```',
+        "Don't override the `CHANNEL` permissions to prevent others from posting there.",
+        '',
       ]
     elif command == 'delete':
       lines = [