Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
[HOTFIX] parameterize hardcoded usernames (#161)
Browse files Browse the repository at this point in the history
[HOTFIX] parameterize hardcoded usernames
  • Loading branch information
TheLonelyGhost committed Jun 12, 2019
2 parents e2567bb + a1926d9 commit 16d6623
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
We follow [Semantic Versioning](http://semver.org/) as a way of measuring stability of an update. This
means we will never make a backwards-incompatible change within a major version of the project.

## v3.6.1 (2019-06-07)

- HOTFIX release:
- Makes the (protected) bot names an environment variable we can override in case usernames need to suddenly change
- Add reference to the currently running bot's username, as determined by Reddit's API

## v3.6.0 (2018-12-2)

- Add handling for `unclaim` comments (credit: @itsthejoker)
Expand Down
6 changes: 5 additions & 1 deletion tor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__version__ = '3.6.0'
import os

__version__ = '3.6.1'
__SELF_NAME__ = 'transcribersofreddit'
__BOT_NAMES__ = os.environ.get('BOT_NAMES', 'transcribersofreddit,tor_archivist,transcribot').split(',')
8 changes: 5 additions & 3 deletions tor/core/user_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import random

import praw

from tor import __BOT_NAMES__
# noinspection PyProtectedMember
from tor_core.helpers import _
from tor_core.helpers import clean_id
Expand Down Expand Up @@ -102,7 +104,7 @@ def process_claim(post, config):
top_parent = get_parent_post_id(post, config.r)

# WAIT! Do we actually own this post?
if top_parent.author.name != 'transcribersofreddit':
if top_parent.author.name not in __BOT_NAMES__:
logging.debug('Received `claim` on post we do not own. Ignoring.')
return

Expand Down Expand Up @@ -167,7 +169,7 @@ def process_done(post, config, override=False, alt_text_trigger=False):
top_parent = get_parent_post_id(post, config.r)

# WAIT! Do we actually own this post?
if top_parent.author.name != 'transcribersofreddit':
if top_parent.author.name not in __BOT_NAMES__:
logging.info('Received `done` on post we do not own. Ignoring.')
return

Expand Down Expand Up @@ -258,7 +260,7 @@ def process_unclaim(post, config):

top_parent = post.submission
# WAIT! Do we actually own this post?
if top_parent.author.name != 'transcribersofreddit':
if top_parent.author.name not in __BOT_NAMES__:
logging.info('Received `unclaim` on post we do not own. Ignoring.')
return

Expand Down
3 changes: 2 additions & 1 deletion tor/helpers/flair.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from tor import __BOT_NAMES__
from tor.core.users import User
from tor_core.helpers import clean_id
from tor_core.helpers import flair
Expand Down Expand Up @@ -147,7 +148,7 @@ def set_meta_flair_on_other_posts(config):
for post in config.tor.new(limit=10):

if (
post.author != config.r.redditor('transcribersofreddit') and
post.author.name not in __BOT_NAMES__ and
post.author not in config.tor_mods and
post.link_flair_text != flair.meta
):
Expand Down
8 changes: 8 additions & 0 deletions tor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from tor_core.helpers import run_until_dead
from tor_core.initialize import build_bot

# The `import tor` lines is necessary because `tor.__SELF_NAME__` is
# set here. Reason: https://gist.github.com/TheLonelyGhost/9dbe810c42d8f2edcf3388a8b19519e1
import tor
from tor import __version__
from tor.core.inbox import check_inbox
from tor.helpers.threaded_worker import threaded_check_submissions
Expand Down Expand Up @@ -77,6 +80,11 @@ def main():

build_bot(bot_name, __version__, full_name='u/ToR')
config.perform_header_check = True

tor.__SELF_NAME__ = config.r.user.me.name
if tor.__SELF_NAME__ not in tor.__BOT_NAMES__:
tor.__BOT_NAMES__.append(tor.__SELF_NAME__)

run_until_dead(run)


Expand Down

0 comments on commit 16d6623

Please sign in to comment.