async def register(self, ctx, *, msg): parser = Arguments(allow_abbrev=False, prog='sudo register') parser.add_argument('user', type=choices.user(ctx.message.channel.server)) parser.add_argument('username', nargs='+') await self.bot.send_typing(ctx.message.channel) args = await parser.do_parse(self.bot, msg) if not args: return # Joining username args.username = '******'.join(args.username) # Checking if username is registered already if User.select().where(User.nitro_name % args.username).first(): await self.bot.say( '**%s** is already registered to another user.' % args.username ) return # Getting profile for user profile = await get_profile(args.username) # Checking if username has profile if not profile: await self.bot.say('No profile found with the name **%s**.' % args.username) await self.bot.cogs['Register'].update_discord_user( args.user, self.bot, profile, ctx.message.channel.server.roles) await self.bot.say('Successfully registered %s racer **%s**.' % (args.user.mention, profile['username']))
async def prune(self, ctx, *, msg=''): parser = Arguments(allow_abbrev=False, prog='sudo prune') parser.add_argument('-b', '--bot', action='store_true', default=False, help='Deletes messages from bots.') parser.add_argument('-e', '--embeds', action='store_true', default=False, help='Deletes messages with embeds.') parser.add_argument('-c', '--contains', nargs='?', default=None, help='Deletes messages containing a phrase.') parser.add_argument('-u', '--user', nargs='?', default=None, type=choices.user(ctx.message.channel.server), help='Deletes messages from a user.') parser.add_argument( '-l', '--limit', type=choices.between(1, 1000, True), default=100, help= 'The number of messages to look through to see what messages can be purged.' ) await self.bot.send_typing(ctx.message.channel) args = await parser.do_parse(self.bot, msg) if not args: return _all = not args.bot and not args.embeds and args.contains is None and args.user is None deleted_messages = await self.bot.purge_from( ctx.message.channel, limit=args.limit, check=lambda m: _all or (args.bot and m.author.bot) or (m.id == ctx.message.id) or (args.embeds and (m.embeds or m.attachments)) or (args.user and m.author.id == args.user.id) or (args.contains and args.contains.lower() in m.content.lower())) await self.bot.say('Deleted **{:,}** messages.'.format( len(deleted_messages)), delete_after=5)
async def unregister(self, ctx, *, msg): parser = Arguments(allow_abbrev=False, prog='sudo register') parser.add_argument('user', type=choices.user(ctx.message.channel.server)) await self.bot.send_typing(ctx.message.channel) args = await parser.do_parse(self.bot, msg) if not args: return # Checking if the user is in the DB u = User.select().where(User.id == args.user.id).first() if not u: await self.bot.say( '**%s**\'s Discord account is not linked to Nitro Type.' % args.user.display_name) return await self.bot.cogs['Unregister'].update_discord_user( self.bot, args.user, u) await self.bot.say( '**%s**\'s Nitro Type account has been unregistered.' % args.user.display_name)
formatted_link.append(parsed_link['scheme']) if not parsed_link['netloc']: formatted_link.append('travel.state.gov') else: formatted_link.append(parsed_link['netloc']) formatted_link.extend([ parsed_link['path'], parsed_link['params'], parsed_link['query'], parsed_link['fragment'] ]) return build_url_from_parts(formatted_link) def get_country(self, links=None): for link in links: if link['link'].find('/country/') != -1: try: return link['link'].split('/country/')[1].split( '.html')[0].replace('-', ' ') except Exception as e: logger.error(e) def get_region(self): pass if __name__ == "__main__": args = Arguments() args.add_argument('--alerts') alerts_source = args.get('alerts', str()) reader = TravelAlertsReader(alerts_path=alerts_source) reader.read_travel_alerts()
if not parsed_link['netloc']: formatted_link.append('travel.state.gov') else: formatted_link.append(parsed_link['netloc']) formatted_link.extend([ parsed_link['path'], parsed_link['params'], parsed_link['query'], parsed_link['fragment'] ]) return build_url_from_parts(formatted_link) def get_country(self, links=None): for link in links: if link['link'].find('/country/') != -1: try: return link['link'].split('/country/')[1].split('.html')[0].replace('-', ' ') except Exception as e: logger.error(e) def get_region(self): pass if __name__ == "__main__": args = Arguments() args.add_argument('--alerts') alerts_source = args.get('alerts', str()) reader = TravelAlertsReader(alerts_path=alerts_source) reader.read_travel_alerts()
async def stats(self, ctx, *, msg=''): parser = Arguments(allow_abbrev=False, prog='stats') parser.add_argument( 'user', nargs='?', type=user(ctx.message.channel.server), default=ctx.message.author, help= 'The name of the user to look up Nitro Type stats for. (As a mention)' ) await self.bot.send_typing(ctx.message.channel) args = await parser.do_parse(self.bot, msg) # Checking if parse was success if not args: return nitro_record = User.select().where( User.id == args.user.id).limit(1).first() # Checking if the is a user for the duser if not nitro_record: await self.bot.say( 'That user does not have their Discord account linked to Nitro Type.' ) return profile = await get_profile(nitro_record.nitro_name) # Checking if the profile was found if not profile: await self.bot.say( 'Could not retrieve **%s**\'s Nitro Type account.' % nitro_record.nitro_name) return with Image.open('assets/images/stats_template.png') as i: d = ImageDraw.Draw(i) fnt_bold = ImageFont.truetype('assets/fonts/DroidSerif-Bold.ttf', 22) fnt_reg = ImageFont.truetype('assets/fonts/DroidSerif-Regular.ttf', 16) # Racing record text d.text((35, 96), '{:,} WPM'.format(profile['avgSpeed']), '#2f93db', font=fnt_bold) d.text((194, 96), '{:,} WPM'.format(profile['highestSpeed']), '#2f93db', font=fnt_bold) # Profile info text d.text((396, 96), '${:,}'.format(profile['money'] + profile['moneySpent']), '#44b938', font=fnt_bold) d.text((578, 96), '${:,}'.format(profile['moneySpent']), '#44b938', font=fnt_bold) d.text((761, 96), '%s' % datetime.fromtimestamp( profile['createdStamp']).strftime('%b %d, %Y'), '#2f93db', font=fnt_bold) d.text((87, 186), 'x{:,}'.format(profile['placed1']), '#2f93db', font=fnt_reg) d.text((193, 186), 'x{:,}'.format(profile['placed2']), '#2f93db', font=fnt_reg) d.text((299, 186), 'x{:,}'.format(profile['placed3']), '#2f93db', font=fnt_reg) fnt_reg.size = 10 d.text((162, 262 - 4), '{:,} races'.format(profile['racesPlayed']), '#2f93db', font=fnt_reg) d.text((162, 296 - 4), '{:,} races'.format(profile['longestSession']), '#2f93db', font=fnt_reg) d.text((162, 330 - 4), '{:,} nitros'.format(profile['nitrosUsed']), '#2f93db', font=fnt_reg) # Race summary text fnt_reg.size = 15 offset = [0, 3, -38, -57] for x in range(4): b = profile['boards'][x] played = b.get('played', 0) rank = b.get('rank', 0) wpm = int(round(b['typed'] / 5 / (float(b['secs']) / 60))) \ if b.get('secs', False) is not False else 0 acc = round(100 - b['errs'] / b['typed'] * 100, 2) \ if b.get('secs', False) is not False else 0 d.text((246 + (x * 199) + offset[x], 509), '{:,}'.format(played), '#2f93db', font=fnt_reg) d.text((246 + (x * 199) + offset[x], 557), '{:,} WPM'.format(wpm), '#2f93db', font=fnt_reg) d.text((246 + (x * 199) + offset[x], 605), '{}%'.format(acc), '#2f93db', font=fnt_reg) d.text((246 + (x * 199) + offset[x], 653), '{:,}'.format(rank), '#2f93db', font=fnt_reg) del d del fnt_bold del fnt_reg with BytesIO() as b: i.save(b, 'PNG') b.seek(0) await self.bot.send_file( ctx.message.channel, b, filename='stats.png', content='<https://www.nitrotype.com/racer/%s>' % profile['username']) gc.collect()
metadata = dict() metadata['title'] = self.get_title() metadata['subtitle'] = self.get_subtitle() metadata['description'] = self.get_description() return metadata def get_title(self): return self.raw_feed.feed.title def get_subtitle(self): return self.raw_feed.feed.subtitle def get_description(self): return self.raw_feed.feed.description def get_feed_entries(self): return self.raw_feed.entries def read_feed(self): feed = dict() feed['metadata'] = self.get_feed_metadata() feed['entries'] = self.get_feed_entries() return feed if __name__ == "__main__": args = Arguments() args.add_argument('--feed') feed_source = args.get('feed', str()) reader = FeedReader(feed_path=feed_source)
async def racer(self, ctx, *, msg=''): parser = Arguments(allow_abbrev=False, prog='racer') parser.add_argument( 'user', type=user(ctx.message.channel.server), default=ctx.message.author, nargs='?', help= 'The name of the user to look up Nitro racer card for. (As a mention)' ) await self.bot.send_typing(ctx.message.channel) args = await parser.do_parse(self.bot, msg) # Checking if parse was success if not args: return nitro_record = User.select().where( User.id == args.user.id).limit(1).first() # Checking if the is a user for the duser if not nitro_record: await self.bot.say( 'That user does not have their Discord account linked to Nitro Type.' ) return profile = await get_profile(nitro_record.nitro_name) # Checking if the profile was found if not profile: await self.bot.say( 'Could not retrieve **%s**\'s Nitro Type account.' % nitro_record.nitro_name) return with Image.open('assets/images/racer_template.png') as i: i.convert('RGBA') fnt_12 = ImageFont.truetype('assets/fonts/DroidSerif-Regular.ttf', 12) fnt_16 = ImageFont.truetype('assets/fonts/DroidSerif-Regular.ttf', 16) fnt_18 = ImageFont.truetype('assets/fonts/DroidSerif-Regular.ttf', 18) d = ImageDraw.Draw(i) # Preparing data is_gold = profile['membership'] == 'gold' top3 = len([ b for b in profile['boards'] if b.get('rank', 0) <= 3 and b.get('rank', 0) != 0 ]) > 0 money = '${:,}'.format(profile['money']) nitros = '{:,} Nitros'.format(profile['nitros']) car_name = get_car_name(profile['carID']) title = profile['title'] name = ('' if not profile['tag'] else '[%s] ' % profile['tag'])\ + (profile['displayName'] or profile['username']) # Applying banner img = 'assets/images/banner_gold.png' if is_gold else 'assets/images/banner_silver.png' with Image.open(img) as b: i.paste(b, (1, 13), b) # Applying top 3 if top3: with Image.open('assets/images/scoreboard_champion.png') as b: i.paste(b, (31, 111), b) # Title stuff d.text((149 - fnt_18.getsize(name)[0] / 2, 66), name, fill='#333' if is_gold else '#2f93db', font=fnt_18) d.text((149 - fnt_12.getsize(title)[0] / 2, 41), profile['title'], fill='#333', font=fnt_12) d.text((338, 41), str(profile['level']), fill='#2f93db', font=fnt_18) if is_gold: d.text((338, 73), 'Nitro Type Gold Member', fill='#fed034', font=fnt_16) # Stats stuff d.text((31, 173), car_name, fill='#2f93db', font=fnt_16) d.text((31, 221), money, fill='#44b938', font=fnt_16) d.text((31, 269), nitros, fill='#2f93db', font=fnt_16) # Drawing car car = await get_car(profile['carID'], profile['carHueAngle']) with Image.open(car) as c: with c.convert('RGBA') as c1: i.paste(c1, (599 - c.size[0], 280 - c.size[1]), c1) car.close() del fnt_12, fnt_16, fnt_18, d, car with BytesIO() as b: i.save(b, 'PNG') b.seek(0) await self.bot.send_file( ctx.message.channel, b, filename='racer.png', content='<https://www.nitrotype.com/racer/%s>' % profile['username']) gc.collect()