Esempio n. 1
0
 def __init__(self, **kwargs):
     self.config = ConfigHandler("config")
     self.main_db = asyncio.get_event_loop().run_until_complete(
         DatabaseHandler.create_instance())
     self.up_time_start_time = get_current_time()
     super(Bot, self).__init__(command_prefix=self.prefix_callable,
                               help_command=None,
                               description=self.config["bot_description"],
                               case_insensitive=True,
                               **kwargs)
Esempio n. 2
0
    async def member_data(self, ctx, member: discord.Member = None):
        """
        Shows active subscriptions of member.
        Sends result in DMs

        """

        if member is None:
            member = ctx.author
        else:
            # If called member is the same as author allow him to see since it's himself
            if ctx.author == member:
                pass
            # We require admin permissions if you want to see other members data
            elif not ctx.author.guild_permissions.administrator:
                await ctx.send(embed=failure(
                    "You need administrator permission to see other members data."
                ))
                return

        table = texttable.Texttable(max_width=90)
        table.set_cols_dtype(["t", "t"])
        table.set_cols_align(["c", "c"])
        header = ("Licensed role", "Expiration date")
        table.add_row(header)

        all_active = await self.bot.main_db.get_member_data(
            ctx.guild.id, member.id)
        if not all_active:
            await ctx.send(
                embed=failure(f"Nothing to show for {member.mention}."))
            return

        for entry in all_active:
            # Entry is in form ("license_id", "expiration_date)
            try:
                role = ctx.guild.get_role(int(entry[0]))
                table.add_row((role.name, entry[1]))
            except (ValueError, AttributeError):
                # Just in case if error in case role is None (deleted from guild) just show IDs from database
                table.add_row(entry)

        local_time = get_current_time()
        title = (
            f"Server local time: {local_time}\n\n"
            f"{member.name} active subscriptions in guild '{ctx.guild.name}':\n\n"
        )

        await ctx.send(embed=info("Sent in Dms!", ctx.me), delete_after=5)
        await Paginator.paginate(self.bot,
                                 ctx.author,
                                 ctx.author,
                                 table.draw(),
                                 title=title,
                                 prefix="```DNS\n")
Esempio n. 3
0
 async def has_license_expired(expiration_date: datetime) -> bool:
     """
     Check if param expiration date is in past related to the current date.
     If it is in past then license is considered expired.
     :param expiration_date: datetime object
     :return: True if license is expired, False otherwise
     """
     if expiration_date < get_current_time():
         # Expired
         return True
     else:
         return False
Esempio n. 4
0
    def last_boot(self) -> str:
        """
        :return: str last boot time

        """
        return time_ago(get_current_time() - self.bot.up_time_start_time)
Esempio n. 5
0
 def last_boot(self) -> str:
     """Returns humanized last boot time."""
     return time_ago(get_current_time() - self.bot.up_time_start_time)