cog_utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Godavaru 作者: Godavaru 项目源码 文件源码
def _time(self, ctx):
        """Determine the current time in a timezone specified.
        The timezone is case sensitive as seen in [this list](https://pastebin.com/B5tLQdEY).

        **Usage:** `g_time <timezone>

        **Permission:** User"""
        umsg = ctx.message.content
        args = umsg.split(' ')
        if len(args) > 1:
            try:
                if args[1].startswith('GMT'):
                    if args[1].startswith('GMT+'):
                        t = args[1].replace('+', '-')
                    elif args[1].startswith('GMT-'):
                        t = args[1].replace('-', '+')
                    tz = pytz.timezone('Etc/'+t)
                else:
                    tz = pytz.timezone(args[1])
                await ctx.send("The time in **{0}** is {1}".format(args[1], datetime.datetime.now(tz).strftime("`%H:%M:%S` on `%d-%b-%Y`")))
            except pytz.UnknownTimeZoneError:
                await ctx.send('Couldn\'t find that timezone, make sure to use one from this list: <https://pastebin.com/B5tLQdEY>\nAlso remember that timezones are case sensitive.')
        else:
            await ctx.send(":x: Usage: `{}time <timezone>`".format(self.bot.command_prefix[0]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号