async def verify_race(ctx): dbclient = clientDB() collection = dbclient.db.NT_to_discord dbdata = await dbclient.get_array(collection, {}) async for elem in dbdata: old = copy.deepcopy(elem) if elem['userID'] == str(ctx.author.id): if elem['verified'] == 'false': username = elem['NTuser'] embed = Embed(':clipboard: Verify your Identity!', f'Join the race to verify **{username}** is owned by you. You don\'t own **{username}**? Run `n.unregister` to unlink your discord from this account.') embed.field('__Instructions__', 'Once you join the race, the race leader will leave and you just have to type `n.verify` again to verify. If this does not work after several times typing `n.verify`, please try unregistering and registering again.') embed.field('__Short instructions__', '**1.** Run `n.verify`\n**2.** Join the race track shown under the link category.\n**3.** Run `n.verify` again.') embed.field('__Common errors__', 'Is the race leader not joining the race? Run `n.verify` again and refresh your page, after maximal **5** times running the command, the race leader joins and you can attempt to verify.') embed.field('__Link__', 'Join [this](https://www.nitrotype.com/race/lacanverification) race to verify your identity.') await embed.send(ctx) elem['verifyCar'] = None elem['verified'] = 'in progress' dbclient = DBClient() collection = dbclient.db.NT_to_discord await dbclient.update_array(collection, old, elem) async with aiohttp.ClientSession() as s: await fetch(s,'https://Lacan-Verification.try2win4code.repl.co') break if elem['verified'] == 'in progress': async with aiohttp.ClientSession() as s: response = await fetch(s,'https://Lacan-Verification.try2win4code.repl.co', method='GET') data = json.loads(response) if elem['NTuser'] in data['verified']: elem['verified'] = 'true' dbclient = DBClient() await dbclient.update_array(collection, old, elem) embed = Embed('<a:Check:797009550003666955> Success', 'You\'ve been verified! In case this is a premium 💠server do `n.update` to update your roles.') await embed.send(ctx) break else: username = elem['NTuser'] embed = Embed('Nearly there!', f'You\'re nearly done - just one more step to go!\nYou are just about to verify your ownership for **{username}**. Not you? Run `n.unregister` to unlink your discord from this account.', 'warning') embed.field('__Instructions__', 'Please join the race and run `n.verify` again.') embed.field('__Common errors__', 'Is the race leader not joining the race? Run `n.verify` again and refresh your page, after maximal **5** times running the command, the race leader joins and you can attempt to verify.') embed.field('__Link__', 'Join [this](https://www.nitrotype.com/race/lacanverification) race to verify your identity.') await embed.send(ctx) async with aiohttp.ClientSession() as s: await fetch(s,'https://Lacan-Verification.try2win4code.repl.co') break if elem['verified'] == 'true': embed = Embed('Error!', 'You are already verified :rofl:', 'joy') return await embed.send(ctx) else: embed = Embed('Error!', 'You have not registered yet. Make sure to run `n.register <username>`', 'warning') await embed.send(ctx)
async def l(compid, category="races"): await update_comp(compid) dbclient = DBClient() collection = dbclient.db['test'] data = await dbclient.get_array( collection, {'$and': [{ 'compid': compid }, { 'compid': compid }]}) usernames = [] displays = [] categorylist = [] for user in data['players']: if user['stillinteam'] == False: continue usernames.append(user['username'].lower()) displays.append(user['display']) if category == "races": categorylist.append(user['total-races']) elif category == "points": categorylist.append(user['points']) elif category == "speed": categorylist.append(user['wpm']) elif category == "accuracy": categorylist.append(user['accuracy']) sortcategory = sorted(categorylist, reverse=True) zipped_lists = zip(categorylist, usernames, displays) sorted_zipped_lists = sorted(zipped_lists, reverse=True) cleanresult = [] for t in sorted_zipped_lists: cleanresult.append((t[1], t[2], t[0])) return ('nothing LMAO', cleanresult)
async def endcomp(self, ctx, compid): await nitrotype.update_comp(compid) dbclient = DBClient() collection = dbclient.db['test'] data = await dbclient.get_array(collection, {'$and': [{'compid': compid}, {'compid': compid}]}) async for d in data: data = d old = data.copy() data = data other = data['other'] if other['ended'] == True: embed = Embed('Error!', 'LMAO you already ended the comp before!') return await embed.send(ctx) if ctx.author.id != other['author'] and ctx.author.id not in [505338178287173642, 637638904513691658, 396075607420567552]: embed = Embed("Bruh Alert", "Yes thank you for trying ot delete someone **else\'s** competition!", "warning") return await embed.send(ctx) embed = discord.Embed(title="Sucess!", description=f"You have succesfully ended the competition ***manually*** for Team **{other['team']}** and Comp ID `{compid}`! Results will be sent to dms!") date = other['endcomptime'] timestamp = datetime.fromtimestamp(date) embed.set_footer(text=f"This competition was scheduled to end at {timestamp.strftime('%Y-%m-%d %H:%M:%S')}") await ctx.send(embed=embed) lb = await nitrotype.l(str(compid)) embed = discord.Embed( title='Competition results', description='This is where you can view everyone\'s progress during the competition!', color=0x15E700 ) usernames = [] races = [] for stat in lb[1]: if stat[1] == '': usernames.append(f'{stat[0]}\n') else: usernames.append(f'{stat[1]}\n') races.append(str(stat[2])) usernames = ''.join(usernames) races = '\n'.join(races) embed.add_field( name='Team Members', value=usernames ) embed.add_field( name="Races", value=races ) user = await self.client.fetch_user(other['author']) try: await user.send(embed=embed) await user.send('Your conpetition has ended! Comp ID: `'+compid+'`. Check out the other categories of your competition by doing `n.lb '+compid+'` and adding `speed`, `accuracy`, `races`, or `points`. Ex: `n.lb '+compid+' points`') except: pass requests.post('https://backupcomps.adl212.repl.co/backupcomp', data={"id": compid, "comp_data": json.dumps(data['players'])}) other['ended'] = True await dbclient.update_array(collection, old, data)
async def create_comp(team, compid, endcomptime, authorid, async_cloudflare=False): page = await team_data(team, async_cloudflare) info = json.loads(page) dbclient = DBClient() data = { "data": { "compid": str(compid), "players": [], "other": {} } } for elem in info['data']['members']: #if elem['displayName'] != None: if elem['displayName'] != None: displayname = elem['displayName'] else: displayname = elem['username'] try: racer = await Racer(elem['username']) except: continue try: typed = racer.season_pre['typed'] secs = racer.season_pre['secs'] errs = racer.season_pre['errs'] except: typed = 0 secs = 0 errs = 0 data['data']['players'].append({ "username": elem['username'], "starting-races": elem['played'], "ending-races": elem['played'], "total-races": 0, "display": displayname, "stillinteam": True, "starting-typed": typed, "ending-typed": typed, "starting-secs": float(secs), "ending-secs": float(secs), "starting-errs": (errs), "ending-errs": (errs) }) data['data']['other'] = { "team": team, "endcomptime": endcomptime, "author": authorid, "ended": False } await dbclient.create_doc(dbclient.db.test, data['data']) return True
async def create_comp(team, compid, endcomptime, authorid): async with aiohttp.ClientSession() as session: page = await fetch(session, f'https://www.nitrotype.com/api/teams/{team}') info = json.loads(page) dbclient = DBClient() data = { "data": { "compid": str(compid), "players": [], "other": {} } } for elem in info['data']['members']: if elem['displayName'] != None: displayname = elem['displayName'] else: displayname = elem['username'] try: racer = await Racer(elem['username']) except: continue try: typed = racer.season_pre['typed'] secs = racer.season_pre['secs'] errs = racer.season_pre['errs'] except: typed = 0 secs = 0 errs = 0 data['data']['players'].append({ "username": elem['username'], "starting-races": elem['played'], "ending-races": elem['played'], "total-races": 0, "display": displayname, "stillinteam": True, "starting-typed": typed, "ending-typed": typed, "starting-secs": float(secs), "ending-secs": float(secs), "starting-errs": (errs), "ending-errs": (errs) }) data['data']['other'] = { "team": team, "endcomptime": endcomptime, "author": authorid, "ended": False } await dbclient.create_doc(dbclient.db.test, data['data']) return True
async def NT_to_discord(id, bypass_verified=False): from mongoclient import DBClient dbclient = DBClient() collection = dbclient.db.NT_to_discord data = await dbclient.get_big_array(collection, 'registered') for elem in data['registered']: if str(id) == elem['userID'] or str(id) == elem['NTuser']: if elem['verified'] == 'true' or bypass_verified: racer = await Racer(elem['NTuser']) return True, racer else: embed = Embed('Error!', 'You\'re not verified yet!', 'warning') return False, embed else: try: return True, await Racer(str(id)) except: embed = Embed('Error!', 'Couldn\'t find that user', 'warning') return False, embed
async def NT_to_discord(id, bypass_verified=False, get_id=False): from mongoclient import DBClient dbclient = DBClient() collection = dbclient.db.NT_to_discord data = await dbclient.get_array(collection, {'$or': [{'userID': str(id)}, {'NTuser': str(id)}]}) async for elem in data: if elem['verified'] == 'true' or bypass_verified: if get_id: return True, elem['userID'] racer = await Racer(elem['NTuser']) return True, racer else: embed = Embed('Error!', 'You\'re not verified yet!', 'warning') return False, embed else: try: return True, await Racer(str(id)) except: embed = Embed('Error!', 'Couldn\'t find that user', 'warning') return False, embed
async def always_update(self): print('started auto update') f = open('dailyupdate.txt') if int(time.time()) >= int(f.readlines()[0].strip()): async with aiohttp.ClientSession() as session: await self.fetch(session, 'https://lacanitemshop.nitrotypers.repl.co/update/daily', data={'key': os.getenv('DB_KEY')}) f.close() with open('dailyupdate.txt', 'w') as f: f.write(str(round(time.time())+86400)) f = open('weeklyupdate.txt') if int(time.time()) >= int(f.readlines()[0].strip()): async with aiohttp.ClientSession() as session: await self.fetch(session, 'https://lacanitemshop.nitrotypers.repl.co/update/weekly', data={'key': os.getenv('DB_KEY')}) f.close() with open('weeklyupdate.txt', 'w') as f: f.write(str(round(time.time())+604800)) dbclient = DBClient() collection = dbclient.db['test'] documents = await dbclient.get_array(collection, {'other.ended': False}) await create_processing_pool(self, dbclient, documents) print('Auto Update Done')
async def update_comp(compid): dbclient = DBClient() collection = dbclient.db['test'] data = await dbclient.get_array( collection, {'$and': [{ 'compid': compid }, { 'compid': compid }]}) old = copy.deepcopy(data) other = data['other'] players = data['players'] team = other['team'] if round(time.time()) >= other['endcomptime']: return async with aiohttp.ClientSession() as session: page = await fetch(session, f'https://www.nitrotype.com/api/teams/{team}') info = json.loads(page) try: for user in players: for elem in info['data']['members']: if user['username'] == elem['username']: try: racer = await Racer(user['username']) except: continue try: typed = float(racer.season_pre['typed']) secs = float(racer.season_pre['secs']) errs = float(racer.season_pre['errs']) except: typed = 0 secs = 0 errs = 0 user['ending-races'] = elem['played'] user['total-races'] = user['ending-races'] - user[ 'starting-races'] user['display'] = elem['displayName'] user['stillinteam'] = True user['ending-typed'] = typed user['ending-secs'] = float(secs) user['ending-errs'] = errs try: user['wpm'] = (user['ending-typed'] - user['starting-typed']) / 5 / float( user['ending-secs'] - user['starting-secs']) * 60 user['accuracy'] = 100 - ( ((user['ending-errs'] - user['starting-errs']) / (user['ending-typed'] - user['starting-typed'])) * 100) user['points'] = user['total-races'] * ( 100 + (user['wpm'] / 2)) * user['accuracy'] / 100 except: user['wpm'] = 0 user['accuracy'] = 0 user['points'] = 0 break else: user['stillinteam'] = False res = [sub['username'] for sub in players] for elem in info['data']['members']: if elem['username'] in res: continue else: players.append({ "username": elem['username'], "starting-races": elem['played'], "ending-races": elem['played'], "total-races": 0, "display": elem['displayName'] or elem['username'], "stillinteam": True, "starting-typed": elem['typed'], "ending-typed": elem['typed'], "starting-secs": float(elem['secs']), "ending-secs": float(elem['secs']), "starting-errs": (elem['errs']), "ending-errs": (elem['errs']) }) except Exception as e: return await dbclient.update_array(collection, old, data) return data
async def always_update(self): f = open('dailyupdate.txt') if int(time.time()) >= int(f.readlines()[0].strip()): async with aiohttp.ClientSession() as session: await self.fetch(session, 'https://lacanitemshop.nitrotypers.repl.co/update/daily', data={'key': os.getenv('DB_KEY')}) f.close() with open('dailyupdate.txt', 'w') as f: f.write(str(round(time.time())+86400)) f = open('weeklyupdate.txt') if int(time.time()) >= int(f.readlines()[0].strip()): async with aiohttp.ClientSession() as session: await self.fetch(session, 'https://lacanitemshop.nitrotypers.repl.co/update/weekly', data={'key': os.getenv('DB_KEY')}) f.close() with open('weeklyupdate.txt', 'w') as f: f.write(str(round(time.time())+604800)) dbclient = DBClient() collection = dbclient.db['test'] documents = await dbclient.get_array(collection, {}) async for data in documents: old = copy.deepcopy(data) compid = data['compid'] if data['other']['ended'] == True: continue endcomptime = data['other']['endcomptime'] if round(time.time()) < endcomptime: try: await nitrotype.update_comp(compid) continue except: print('Couldn\'t update Comp!') pass elif round(time.time()) >= endcomptime: await nitrotype.update_comp(str(compid)) lb = await nitrotype.l(str(compid)) embed = discord.Embed( title='Live Leaderboards', description='This is where you can view everyone\'s progress during the competition!', color=0x15E700 ) usernames = [] races = [] for stat in lb[1]: if stat[1] == '': usernames.append(f'{stat[0]}\n') else: usernames.append(f'{stat[1]}\n') races.append(str(stat[2])) usernames = ''.join(usernames) races = '\n'.join(races) embed.add_field( name='Team Members', value=usernames ) embed.add_field( name="Races", value=races ) try: user = await self.client.fetch_user(data['other']['author']) await user.send(embed=embed) await user.send('Your conpetition has ended! Comp ID: `'+compid+'`. Check out the other categories of your competition by doing `n.lb '+compid+'` and adding `speed`, `accuracy`, `races`, or `points`. Ex: `n.lb '+compid+' points`') except: pass data['other']['ended'] = True await dbclient.update_array(dbclient.db["test"], old, data) print('Auto Update Done')