Skip to content
Snippets Groups Projects
utils.py 891 B
Newer Older
  • Learn to ignore specific revisions
  • dnns01's avatar
    dnns01 committed
    import disnake
    
    
    
    async def send_dm(user, message, embed=None):
        """ Send DM to a user/member """
    
    
    dnns01's avatar
    dnns01 committed
        if type(user) is disnake.User or type(user) is disnake.Member:
    
            if user.dm_channel is None:
                await user.create_dm()
    
            await user.dm_channel.send(message, embed=embed)
    
    
    def is_mod(ctx):
        author = ctx.author
        roles = author.roles
    
        for role in roles:
    
            if role.id in [int(os.getenv("DISCORD_MOD_ROLE")), int(os.getenv("DISCORD_ADMIN_ROLE"))]:
    
                return True
    
        return False
    
    
    def is_valid_time(time):
        return re.match(r"^\d+[mhd]?$", time)
    
    
    def to_minutes(time):
        if time[-1:] == "m":
            return int(time[:-1])
        elif time[-1:] == "h":
            h = int(time[:-1])
            return h * 60
        elif time[-1:] == "d":
            d = int(time[:-1])
            h = d * 24
            return h * 60
    
        return int(time)