Exemplo n.º 1
0
 async def save(self, ctx):
     if not utils.is_staff(ctx.author):
         return
     if not await utils.save_db():
         await utils.embed_reply(
             ctx, title="💢 Failed to save remote database!")
     else:
         await ctx.message.add_reaction('👌')
     await ctx.reply(file=discord.File('db.sqlite3'))
     await ctx.author.send(file=discord.File('db.sqlite3'))
Exemplo n.º 2
0
 async def gibxp_assistance(self,
                            ctx,
                            target: Union[discord.Member, discord.User, int,
                                          str] = None,
                            amount: int = 0):
     if not utils.is_staff(ctx.author):
         return
     # Convert target input to discord.Member
     if not target:
         await utils.embed_reply(ctx,
                                 title="💢 Please provide a valid user!")
         return
     if isinstance(target, int):
         target = ctx.guild.get_member(target)
     elif isinstance(target, str):
         target = utils.strip_argument(target)
         target = await utils.get_best_member_match(ctx, target)
     elif isinstance(target, discord.User):
         target = ctx.guild.get_member(target.id)
     elif isinstance(target, discord.Member):
         pass
     else:
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid user!")
         return
     if not target:
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid user!")
         return
     # Handle amount
     try:
         amount = int(utils.strip_argument(amount))
     except (
             TypeError,
             ValueError,
     ):
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid amount!")
         return
     # Actual command
     _, _, assistance_xp = await db.add_user_xp(target.id,
                                                assistance=amount)
     await utils.embed_reply(
         ctx,
         description=(
             f"👌 Gave {amount} assistance XP to <@!{target.id}>!\n"
             if amount >= 0 else
             f"👌 Took {-amount} assistance XP from <@!{target.id}>!\n") +
         f"New assistance XP value: `{assistance_xp}`")
Exemplo n.º 3
0
 async def setxp_cred(self,
                      ctx,
                      target: Union[discord.Member, discord.User, int,
                                    str] = None,
                      amount: int = 0):
     if not utils.is_staff(ctx.author):
         return
     # Convert target input to discord.Member
     if not target:
         await utils.embed_reply(ctx,
                                 title="💢 Please provide a valid user!")
         return
     if isinstance(target, int):
         target = ctx.guild.get_member(target)
     elif isinstance(target, str):
         target = utils.strip_argument(target)
         target = await utils.get_best_member_match(ctx, target)
     elif isinstance(target, discord.User):
         target = ctx.guild.get_member(target.id)
     elif isinstance(target, discord.Member):
         pass
     else:
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid user!")
         return
     if not target:
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid user!")
         return
     # Handle amount
     try:
         amount = int(utils.strip_argument(amount))
     except (
             TypeError,
             ValueError,
     ):
         await utils.embed_reply(ctx,
                                 title="💢 That is not a valid amount!")
         return
     # Actual command
     _, cred_xp, _ = await db.set_user_xp(target.id, cred=amount)
     await utils.embed_reply(
         ctx,
         description=f"👌 Set <@!{target.id}>'s cred XP successfully!\n"
         f"New cred XP value: `{cred_xp}`")
Exemplo n.º 4
0
 async def restore(self, ctx):
     if not utils.is_staff(ctx.author):
         return
     db_bytes = None
     for attachment in ctx.message.attachments:
         if attachment.filename == "db.sqlite3":
             async with globals.http.get(attachment.url) as req:
                 db_bytes = await req.read()
             break
     if not db_bytes:
         await utils.embed_reply(ctx,
                                 title='💢 Please attach a "db.sqlite3"!')
         return
     await globals.db.commit()
     await globals.db.close()
     async with aiofiles.open('db.sqlite3', 'wb') as f:
         await f.write(db_bytes)
     await db.init_db()
     if not await utils.save_db():
         await utils.embed_reply(
             ctx, title="💢 Failed to save remote database!")
     else:
         await ctx.message.add_reaction('👌')
