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), permissions boolean not null default true, 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, show_link boolean not null default true, 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()
def get_feeds(self, client):
now = self.now()
- cursor = self.query("select id, server_id, channel_id, url, date, summary, link_json, permissions, enabled from feeds where bot_id=?", [client.user.id])
+ cursor = self.query("select id, server_id, channel_id, url, date, summary, show_link, link_json, permissions, enabled from feeds where bot_id=?", [client.user.id])
for row in cursor.fetchall():
yield dict(row)
self.close_db()
def feed_key(self, k):
d = {
'channel_id': 'in',
- 'description': 'title'
+ 'description': 'title',
+ 'show_link': 'link'
}
if k in d:
return d[k]
date = bot.parse_boolean(feed['date']) if 'date' in feed else True
# Include summary text.
summary = bot.parse_boolean(feed['summary']) if 'summary' in feed else False
+ # Post link
+ show_link = bot.parse_boolean(feed['show_link']) if 'show_link' in feed else True
url = feed['url']
d = feedparser.parse(url)
for entry in d.entries:
else:
order = now
now += 0.001
- all_entries.append({ 'order': order, 'date': date, 'summary': summary, 'url': feed['url'], 'link_json': feed['link_json'], 'entry': entry })
+ all_entries.append({ 'order': order, 'date': date, 'summary': summary, 'show_link': show_link, 'url': feed['url'], 'link_json': feed['link_json'], 'entry': entry })
if not len(all_entries):
log.debug('No messages to post to {}'.format(channel.name))
return
entry = feed['entry']
formatted = '*{}*\n'.format(entry['published']) if feed['date'] else ''
link = None
- if 'links' in entry:
+ if not feed['show_link']:
+ log.debug('Entry {} link is hidden.'.format(feed['url']))
+ elif 'links' in entry:
link = entry['links'][0]['href']
elif 'link_json' in feed:
try:
log.error('Invalid link_json in feed {}'.format(feed['url']))
except:
log.exception('do_rss:link_json')
- if not link:
+ if feed['show_link'] and not link:
log.warning('No link for entry {}'.format(entry['title']))
continue
- formatted += '**{}**\n{}'.format(entry['title'], link)
+ formatted += '**{}**{}'.format(entry['title'], '\n{}'.format(link) if feed['show_link'] else '')
if feed['summary']:
formatted += '\n{}'.format(''.join(bs4.BeautifulSoup(entry['summary'], 'html.parser').findAll(text = True)))
formatted = formatted.strip()
text += ' in <#{}>'.format(feed['channel_id'])
text += ' date {}'.format(feed['date'])
text += ' summary {}'.format(feed['summary'])
+ text += ' link {}'.format(feed['show_link'])
text += ' permissions {}'.format(feed['permissions'])
if feed['link_json']:
text += "--link_json '{}'".format(feed['link_json'])
ok = True
else:
break
- elif arg in ['date', 'permissions', 'summary']:
- k = arg
+ elif arg in ['date', 'permissions', 'link', 'summary']:
+ if arg == 'link':
+ k = 'show_link'
+ else:
+ k = arg
if param in ['true', 'false']:
parsed[k] = param
ok = True
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:
if 'description' not in parsed:
yield from bot.say(message.channel, 'Missing title!')
return None
+ if 'show_link' not in parsed:
+ parsed['show_link'] = True
+ if 'permissions' not in parsed:
+ parsed['permissions'] = True
return parsed
'```permissions false```',
"Don't override the `CHANNEL` permissions to prevent others from posting there.",
'',
+ '```link false```',
+ "Don't post a link to the entry.",
+ '',
]
elif command == 'delete':
lines = [