Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gc-plp/reddit-moderator-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
gbionescu committed Jan 7, 2020
2 parents f831f2f + 17964d7 commit eba6cee
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions modbot/reddit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
inbox_thread = None
last_inbox_update = None
report_cmds = None
cache_data = None

last_moderator_subs_check = 0
moderator_subs_list = []
Expand Down Expand Up @@ -446,8 +447,10 @@ def catch_up(self, worker):
worker["finished"] = 1
self.storage.sync()

cache_data = {}
class CacheData():
"""
Holds information about a cached object - whether it's time to update it or not
"""
def __init__(self, interval):
self.interval = interval
self.last_check = -1000000
Expand All @@ -464,10 +467,10 @@ def set_opaque(self, opaque):
def mark_updated(self):
self.last_check = utcnow()

def add_cache_obj(name, interval):
cache_data[name] = CacheData(interval)

def is_expired(name):
"""
Check if a cached object has expired
"""
if name not in cache_data:
cache_data[name] = CacheData(update_intervals[name])

Expand All @@ -479,13 +482,15 @@ def set_input_type(input_type):
global wiki_storages
global subreddit_cache
global report_cmds
global cache_data

backend = importlib.import_module("modbot.input.%s" % input_type)

# Initialize objects that depend on the backend
all_data = dsdict("all", "last_seen") # Last seen /r/all subs and comms
wiki_storages = {}
subreddit_cache = {}
cache_data = {}
report_cmds = dsdict("mod", "cmds")

def set_credentials(credentials, user_agent):
Expand Down Expand Up @@ -666,7 +671,6 @@ def _check_inbox():
if not is_expired("inbox_update"):
return

last_inbox_update = tnow
inbox_thread = BotThread(
_check_inbox,
"inbox_thread")
Expand Down

0 comments on commit eba6cee

Please sign in to comment.