Exemplo n.º 5
0
 async def help(self, ctx, subcommand=None):
     prfx = globals.BOT_PREFIX.lower()
     if subcommand:
         subcommand = utils.strip_argument(subcommand)
     if subcommand and subcommand.lower().startswith(prfx):
         subcommand = subcommand[len(prfx):]
     if subcommand:
         subcommand = subcommand.lower()
         for cog_name in globals.bot.cogs:
             if cog_name.lower() == "jishaku":
                 continue
             if cog_name.lower() == subcommand:
                 cog = globals.bot.get_cog(cog_name)
                 desc = ""
                 if "staff" in cog_name.lower() and not utils.is_staff(
                         ctx.author):
                     desc += "These are **staff only** commands, you can't use them!\n\n"
                 desc += cog.description + "\n\n"
                 for command in sorted(cog.get_commands(),
                                       key=lambda x: x.name):
                     desc += f'{prfx}**{command.name}**: ' + (
                         command.description[:command.description.
                                             find("\n")] if "\n" in command.
                         description else command.description) + '\n'
                 desc += f"\nYou can use `{prfx}help [ command ]` to see more info about it!\n"
                 desc += f"**\nA.L.T.I.E.R.A. Bot**{(' `' + os.environ.get('HEROKU_RELEASE_VERSION') + '`') if os.environ.get('HEROKU_RELEASE_VERSION') else ''}, made with ❤️ by [WillyJL](https://linktr.ee/WillyJL)"
                 await utils.embed_reply(
                     ctx,
                     title=f"⁉️   A.L.T.I.E.R.A. Help  >  {cog_name}",
                     description=desc)
                 return
         for command in globals.bot.commands:
             cog_name = command.cog.qualified_name
             if cog_name.lower() == "jishaku":
                 continue
             aliases = [alias.lower() for alias in command.aliases]
             if command.name.lower() == subcommand or subcommand in aliases:
                 desc = ""
                 if "staff" in cog_name.lower() and not utils.is_staff(
                         ctx.author):
                     desc += "This is a **staff only** command, you can't use it!\n\n"
                 desc += command.description + "\n\n"
                 desc += "**Usage**: `" + command.usage.format(
                     prfx=prfx) + "`\n"
                 if command.help:
                     desc += command.help + "\n"
                 if aliases:
                     desc += f"\n**Aliases**: `{prfx}" + f"`, `{prfx}".join(
                         aliases) + "`\n"
                 desc += f"**\nA.L.T.I.E.R.A. Bot**{(' `' + os.environ.get('HEROKU_RELEASE_VERSION') + '`') if os.environ.get('HEROKU_RELEASE_VERSION') else ''}, made with ❤️ by [WillyJL](https://linktr.ee/WillyJL)"
                 await utils.embed_reply(
                     ctx,
                     title=
                     f"⁉️   A.L.T.I.E.R.A. Help  >  {cog_name}  >  {prfx}{command.name}",
                     description=desc)
                 return
     desc = "You can use these commands to see a category of commands:\n\n"
     for cog_name in sorted(list(globals.bot.cogs)):
         if cog_name.lower() == "jishaku":
             continue
         if "staff" in cog_name.lower() and not utils.is_staff(ctx.author):
             continue
         cog = globals.bot.get_cog(cog_name)
         desc += f"{prfx}help **{cog_name.lower()}**: " + (
             cog.description[:cog.description.find('\n')]
             if '\n' in cog.description else cog.description) + "\n"
     desc += f"\nYou can use `{prfx}help [ command ]` to see more info about it!\n"
     desc += f"\n**A.L.T.I.E.R.A. Bot**{(' `' + os.environ.get('HEROKU_RELEASE_VERSION') + '`') if os.environ.get('HEROKU_RELEASE_VERSION') else ''}, made with ❤️ by [WillyJL](https://linktr.ee/WillyJL)"
     await utils.embed_reply(ctx,
                             title="⁉️   A.L.T.I.E.R.A. Help",
                             description=desc)
     return
