예제 #1
0
async def time(ctx: MtgContext, *, args: str) -> None:
    """Current time in location."""
    if len(args) == 0:
        return await ctx.send(
            '{author}: No location provided. Please type !time followed by the location you want the time for.'
            .format(author=ctx.author.mention))
    try:
        twentyfour = configuration.get_bool(
            f'{guild_or_channel_id(ctx.channel)}.use_24h'
        ) or configuration.get_bool(f'{ctx.channel.id}.use_24h')
        ts = fetcher.time(args, twentyfour)
        times_s = ''
        for t, zones in ts.items():
            cities = sorted(
                set(
                    re.sub('.*/(.*)', '\\1', zone).replace('_', ' ')
                    for zone in zones))
            times_s += '{cities}: {t}\n'.format(cities=', '.join(cities), t=t)
        await ctx.send(times_s)
    except NotConfiguredException:
        await ctx.send('The time command has not been configured.')
    except TooFewItemsException:
        logging.exception('Exception trying to get the time for %s.', args)
        await ctx.send(
            '{author}: Location not found.'.format(author=ctx.author.mention))
예제 #2
0
 async def time(self, client: Client, channel: Channel, args: str, author: Member, **_: Dict[str, Any]) -> None:
     """`!time {location}` Show the current time in the specified location."""
     try:
         t = fetcher.time(args.strip())
     except TooFewItemsException:
         logging.exception('Exception trying to get the time for %s.', args)
         return await client.send_message(channel, '{author}: Location not found.'.format(author=author.mention))
     await client.send_message(channel, '{args}: {time}'.format(args=args, time=t))
예제 #3
0
 async def time(self, bot, channel, args, author):
     """`!time {location}` Show the current time in the specified location."""
     try:
         t = fetcher.time(args.strip())
     except TooFewItemsException:
         return await bot.client.send_message(
             channel,
             '{author}: Location not found.'.format(author=author.mention))
     await bot.client.send_message(
         channel, '{args}: {time}'.format(args=args, time=t))
예제 #4
0
 async def time(self, bot, channel, args, author):
     """`!time {location}` Show the current time in the specified location."""
     t = fetcher.time(args.strip())
     await bot.client.send_message(
         channel, '{args}: {time}'.format(args=args, time=t))