async def runall(msg, websocket, userSearch): global owner global username owner = owner.replace(' ', '') owner = owner.lower() username = username.replace(' ', '') username = username.lower() if msg.replace(' ', '').lower() == PM(userSearch, 'spheal'): await websocket.send(spheal(user=userSearch)) if msg.replace(' ', '').lower() == PM(userSearch, 'timer'): print(msg.replace(' ', '').lower())
def getComments(submission): rp = RedditPoller(CommentWrapper(pg.comments, reddit.inbox.all)) comments = rp.getLatest() # flush old comments while next(comments): continue for c in comments: if hasattr(c, 'submission') and hasattr(c, 'author') and c.author and c.submission: if c.author.name.lower() == username.lower() and '+correct' in c.body and not c.is_root: return if not c.is_root: continue if c.author.name.lower() in donotreply or c.submission != submission: continue yield c
def postDelay(): if debug: return -1 r = requests.get('https://api.picturegame.co/current') data = json.loads(r.content) tries = 1 while data['round']['hostName'].lower() != username.lower(): tries += 1 if tries > 5: return -1 r = requests.get('https://api.picturegame.co/current') data = json.loads(r.content) time.sleep(5) return data['round'].get('postDelay', -1)
def check(submission, answer, tolerance, manual=False, multiple=False): comments = RedditPoller(CommentWrapper(pg.comments, reddit.inbox.all)) if not multiple: answer = Point(answer) else: answer = [Point(a) for a in answer] plus_correct = None for c in get_comments(comments.getLatest()): if c.author.name.lower() == username.lower() and '+correct' in c.body: return if not c.is_root: continue if c.author.name.lower() in donotreply or c.submission != submission: continue error = get_distance(c.body, answer) if not multiple else None is_coord = error is not None if multiple: correct = check_multiple(c.body, answer, tolerance) else: correct = is_coord and error <= tolerance if correct and not manual: plus_correct = c.reply('+correct') elif is_coord and not correct or not correct and multiple: c.reply(incorrect) print(f'{c.author}\'s guess {c.body} was {error} meters off') if correct and not manual: print( f'corrected {c.author} in {plus_correct.created_utc - c.created_utc}s' ) if correct and not manual: return
def approved(): c = next(iter(pg.contributor())) return c and c.name.lower() == username.lower()