diff options
author | stolenvw <stolenvw@hotmail.com> | 2021-05-07 18:09:12 -0400 |
---|---|---|
committer | stolenvw <stolenvw@hotmail.com> | 2021-05-07 18:09:12 -0400 |
commit | 243495480e880a86d1a4496d132d1ad552ebfb29 (patch) | |
tree | f216d5e4594cdc30691f3cdf9051710fad376c8e /optional | |
parent | 79e5396d15f10e358ae95ba4cff8d401bc45ff22 (diff) |
Added code for showing percent of world explored. Will not show right on an existing world
Diffstat (limited to 'optional')
-rw-r--r-- | optional/explorecmds.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/optional/explorecmds.py b/optional/explorecmds.py new file mode 100644 index 0000000..2ba7537 --- /dev/null +++ b/optional/explorecmds.py @@ -0,0 +1,60 @@ +import discord, typing, config +from discord.ext import commands + +class Explored(commands.Cog): + """ + Explored commands + """ + + def __init__(self, bot): + self.bot = bot + + async def chancheck(ctx): + if ctx.channel.id == config.LOGCHAN_ID or commands.is_owner(): + return True + + @commands.command(name='explored', + brief="Explored stats", + help="Shows total world locations and how many have be explored.", + ) + @commands.has_any_role(config.PLOC_CMD) + @commands.check(chancheck) + async def explored(self, ctx): + ldrembed = discord.Embed(title="World Explored Stats", color=0x33a163) + botsql = self.bot.get_cog('BotSQL') + mycursor = await botsql.get_cursor() + sql = """SELECT COUNT(*) FROM plocinfo WHERE locations IS NULL""" + mycursor.execute(sql) + Info = mycursor.fetchall() + sql1 = """SELECT locations FROM plocinfo WHERE locations IS NOT NULL LIMIT 1""" + mycursor.execute(sql1) + Info1 = mycursor.fetchall() + mycursor.close() + Info=Info[0] + Info1=Info1[0] + ldrembed.add_field(name="Total Locations", + value="{}".format(Info1[0]), + inline=True) + ldrembed.add_field(name="Locations Explored", + value="{}".format(Info[0]), + inline=True) + ldrembed.add_field(name="Percent of World Explored", + value="{}%".format(format(Info[0]/Info1[0]*100, ".2f")), + inline=True) + await ctx.send(embed=ldrembed) + + @explored.error + async def explored_error_handler(self, ctx, error): + if isinstance(error, commands.MissingAnyRole): + if config.USEDEBUGCHAN == True: + bugchan = self.bot.get_channel(config.BUGCHANNEL_ID) + bugerror = discord.Embed(title=":sos: **ERROR** :sos:", description='**{}** Tried to use command: **{}**\n{}'.format(ctx.author, ctx.command, error), color=0xFF001E) + await bugchan.send(embed=bugerror) + if isinstance(error, commands.CheckFailure): + if config.USEDEBUGCHAN == True: + bugchan = self.bot.get_channel(config.BUGCHANNEL_ID) + bugerror = discord.Embed(title=":sos: **ERROR** :sos:", description='**{}** Tried to use command: **{}**\nIn channel **#{}**'.format(ctx.author, ctx.command, ctx.channel), color=0xFF001E) + await bugchan.send(embed=bugerror) + +def setup(bot): + bot.add_cog(Explored(bot)) |