Clean up
This commit is contained in:
@@ -21,38 +21,6 @@ def run():
|
||||
is_mod = bool(subreddit.moderator(redditor=reddit.user.me()))
|
||||
print_level(1, f'Is mod? {is_mod}')
|
||||
|
||||
testpoints = [1, 3, 5, 10, 15, 30, 45, 75] + list(range(100, 551, 50))
|
||||
|
||||
for sub in subreddit.new():
|
||||
if sub.title == 'Testing comment scenarios':
|
||||
redditor = sub.author
|
||||
for points in testpoints:
|
||||
body = f'Solver: {redditor}\n\nTotal points after solving: {points}'
|
||||
print_level(0, body)
|
||||
comm = sub.reply(body)
|
||||
if comm:
|
||||
level_info = level.user_level_info(points, levels)
|
||||
body = reply.make(redditor, points, level_info)
|
||||
comm.reply(body)
|
||||
else:
|
||||
print_level(1, 'ERROR: Unable to comment')
|
||||
break
|
||||
|
||||
|
||||
def real_run():
|
||||
cfg = config.load()
|
||||
levels = cfg.levels
|
||||
|
||||
# Connect to Reddit
|
||||
reddit = praw.Reddit(site_name=cfg.praw_site_name)
|
||||
subreddit = reddit.subreddit(cfg.subreddit_name)
|
||||
|
||||
print_level(0, f'Connected to Reddit as {reddit.user.me()}')
|
||||
print_level(1, f'Read-only? {reddit.read_only}')
|
||||
print_level(0, f'Watching subreddit {subreddit.title}')
|
||||
is_mod = bool(subreddit.moderator(redditor=reddit.user.me()))
|
||||
print_level(1, f'Is mod? {is_mod}')
|
||||
|
||||
db = database.Database(cfg.database_path)
|
||||
|
||||
# The pattern that determines whether a post is marked as solved
|
||||
@@ -167,3 +135,35 @@ def print_solution_info(comm):
|
||||
print_level(3, f'Body: {comm.body}')
|
||||
|
||||
|
||||
def make_comments():
|
||||
cfg = config.load()
|
||||
levels = cfg.levels
|
||||
|
||||
# Connect to Reddit
|
||||
reddit = praw.Reddit(site_name=cfg.praw_site_name)
|
||||
subreddit = reddit.subreddit(cfg.subreddit_name)
|
||||
|
||||
print_level(0, f'Connected to Reddit as {reddit.user.me()}')
|
||||
print_level(1, f'Read-only? {reddit.read_only}')
|
||||
print_level(0, f'Watching subreddit {subreddit.title}')
|
||||
is_mod = bool(subreddit.moderator(redditor=reddit.user.me()))
|
||||
print_level(1, f'Is mod? {is_mod}')
|
||||
|
||||
testpoints = [1, 3, 5, 10, 15, 30, 45, 75] + list(range(100, 551, 50))
|
||||
|
||||
for sub in subreddit.new():
|
||||
if sub.title == 'Testing comment scenarios':
|
||||
redditor = sub.author
|
||||
for points in testpoints:
|
||||
body = f'Solver: {redditor}\n\nTotal points after solving: {points}'
|
||||
print_level(0, body)
|
||||
comm = sub.reply(body)
|
||||
if comm:
|
||||
level_info = level.user_level_info(points, levels)
|
||||
body = reply.make(redditor, points, level_info)
|
||||
comm.reply(body)
|
||||
else:
|
||||
print_level(1, 'ERROR: Unable to comment')
|
||||
break
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from .level import Level
|
||||
|
||||
ROOTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
CONFIGPATH = os.path.join(ROOTPATH, 'pointsbot.ini')
|
||||
# CONFIGPATH = abspath(join(dirname(__file__), '..', 'pointsbot.ini'))
|
||||
|
||||
# TODO add default config values to pass to configparser
|
||||
|
||||
@@ -29,7 +28,6 @@ class Config:
|
||||
database_path = os.path.join(ROOTPATH, config['Core']['database_name'])
|
||||
|
||||
# Get the user flair levels in ascending order by point value
|
||||
# TODO Make levels a dict instead
|
||||
levels = []
|
||||
for opt in config.options('Levels'):
|
||||
name, points = opt.title(), config.getint('Levels', opt)
|
||||
|
||||
@@ -8,24 +8,10 @@ Level = namedtuple('Level', 'name points')
|
||||
# A ([Level], Level, Level) tuple;
|
||||
# previous can be empty, and exactly one of current and next can be None
|
||||
LevelInfo = namedtuple('LevelInfo', 'previous current next')
|
||||
# LevelInfo = namedtuple('LevelInfo', 'prev cur next')
|
||||
|
||||
### Functions ###
|
||||
|
||||
|
||||
"""
|
||||
def get_levels(config):
|
||||
levels = []
|
||||
for opt in config.options('Levels'):
|
||||
name, points = opt.title(), config.getint('Levels', opt)
|
||||
levels.append(Level(name, points))
|
||||
# levels.append((opt.title(), config.getint('Levels', opt)))
|
||||
# levels.sort(key=lambda pair: pair[1])
|
||||
levels.sort(key=lambda lvl: lvl.points)
|
||||
return levels
|
||||
"""
|
||||
|
||||
|
||||
def user_level_info(points, levels):
|
||||
'''Return a tuple the user's previous (plural), current, and next levels.
|
||||
|
||||
@@ -56,11 +42,3 @@ def is_max_level(level_info):
|
||||
return not level_info.next
|
||||
|
||||
|
||||
"""
|
||||
def is_max_level(points, levels):
|
||||
'''Assume levels is sorted in ascending order by points.'''
|
||||
# return points >= levels[-1][1]
|
||||
return points >= levels[-1].points
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -56,9 +56,6 @@ def level_up(redditor, level_name, tag_user=True):
|
||||
start = f'Congrats u/{redditor.name}, y' if tag_user else 'Y'
|
||||
return (f'{start}ou have leveled up to "{level_name}"! Your flair has been '
|
||||
'updated accordingly.')
|
||||
# return (f'Congrats u/{redditor.name}, y
|
||||
# return (f'Congrats u/{redditor.name}, you have leveled up to "{level_name}"! '
|
||||
# 'Your flair has been updated accordingly.')
|
||||
|
||||
|
||||
def new_star(redditor, first_star):
|
||||
@@ -118,7 +115,5 @@ def footer():
|
||||
return ('^(This bot is written and maintained by GlipGlorp7 '
|
||||
'| Learn more and view the source code on '
|
||||
'[Github](https://github.com/cur33/PointsBot))')
|
||||
# ^(This bot is written and maintained by u/GlipGlorp7 | Learn more and view the source code on [Github](https://github.com/cur33/PointsBot))
|
||||
# ^([Learn more]() | [View source code](https://github.com/cur33/PointsBot) | [Contacts mods]())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user