import os
import re

from redbot.core import checks, Config, commands


class Wat(command.Cog):

    """Repeat messages when other users are having trouble hearing"""

    default_global_settings = {
        "channels_ignored": [],
        "guilds_ignored": []
    }

    def __init__(self, bot):
        self.bot = bot
        self.conf = Config.get_conf(self, identifier=527690525)
        self.conf.register_global(
            **self.default_global_settings
        )

    @commands.group(name="watignore", pass_context=True, no_pm=True)
    @checks.admin_or_permissions(manage_guild=True)
    async def watignore(self, ctx):
        """Change Wat cog ignore settings."""
        pass

    @watignore.command(name="server", pass_context=True, no_pm=True)
    @checks.admin_or_permissions(manage_guild=True)
    async def _watignore_server(self, ctx):
        """Ignore/Unignore the current server"""

        guild = ctx.message.guild
        guilds = await self.conf.guilds_ignored()
        if guild.id in guilds:
            guilds.remove(guild.id)
            await ctx.send("wot? Ok boss, I will no longer "
                           "ignore this server.")
        else:
            guilds.append(guild.id)
            await ctx.send("what? Fine, I will ignore "
                           "this server.")
        await self.conf.guilds_ignored.set(guilds)

    @watignore.command(name="channel", pass_context=True, no_pm=True)
    @checks.admin_or_permissions(manage_guild=True)
    async def _watignore_channel(self, ctx):
        """Ignore/Unignore the current channel"""

        chan = ctx.message.channel
        chans = await self.conf.channels_ignored()
        if chan.id in chans:
            chans.remove(chan.id)
            await ctx.send("wut? Ok, I will no longer "
                           "ignore this channel.")
        else:
            chans.append(chan.id)
            await ctx.send("wat? Alright, I will ignore "
                           "this channel.")
        await self.conf.channels_ignored.set(chans)

    # Come up with a new method to ignore bot commands
    @commands.Cog.listener()
    async def on_message(self, message):
        if message.guild is None:
            return
        if message.author.bot:
            return
        #if self.is_command(message):
        #    return
        content = message.content.lower().split()
        if len(content) != 1:
            return
        if message.guild.id in await self.conf.guilds_ignored():
            return
        if message.channel.id in await self.conf.channels_ignored():
            return

        pattern = re.compile(r'w+h*[aou]+t+[?!]*', re.IGNORECASE)
        if pattern.fullmatch(content[0]):
            async for before in message.channel.history(limit=5, before=message):
                author = before.author
                name = author.display_name
                content = before.clean_content
                if not author.bot\
                        and not author == message.author\
                        and not pattern.fullmatch(content):
                        #and not self.is_command(before)\
                    emoji = "\N{CHEERING MEGAPHONE}"
                    msg = "{0} said, **{1}   {2}**".format(name, emoji,
                                                           content)
                    await message.channel.send(msg)
                    break

@@ -64,16 +64,75 @@
 mmands%0A%0A
+PATTERN = re.compile(r%22w+h*%5Baou%5D+t+%5B?!%5D*%22, re.IGNORECASE)%0A%0A
 %0Aclass W
@@ -141,16 +141,17 @@
 (command
+s
 .Cog):%0A%0A
@@ -252,25 +252,16 @@
 ings = %7B
-%0A        
 %22channel
@@ -275,24 +275,16 @@
 ed%22: %5B%5D,
-%0A       
  %22guilds
@@ -296,21 +296,16 @@
 red%22: %5B%5D
-%0A    
 %7D%0A%0A    d
@@ -449,29 +449,16 @@
 _global(
-%0A            
 **self.d
@@ -479,25 +479,16 @@
 settings
-%0A        
 )%0A%0A    @
@@ -1128,38 +1128,8 @@
 ger 
-%22%0A                           %22
 igno
@@ -1254,38 +1254,8 @@
 ore 
-%22%0A                           %22
 this
@@ -1742,38 +1742,8 @@
 ger 
-%22%0A                           %22
 igno
@@ -1869,38 +1869,8 @@
 ore 
-%22%0A                           %22
 this
@@ -1938,63 +1938,8 @@
 s)%0A%0A
-    # Come up with a new method to ignore bot commands%0A
     
@@ -1987,16 +1987,32 @@
 _message
+_without_command
 (self, m
@@ -2127,66 +2127,8 @@
 urn%0A
-        #if self.is_command(message):%0A        #    return%0A
     
@@ -2407,84 +2407,18 @@
     
-pattern = re.compile(r'w+h*%5Baou%5D+t+%5B?!%5D*', re.IGNORECASE)%0A        if pattern
+if PATTERN
 .ful
@@ -2667,16 +2667,38 @@
      if 
+(%0A                    
 not auth
@@ -2703,17 +2703,16 @@
 thor.bot
-%5C
 %0A       
@@ -2716,36 +2716,32 @@
                 
-    
 and not author =
@@ -2756,19 +2756,17 @@
 e.author
-%5C%0A 
+%0A
         
@@ -2777,27 +2777,24 @@
         
-   
 and not 
 pattern.
@@ -2789,15 +2789,15 @@
 not 
-pattern
+PATTERN
 .ful
@@ -2811,17 +2811,16 @@
 content)
-:
 %0A       
@@ -2832,49 +2832,10 @@
     
-        #and not self.is_command(before)%5C
+):
 %0A   
@@ -2914,11 +2914,15 @@
 g = 
+f
 %22%7B
-0
+name
 %7D sa
@@ -2932,107 +2932,29 @@
  **%7B
-1%7D   %7B2%7D**%22.format(name, emoji,%0A                                                           
+emoji%7D   %7B
 content
-)
+%7D**%22
 %0A   

Update + fix class