This commit is contained in:
Collin R
2020-02-01 00:48:14 -08:00
parent 3dee25bd80
commit 5b3a3d8f1f
4 changed files with 32 additions and 61 deletions

View File

@@ -21,38 +21,6 @@ def run():
is_mod = bool(subreddit.moderator(redditor=reddit.user.me())) is_mod = bool(subreddit.moderator(redditor=reddit.user.me()))
print_level(1, f'Is mod? {is_mod}') 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) db = database.Database(cfg.database_path)
# The pattern that determines whether a post is marked as solved # 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}') 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

View File

@@ -8,7 +8,6 @@ from .level import Level
ROOTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) ROOTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
CONFIGPATH = os.path.join(ROOTPATH, 'pointsbot.ini') CONFIGPATH = os.path.join(ROOTPATH, 'pointsbot.ini')
# CONFIGPATH = abspath(join(dirname(__file__), '..', 'pointsbot.ini'))
# TODO add default config values to pass to configparser # 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']) database_path = os.path.join(ROOTPATH, config['Core']['database_name'])
# Get the user flair levels in ascending order by point value # Get the user flair levels in ascending order by point value
# TODO Make levels a dict instead
levels = [] levels = []
for opt in config.options('Levels'): for opt in config.options('Levels'):
name, points = opt.title(), config.getint('Levels', opt) name, points = opt.title(), config.getint('Levels', opt)

View File

@@ -8,24 +8,10 @@ Level = namedtuple('Level', 'name points')
# A ([Level], Level, Level) tuple; # A ([Level], Level, Level) tuple;
# previous can be empty, and exactly one of current and next can be None # previous can be empty, and exactly one of current and next can be None
LevelInfo = namedtuple('LevelInfo', 'previous current next') LevelInfo = namedtuple('LevelInfo', 'previous current next')
# LevelInfo = namedtuple('LevelInfo', 'prev cur next')
### Functions ### ### 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): def user_level_info(points, levels):
'''Return a tuple the user's previous (plural), current, and next 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 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
"""

View File

@@ -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' 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 ' return (f'{start}ou have leveled up to "{level_name}"! Your flair has been '
'updated accordingly.') '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): def new_star(redditor, first_star):
@@ -118,7 +115,5 @@ def footer():
return ('^(This bot is written and maintained by GlipGlorp7 ' return ('^(This bot is written and maintained by GlipGlorp7 '
'| Learn more and view the source code on ' '| Learn more and view the source code on '
'[Github](https://github.com/cur33/PointsBot))') '[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]())