Exemplo n.º 6
0
 async def stats(self,
                 ctx,
                 target: Union[discord.Member, discord.User, int,
                               str] = None):
     # Convert target input to discord.Member
     if not target:
         target = ctx.author
     if isinstance(target, int):
         target = ctx.guild.get_member(target)
     elif isinstance(target, str):
         target = utils.strip_argument(target)
         target = await utils.get_best_member_match(ctx, target)
     elif isinstance(target, discord.User):
         target = ctx.guild.get_member(target.id)
     elif isinstance(target, discord.Member):
         pass
     else:
         await utils.embed_reply(ctx, title="💢 That is not a valid user!")
         return
     if not target:
         await utils.embed_reply(ctx, title="💢 That is not a valid user!")
         return
     # Actual command
     level_xp, cred_xp, assistance_xp = await db.get_user_xp(target.id)
     level = xp.xp_to_lvl(level_xp)
     cred = xp.xp_to_lvl(cred_xp)
     assistance = xp.xp_to_lvl(assistance_xp)
     level_next = math.floor((level[2] - level[1]) * 100 / level[2])
     cred_next = math.floor((cred[2] - cred[1]) * 100 / cred[2])
     assistance_next = math.floor(
         (assistance[2] - assistance[1]) * 100 / assistance[2])
     # Setup image foundation
     if target.id == globals.ADMIN_ID:
         img = Image.open("assets/backgrounds/admin.png")
     elif utils.is_staff(target):
         img = Image.open("assets/backgrounds/staff.png")
     else:
         img = Image.open("assets/backgrounds/default.png")
     draw = ImageDraw.Draw(img)
     # Draw user avatar
     if str(target.avatar_url).startswith(
             "https://cdn.discordapp.com/embed/avatars"):
         avatar = globals.default_avatar
     else:
         avatar = (await
                   utils.pil_img_from_link(str(target.avatar_url))).resize((
                       200,
                       200,
                   ))
     try:
         img.paste(avatar, (
             24,
             18,
         ), avatar)
     except ValueError:
         img.paste(avatar, (
             24,
             18,
         ))
     # Apply base overlay
     if target.id == globals.ADMIN_ID:
         img.paste(globals.overlays_admin, (
             0,
             0,
         ), globals.overlays_admin)
     elif utils.is_staff(target):
         img.paste(globals.overlays_staff, (
             0,
             0,
         ), globals.overlays_staff)
     else:
         img.paste(globals.overlays_default, (
             0,
             0,
         ), globals.overlays_default)
     # Draw username
     username = target.name.encode('ascii', 'replace').decode(
         'ascii')  # Remove non-ascii glyphs
     utils.draw_text(draw, globals.font35, username, "#FFFFFF", (
         268,
         85,
     ), 298)
     # Draw main level and cred values
     utils.draw_text(draw, globals.font47, f"LV:{level[0]}", "#009EDF", (
         277,
         141,
     ), 999)
     if target.id == globals.ADMIN_ID:
         utils.draw_text(draw, globals.font47, f"SC:{cred[0]}", "#16F2D6", (
             434,
             141,
         ), 999)
     else:
         utils.draw_text(draw, globals.font47, f"SC:{cred[0]}", "#F06B02", (
             434,
             141,
         ), 999)
     # Draw trophy shards
     x = 267
     for i in range(utils.get_trophy_amount(target)):
         if i % 2:
             img.paste(globals.shards_white, (
                 x,
                 194,
             ), globals.shards_white)
         else:
             if target.id == globals.ADMIN_ID:
                 img.paste(globals.shards_teal, (
                     x,
                     194,
                 ), globals.shards_teal)
             else:
                 img.paste(globals.shards_orange, (
                     x,
                     194,
                 ), globals.shards_orange)
         x += 24
     # Draw single level values
     if target.id == globals.ADMIN_ID:
         utils.draw_text(draw, globals.font16, "LVL:", "#090D18", (
             275,
             425,
         ), 999)
         utils.draw_text(draw, globals.font24, f"{level[0]}", "#090D18", (
             308,
             423,
         ), 999)
     else:
         utils.draw_text(draw, globals.font16, "LVL:", "#FFFFFF", (
             275,
             425,
         ), 999)
         utils.draw_text(draw, globals.font24, f"{level[0]}", "#FFFFFF", (
             308,
             423,
         ), 999)
     utils.draw_text(draw, globals.font16, "LVL:", "#FFFFFF", (
         275,
         518,
     ), 999)
     utils.draw_text(draw, globals.font24, f"{cred[0]}", "#FFFFFF", (
         308,
         516,
     ), 999)
     if target.id == globals.ADMIN_ID:
         utils.draw_text(draw, globals.font16, "LVL:", "#009EDF", (
             275,
             619,
         ), 999)
         utils.draw_text(draw, globals.font24, f"{assistance[0]}",
                         "#009EDF", (
                             308,
                             617,
                         ), 999)
     else:
         utils.draw_text(draw, globals.font16, "LVL:", "#F06B02", (
             275,
             619,
         ), 999)
         utils.draw_text(draw, globals.font24, f"{assistance[0]}",
                         "#F06B02", (
                             308,
                             617,
                         ), 999)
     # Draw single percentage values
     if level_next >= 100:
         utils.draw_text(draw, globals.font30, "MAX", "#090D18", (
             579 - globals.font30.getsize("MAX")[0],
             398,
         ), 999)
     else:
         utils.draw_text(draw, globals.font30, f"{level_next}", "#090D18", (
             565 - globals.font30.getsize(f"{level_next}")[0],
             398,
         ), 999)
         utils.draw_text(draw, globals.font20, "%", "#090D18", (
             565,
             407,
         ), 999)
     if cred_next >= 100:
         utils.draw_text(draw, globals.font30, "MAX", "#090D18", (
             579 - globals.font30.getsize("MAX")[0],
             491,
         ), 999)
     else:
         utils.draw_text(draw, globals.font30, f"{cred_next}", "#090D18", (
             565 - globals.font30.getsize(f"{cred_next}")[0],
             491,
         ), 999)
         utils.draw_text(draw, globals.font20, "%", "#090D18", (
             565,
             500,
         ), 999)
     if assistance_next >= 100:
         utils.draw_text(draw, globals.font30, "MAX", "#090D18", (
             579 - globals.font30.getsize("MAX")[0],
             593,
         ), 999)
     else:
         utils.draw_text(
             draw, globals.font30, f"{assistance_next}", "#090D18", (
                 565 - globals.font30.getsize(f"{assistance_next}")[0],
                 593,
             ), 999)
         utils.draw_text(draw, globals.font20, "%", "#090D18", (
             565,
             602,
         ), 999)
     # Overlay percentage bars
     if target.id == globals.ADMIN_ID:
         level_bar = globals.bars["teal_white"][
             utils.get_bar_index_from_lvl_percent(level_next)]
         cred_bar = globals.bars["blue_white"][
             utils.get_bar_index_from_lvl_percent(cred_next)]
         assistance_bar = globals.bars["white_blue"][
             utils.get_bar_index_from_lvl_percent(assistance_next)]
     else:
         level_bar = globals.bars["blue_white"][
             utils.get_bar_index_from_lvl_percent(level_next)]
         cred_bar = globals.bars["orange_white"][
             utils.get_bar_index_from_lvl_percent(cred_next)]
         assistance_bar = globals.bars["white_orange"][
             utils.get_bar_index_from_lvl_percent(assistance_next)]
     img.paste(level_bar, (
         218,
         457,
     ), level_bar)
     img.paste(cred_bar, (
         218,
         550,
     ), cred_bar)
     img.paste(assistance_bar, (
         218,
         650,
     ), assistance_bar)
     # Send the image
     binary = io.BytesIO()
     img.save(binary, format="PNG")
     binary.seek(0)
     await ctx.reply(
         file=discord.File(binary, filename=username[:16] + ".png"))
Exemplo n.º 7
0
 async def restart(self, ctx):
     if not utils.is_staff(ctx.author):
         return
     await utils.embed_reply(ctx, title="👌 Restarting...")
     await utils.restart()