<commit_before>import logging

import datetime
import discord
import pycountry
import pytz
from discord.ext.commands import group
from lifesaver.bot import Cog, Context
from lifesaver.bot.storage import AsyncJSONStorage

log = logging.getLogger(__name__)


class Time(Cog):
    def __init__(self, bot):
        super().__init__(bot)
        self.timezones = AsyncJSONStorage('timezones.json', loop=bot.loop)

    def get_time_for(self, user: discord.User):
        timezone = self.timezones.get(user.id)
        if not timezone:
            return None
        their_time = datetime.datetime.now(pytz.timezone(timezone))
        return their_time.strftime('%B %d, %Y  %H:%M:%S (%I:%M:%S %p)')

    @group(invoke_without_command=True, aliases=['t'])
    async def time(self, ctx: Context, *, who: discord.User = None):
        """Views the time for another user."""
        who = who or ctx.author
        formatted_time = self.get_time_for(who)
        await ctx.send(f'{who.display_name}: {formatted_time}')

    @time.command(name='set')
    async def time_set(self, ctx: Context):
        """Sets your current timezone interactively."""
        target = ctx.author

        # TODO: refactor, improve, and build upon ask and prompt into a generic interface. should be usable by others.
        #       it's currently too trashy and narrow the way it stands.
        ask_aborted = object()  # sentinel that indicates abort

        async def ask(prompt, *, determiner, on_fail="Invalid response. Please try again."):
            embed = discord.Embed(color=discord.Color.green(), title='Timezone wizard', description=prompt)
            await target.send(embed=embed)
            while True:
                message = await self.bot.wait_for('message', check=lambda m: not m.guild and m.author == target)
                if message.content == 'cancel':
                    return ask_aborted
                try:
                    value = determiner(message.content)
                    if not value:
                        continue
                    else:
                        return value
                except:<commit_msg>time: handle no assigned time<commit_after>import logging

import datetime
import discord
import pycountry
import pytz
from discord.ext.commands import group
from lifesaver.bot import Cog, Context
from lifesaver.bot.storage import AsyncJSONStorage

log = logging.getLogger(__name__)


class Time(Cog):
    def __init__(self, bot):
        super().__init__(bot)
        self.timezones = AsyncJSONStorage('timezones.json', loop=bot.loop)

    def get_time_for(self, user: discord.User):
        timezone = self.timezones.get(user.id)
        if not timezone:
            return None
        their_time = datetime.datetime.now(pytz.timezone(timezone))
        return their_time.strftime('%B %d, %Y  %H:%M:%S (%I:%M:%S %p)')

    @group(invoke_without_command=True, aliases=['t'])
    async def time(self, ctx: Context, *, who: discord.User = None):
        """Views the time for another user."""
        who = who or ctx.author
        formatted_time = self.get_time_for(who)
        if not formatted_time:
            await ctx.send(
                f'{who.display_name} has not set their time. You can tell them to set their time with '
                f'`{ctx.prefix}time set`.'
            )
            return
        await ctx.send(f'{who.display_name}: {formatted_time}')

    @time.command(name='set')
    async def time_set(self, ctx: Context):
        """Sets your current timezone interactively."""
        target = ctx.author

        # TODO: refactor, improve, and build upon ask and prompt into a generic interface. should be usable by others.
        #       it's currently too trashy and narrow the way it stands.
        ask_aborted = object()  # sentinel that indicates abort

        async def ask(prompt, *, determiner, on_fail="Invalid response. Please try again."):
            embed = discord.Embed(color=discord.Color.green(), title='Timezone wizard', description=prompt)
            await target.send(embed=embed)
            while True:
                message = await self.bot.wait_for('message', check=lambda m: not m.guild and m.author == target)
                if message.content == 'cancel':
                    return ask_aborted
                try:
                    value = determiner(message.content)
                    if not value:
                        continue
                    else:
                        return value
                except:
{'fraction_non_alphanumeric': 0.10011049723756905, 'fraction_numerical': 0.0, 'mean_word_length': 2.2584593232541397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '57693', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1222, 'n_words': 366}