Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reddit: spoiler update #1620

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 62 additions & 12 deletions sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
reddit.py - Sopel Reddit Module
Copyright 2012, Elsie Powell, embolalia.com
Copyright 2019, dgw, technobabbl.es
Licensed under the Eiffel Forum License 2.

https://sopel.chat
Expand Down Expand Up @@ -37,10 +38,6 @@
post_url = r'%s/r/.*?/comments/([\w-]+)' % domain
short_post_url = r'https?://redd.it/([\w-]+)'
user_url = r'%s/u(ser)?/([\w-]+)' % domain
spoiler_subs = [
'stevenuniverse',
'onepunchman',
]


@url(post_url)
Expand All @@ -65,11 +62,9 @@ def rpost_info(bot, trigger, match):
else:
link = '({}) to r/{}'.format(s.url, subreddit)

nsfw = ''
if s.over_18:
if subreddit.lower() in spoiler_subs:
nsfw = ' ' + bold(color('[SPOILERS]', colors.RED))
else:
nsfw = ' ' + bold(color('[NSFW]', colors.RED))
nsfw += ' ' + bold(color('[NSFW]', colors.RED))

sfw = bot.db.get_channel_value(trigger.sender, 'sfw')
if sfw:
Expand All @@ -78,8 +73,16 @@ def rpost_info(bot, trigger, match):
trigger.nick, trigger.sender,
'Linking to NSFW content in a SFW channel.'
)
else:
nsfw = ''
if s.spoiler:
nsfw += ' ' + bold(color('[SPOILER]', colors.GRAY))

spoiler_free = bot.db.get_channel_value(trigger.sender, 'spoiler_free')
if spoiler_free:
link = '(link hidden)'
bot.kick(
trigger.nick, trigger.sender,
'Linking to spoiler content in a spoiler-free channel.'
)

if s.author:
author = s.author.name
Expand Down Expand Up @@ -169,7 +172,7 @@ def auto_redditor_info(bot, trigger, match):
@commands('setsafeforwork', 'setsfw')
@example('.setsfw true')
@example('.setsfw false')
def update_channel(bot, trigger):
def set_channel_sfw(bot, trigger):
"""
Sets the Safe for Work status (true or false) for the current
channel. Defaults to false.
Expand Down Expand Up @@ -199,7 +202,8 @@ def get_channel_sfw(bot, trigger):
if not channel:
channel = trigger.sender
if channel.is_nick():
return bot.say('.getsfw with no channel param is only permitted in channels')
return bot.say('{}getsfw with no channel param is only permitted in '
'channels'.format(bot.config.core.help_prefix))

channel = channel.strip()

Expand All @@ -208,3 +212,49 @@ def get_channel_sfw(bot, trigger):
bot.say('%s is flagged as SFW' % channel)
else:
bot.say('%s is flagged as NSFW' % channel)


@require_chanmsg('.setspoilfree is only permitted in channels')
@commands('setspoilerfree', 'setspoilfree')
@example('.setspoilfree true')
@example('.setspoilfree false')
def set_channel_spoiler_free(bot, trigger):
"""
Sets the Spoiler-Free status (true or false) for the current channel.
Defaults to false.
"""
if bot.channels[trigger.sender].privileges[trigger.nick] < OP:
return
else:
param = 'true'
if trigger.group(2) and trigger.group(3):
param = trigger.group(3).strip().lower()
spoiler_free = param == 'true'
bot.db.set_channel_value(trigger.sender, 'spoiler_free', spoiler_free)
if spoiler_free:
bot.reply('Got it. %s is now flagged as spoiler-free.' % trigger.sender)
else:
bot.reply('Got it. %s is now flagged as spoilers-allowed.' % trigger.sender)


@commands('getspoilerfree', 'getspoilfree')
@example('.getspoilfree [channel]')
def get_channel_spoiler_free(bot, trigger):
dgw marked this conversation as resolved.
Show resolved Hide resolved
"""
Gets the channel's Spoiler-Free status, or the current channel's
status if no channel given.
"""
channel = trigger.group(2)
if not channel:
channel = trigger.sender
if channel.is_nick():
return bot.say('{}getspoilfree with no channel param is only permitted '
'in channels'.format(bot.config.core.help_prefix))

channel = channel.strip()

spoiler_free = bot.db.get_channel_value(channel, 'spoiler_free')
if spoiler_free:
bot.say('%s is flagged as spoiler-free' % channel)
else:
bot.say('%s is flagged as spoilers-allowed' % channel)