async def top(self, ctx, count=3): typing_task = asyncio.ensure_future(ctx.channel.trigger_typing()) logger.info(f'Command invoked: top | {count}') response = self._send_karma_list(ctx, count, reverse=True) await typing_task await ctx.send(embed=response)
async def on_ready(): start_time = Timing.start() logger.info(f'Logged in as {bot.user.name}') logger.info('--------') logger.info(f'Karma Bot Version: {karma.__version__}') logger.info(f'Current Discord.py Version: {discord.__version__} | Current Python Version: {platform.python_version()}') logger.info(f'Startup time: {Timing.human_readable(start_time)}')
async def uptime(self, ctx): logger.info('Command invoked - uptime') uptime = Timing.get_uptime_readable() response = f'Uptime: {uptime}' logger.info(f'Response - {response}') await ctx.send(response)
async def all(self, ctx): typing_task = asyncio.ensure_future(ctx.channel.trigger_typing()) logger.info("Command invoked: all") result = db.get_all_karma() sorted_karma = sorted(result, key=lambda k: k.karma, reverse=True) response = karma_summary(sorted_karma, ctx.guild) await typing_task await ctx.send(embed=response)
async def get(self, ctx, *args): logger.info("Command invoked: get | {}".format(*args)) pattern = re.compile(r'<@!?(?P<user_id>\d+)>') for key in args: match = pattern.search(key) if match: entry = db.get_karma(match.group('user_id')) await ctx.send('<@%s> has %d total karma' % (entry.discord_id, entry.karma)) else: await ctx.send(f'Could not find user: {key}')
def karma_summary(items, guild, count=None): if not count: count = len(items) items = items[:count] # trim list if requested user_list = [] for pos, user in enumerate(items, start=1): member = guild.get_member(int(user.discord_id)) if member: logger.info(f'Found member: {member.name} ({member.id})') line = '({}) **{:24}**'.format( user.karma, member.name if member else 'Unknown User :ghost:') user_list.append(line) output = discord.Embed(title='Karma Summary', description=iconise_list(user_list), colour=discord.Colour.purple()) if count > len(items): output.description += '\n\n*No more entries available*' return output
def main(): logger.info('Generating data ...') timezone = tzlocal.get_localzone() end_time = timezone.localize(datetime.now()) start_time = end_time - relativedelta(weeks=5) current_time = start_time parser = argparse.ArgumentParser() parser.add_argument('-d', '--db-path', type=str, default='.') args = parser.parse_args() db.init(path=args.db_path) while current_time < end_time: for person in community: todays_roll = get_votes() for x in range(todays_roll): # Select a random person ... without = list(community) without.remove(person) giver = random.choice(without) message = MockMessage(person, giver) db.update_karma(person, 1) db.add_karma_event( message, person, 1, current_time.timestamp() ) logger.info(f'Current person {person} assigned {todays_roll} karma at {current_time}') current_time += relativedelta(days=1) logger.info(f'New time is {current_time}')
async def sync(self, ctx): logger.info('Command invoked - sync') db.sync_karma() await ctx.send('Sync complete!')