import prettytable
import discord
import os
import re
from urllib.parse import urlparse
from PythonGists import PythonGists
from discord.ext import commands
from cogs.utils.checks import embed_perms, cmd_prefix_len

'''Module for server commands.'''


class Server:

    def __init__(self, bot):
        self.bot = bot
        self.invites = ['discord.gg/', 'discordapp.com/invite/']
        self.invite_domains = ['discord.gg', 'discordapp.com']

    def find_server(self, msg):
        server = None
        if msg:
            try:
                float(msg)
                server = self.bot.get_guild(int(msg))
                if not server:
                    return self.bot.bot_prefix + 'Server not found.', False
            except:
                for i in self.bot.guilds:
                    if i.name.lower() == msg.lower().strip():
                        server = i
                        break
                if not server:
                    return self.bot.bot_prefix + 'Could not find server. Note: You must be a member of the server you are trying to search.', False

        return server, True

    # Stats about server
    @commands.group(aliases=['server', 'sinfo', 'si'], pass_context=True, invoke_without_command=True)