internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Cog-Creators/Red-DiscordBot

Issue:
Filtering issue
#### What were you trying to do?

Someone changed his name to Night and it filtered the name because the word Nig is on the filter list. so basically it shouldn't filter the persons name because it was Night and not Nig.

Now this issue is solved in the filtering system when it comes to proper chat in a channel, where someone can say for example assistance but not ass when ass is on the filter list. but assistance consisting the word ass is possible. (like i stated that works correctly)

however if you do the same for nicknames (!filter names) it will filter the name if a word consists of the word that is in the filter list. so Nig is filtered and night is not. however changing the name to Night will filter that name because Nig is in Night.

Hope that made sense.

#### What were you expecting to happen?

For nickname Night not be filtered because that actual word is not on the filter list.

#### What actually happened?

The word night got filtered because the word Nig which is part of Night is on the filter list.

#### How can we reproduce this issue?

1. !filter add Nig
2. !filter names (to enable the filtering names option)
3. Try to change your name to Night
4. See how the bot changes your name because nig is on the list and part of the word night.



Discussion:
any idea how to fix this? as its a rather big issue on the company discord.
I'd suggest turning off name filtering until it's fixed. It will be fixed when someone has the time to fix it.

Resolving patch:
diff --git a/redbot/cogs/filter/filter.py b/redbot/cogs/filter/filter.py
--- a/redbot/cogs/filter/filter.py
+++ b/redbot/cogs/filter/filter.py
@@ -448,13 +448,12 @@ async def maybe_filter_name(self, member: discord.Member):
         if not await self.settings.guild(member.guild).filter_names():
             return
 
-        word_list = await self.settings.guild(member.guild).filter()
-        for w in word_list:
-            if w in member.display_name.lower():
-                name_to_use = await self.settings.guild(member.guild).filter_default_name()
-                reason = _("Filtered nickname") if member.nick else _("Filtered name")
-                try:
-                    await member.edit(nick=name_to_use, reason=reason)
-                except discord.HTTPException:
-                    pass
-                return
+        if await self.filter_hits(member.display_name, member.guild):
+
+            name_to_use = await self.settings.guild(member.guild).filter_default_name()
+            reason = _("Filtered nickname") if member.nick else _("Filtered name")
+            try:
+                await member.edit(nick=name_to_use, reason=reason)
+            except discord.HTTPException:
+                pass
+            return


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Audio] Unhandled error for nonexistent folders in `[p]search` command
# Command bugs

#### Command name

`[p]search folder:<nonexistent folder>`

#### What cog is this command from?

Audio

#### What were you expecting to happen?

Cog to handle the error gracefully (with meaningful error message)

#### What actually happened?

Bot sent: `Error in command 'search'. Check your console or logs for details.`
Here's traceback:
```
Exception in command 'search'
Traceback (most recent call last):
  File "/home/ubuntu/red-venv/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/ubuntu/red-venv/lib/python3.7/site-packages/redbot/cogs/audio/audio.py", line 2956, in search
    tracks = await self._folder_tracks(ctx, player, query)
  File "/home/ubuntu/red-venv/lib/python3.7/site-packages/redbot/cogs/audio/audio.py", line 1241, in _folder_tracks
    for local_file in await self._all_folder_tracks(ctx, folder):
  File "/home/ubuntu/red-venv/lib/python3.7/site-packages/redbot/cogs/audio/audio.py", line 1192, in _all_folder_tracks
    for f in os.listdir(current_folder)
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/red-data/cogs/Audio/localtracks/Spotfy/'
```

#### How can we reproduce this issue?

Use this command (replace `<nonexistent folder>` with some folder that doesn't exist in `localtracks` folder)
`[p]search folder:<nonexistent folder>`



Discussion:
I forgot to say, this also happen when using `[p]search localfolder:<nonexistent folder>`

Resolving patch:
diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py
--- a/redbot/cogs/audio/audio.py
+++ b/redbot/cogs/audio/audio.py
@@ -1211,6 +1211,8 @@ async def _build_local_search_list(to_search, search_words):
     async def _folder_list(self, ctx, folder):
         if not await self._localtracks_check(ctx):
             return
+        if not os.path.isdir(os.getcwd() + "/localtracks/{}/".format(folder)):
+            return
         allowed_files = (".mp3", ".flac", ".ogg")
         folder_list = sorted(
             (
@@ -1237,6 +1239,8 @@ async def _folder_list(self, ctx, folder):
     async def _folder_tracks(self, ctx, player, folder):
         if not await self._localtracks_check(ctx):
             return
+        if not os.path.isdir(os.getcwd() + "/localtracks/{}/".format(folder)):
+            return
         local_tracks = []
         for local_file in await self._all_folder_tracks(ctx, folder):
             track = await player.get_tracks("localtracks/{}/{}".format(folder, local_file))


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Modlog] Reason traceback.
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

``reason <a case that doesn't exist> <reason>``

#### What cog is this command from?

``modlog``

#### What were you expecting to happen?

A propper invalid modlog case edit

#### What actually happened?

``reason`` errors out on mongodb installs.

```
Traceback (most recent call last):
  File "/red-v3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/red-v3/lib/python3.7/site-packages/redbot/cogs/modlog/modlog.py", line 189, in reason
    await case_before.edit(to_modify)
  File "/red-v3/lib/python3.7/site-packages/redbot/core/modlog.py", line 145, in edit
    await _conf.custom(_CASES, str(self.guild.id), str(self.case_number)).set(self.to_json())
AttributeError: 'NoneType' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/red-v3/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
    await ctx.command.invoke(ctx)
  File "/red-v3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/red-v3/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'
```


Discussion:
Unrelated to mongo, the command errors out on JSON backend as well.

Resolving patch:
diff --git a/redbot/core/modlog.py b/redbot/core/modlog.py
--- a/redbot/core/modlog.py
+++ b/redbot/core/modlog.py
@@ -514,10 +514,10 @@ async def get_case(case_number: int, guild: discord.Guild, bot: Red) -> Case:
         If there is no case for the specified number
 
     """
-    try:
-        case = await _conf.custom(_CASES, str(guild.id), str(case_number)).all()
-    except KeyError as e:
-        raise RuntimeError("That case does not exist for guild {}".format(guild.name)) from e
+
+    case = await _conf.custom(_CASES, str(guild.id), str(case_number)).all()
+    if not case["case_number"]:
+        raise RuntimeError("That case does not exist for guild {}".format(guild.name))
     mod_channel = await get_modlog_channel(guild)
     return await Case.from_json(mod_channel, bot, case_number, case)
 


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
Removing commands on bot load
# Other bugs

Loading a cog with bot.remove_command statements in init causes it to error out and not load.



#### What were you trying to do?

I have a cog that has statements in __init__ like this
```py
        bot.remove_command("invite")
        bot.remove_command("ping")
        bot.remove_command("pong")
        bot.remove_command("uptime")
```

#### What were you expecting to happen?

The commands to be unloaded and my command loaded.

#### What actually happened?

The cog does not load. 

```py
Traceback (most recent call last):
File "/data/venv/lib/python3.7/site-packages/redbot/core/events.py", line 71, in on_ready
await bot.load_extension(spec)
File "/data/venv/lib/python3.7/site-packages/redbot/core/bot.py", line 304, in load_extension
lib.setup(self)
File "/data/cogs/CogManager/cogs/general/__init__.py", line 5, in setup
bot.add_cog(General(bot))
File "/data/cogs/CogManager/cogs/general/general.py", line 39, in __init__
bot.remove_command("pong")
File "/data/venv/lib/python3.7/site-packages/redbot/core/bot.py", line 466, in remove_command
command.requires.reset()
AttributeError: 'NoneType' object has no attribute 'requires'
``` 
#### How can we reproduce this issue?

Make a simple cog with this in init
`bot.remove_command("ping")`



Discussion:

Resolving patch:
diff --git a/redbot/core/bot.py b/redbot/core/bot.py
--- a/redbot/core/bot.py
+++ b/redbot/core/bot.py
@@ -461,6 +461,8 @@ def add_command(self, command: commands.Command) -> None:
 
     def remove_command(self, name: str) -> None:
         command = super().remove_command(name)
+        if not command:
+            return
         command.requires.reset()
         if isinstance(command, commands.Group):
             for subcommand in set(command.walk_commands()):


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Core] Make `[p]command disable` remove it from help
# Feature request

#### Select the type of feature you are requesting:

- [ ] Cog
- [x] Command
- [ ] API functionality

#### Describe your requested feature
As in title, make `[p]command disable` remove the command from help. Maybe as a `[p]helpset` setting.

Currently workaround for this is denying it in permissions cog as well:
```
[p]permissions setdefaultglobalrule deny <cog_or_command>
```



Discussion:

Resolving patch:
diff --git a/redbot/core/commands/commands.py b/redbot/core/commands/commands.py
--- a/redbot/core/commands/commands.py
+++ b/redbot/core/commands/commands.py
@@ -328,7 +328,7 @@ async def can_see(self, ctx: "Context"):
                 can_run = await self.can_run(
                     ctx, check_all_parents=True, change_permission_state=False
                 )
-            except commands.CheckFailure:
+            except (commands.CheckFailure, commands.errors.DisabledCommand):
                 return False
             else:
                 if can_run is False:
diff --git a/redbot/core/commands/help.py b/redbot/core/commands/help.py
--- a/redbot/core/commands/help.py
+++ b/redbot/core/commands/help.py
@@ -1,7 +1,6 @@
 # This is a full replacement of discord.py's help command
-# Signatures are not guaranteed to be unchanging in this file.
-# At a later date when this is more set in stone, this warning will be removed.
-# At said later date, there should also be things added to support extra formatter
+#
+# At a later date, there should be things added to support extra formatter
 # registration from 3rd party cogs.
 #
 # This exists due to deficiencies in discord.py which conflict
@@ -441,14 +440,14 @@ async def help_filter_func(
         for obj in objects:
             if verify_checks and not show_hidden:
                 # Default Red behavior, can_see includes a can_run check.
-                if await obj.can_see(ctx):
+                if await obj.can_see(ctx) and getattr(obj, "enabled", True):
                     yield obj
             elif verify_checks:
                 try:
                     can_run = await obj.can_run(ctx)
                 except discord.DiscordException:
                     can_run = False
-                if can_run:
+                if can_run and getattr(obj, "enabled", True):
                     yield obj
             elif not show_hidden:
                 if not getattr(obj, "hidden", False):  # Cog compatibility


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Mod] Bot doesn't record name changes correctly
# Other bugs

#### What were you trying to do?

Check past names using `[p]names` command

#### What were you expecting to happen?

Get past names

#### What actually happened?

I didn't get any names, because we're checking for it in wrong event (`on_member_update` instead of `on_user_update`).

#### How can we reproduce this issue?

1. Load mod cog
2. Change username
3. Use `[p]names` on yourself.



Discussion:

Resolving patch:
diff --git a/redbot/cogs/mod/events.py b/redbot/cogs/mod/events.py
--- a/redbot/cogs/mod/events.py
+++ b/redbot/cogs/mod/events.py
@@ -95,7 +95,7 @@ async def on_message(self, message):
             await self.check_mention_spam(message)
 
     @commands.Cog.listener()
-    async def on_member_update(self, before: discord.Member, after: discord.Member):
+    async def on_user_update(self, before: discord.User, after: discord.User):
         if before.name != after.name:
             async with self.settings.user(before).past_names() as name_list:
                 while None in name_list:  # clean out null entries from a bug
@@ -107,6 +107,8 @@ async def on_member_update(self, before: discord.Member, after: discord.Member):
                 while len(name_list) > 20:
                     name_list.pop(0)
 
+    @commands.Cog.listener()
+    async def on_member_update(self, before: discord.Member, after: discord.Member):
         if before.nick != after.nick and after.nick is not None:
             async with self.settings.member(before).past_nicks() as nick_list:
                 while None in nick_list:  # clean out null entries from a bug


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
Modset deletedelay behavior, 3.1.5
# Other bugs
This bug happens with the modset's deletedelay feature enabled, I have submitted about this on a previous version which was 3.0.2 on python 3.6.8 @ [#2705](https://github.com/Cog-Creators/Red-DiscordBot/issues/2705) 

#### What were you trying to do?

Just normally chat with friends in a public server, though some users happen t use the prefix [p] in front of their messages and it just deletes.

#### What were you expecting to happen?

Ignored message as it's not a command

#### What actually happened?

The bot seems to registers any messages with the prefix as a command, so it just deletes any messagess as `[p]whateverMessage is this`

#### How can we reproduce this issue?

Red's Version: 3.1.5
Python Version: 3.7.3

1. enable `[p]modset delaydelete X`
2. type whatever message with the prefix in the front `[p]whateverhere`
3. auto deleted?

Example screenshots:
https://i.shikashi.me/BYX0o
https://i.shikashi.me/ewyny

Note: I have tried this with cogs unloaded and loaded. (Looks like a core behavior)



Discussion:
I can reproduce this behaviour. Red 3.1.5, Python 3.7.4 and d.py 1.2.3.

Video: https://vexed.uk.to/294f4

Resolving patch:
diff --git a/redbot/cogs/mod/movetocore.py b/redbot/cogs/mod/movetocore.py
--- a/redbot/cogs/mod/movetocore.py
+++ b/redbot/cogs/mod/movetocore.py
@@ -21,10 +21,12 @@ class MoveToCore(MixinMeta):
     async def on_command_completion(self, ctx: commands.Context):
         await self._delete_delay(ctx)
 
-    # noinspection PyUnusedLocal
     @commands.Cog.listener()
-    async def on_command_error(self, ctx: commands.Context, error):
-        await self._delete_delay(ctx)
+    async def on_command_error(self, ctx: commands.Context, error: Exception):
+        # Every message which isn't a command but which
+        # starts with a bot prefix is dispatched as a command error
+        if not isinstance(error, commands.CommandNotFound):
+            await self._delete_delay(ctx)
 
     async def _delete_delay(self, ctx: commands.Context):
         """Currently used for:


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Utils] Creating backup on Windows results in 0 bytes file.
# Other bugs

#### What were you trying to do?

Create backup on Windows.

#### What were you expecting to happen?

Get backup file for my bot in the location it told me.

#### What actually happened?

I got 0 bytes file with non-full name (issue is `:` in filename that is not allowed on Windows)

#### How can we reproduce this issue?

Create backup on Windows 😄

---

I have PR almost ready, this is just informational.




Discussion:

Resolving patch:
diff --git a/redbot/core/utils/__init__.py b/redbot/core/utils/__init__.py
--- a/redbot/core/utils/__init__.py
+++ b/redbot/core/utils/__init__.py
@@ -410,7 +410,7 @@ async def create_backup(dest: Path = Path.home()) -> Optional[Path]:
         return
 
     dest.mkdir(parents=True, exist_ok=True)
-    timestr = datetime.utcnow().isoformat(timespec="minutes")
+    timestr = datetime.utcnow().strftime("%Y-%m-%dT%H-%M-%S")
     backup_fpath = dest / f"redv3_{data_manager.instance_name}_{timestr}.tar.gz"
 
     to_backup = []


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Core] Starting Red with non-existent instance name doesn't give friendly error.
# Other bugs

#### What were you trying to do?

Use non-existent instance name when starting Red.

#### What were you expecting to happen?

Get the regular "You need to configure the bot instance using `redbot-setup` prior to running the bot." message.

#### What actually happened?

I got traceback about `KeyError`.

<details>
<summary>Details</summary>

```
Traceback (most recent call last):
  File ".venv\Scripts\redbot-script.py", line 11, in <module>
    load_entry_point('Red-DiscordBot', 'console_scripts', 'redbot')()
  File "redbot\__main__.py", line 104, in main
    data_manager.load_basic_configuration(cli_flags.instance_name)
  File "redbot\core\data_manager.py", line 101, in load_basic_configuration
    basic_config = config[instance_name]
KeyError: 'blahhdhf'
```
</details>

#### How can we reproduce this issue?

Try running `redbot` command with non-existent instance name

---

This is an easy fix, so I'll make a PR soon.




Discussion:

Resolving patch:
diff --git a/redbot/core/data_manager.py b/redbot/core/data_manager.py
--- a/redbot/core/data_manager.py
+++ b/redbot/core/data_manager.py
@@ -91,14 +91,20 @@ def load_basic_configuration(instance_name_: str):
     try:
         with config_file.open(encoding="utf-8") as fs:
             config = json.load(fs)
-    except (FileNotFoundError, KeyError):
+    except FileNotFoundError:
         print(
             "You need to configure the bot instance using `redbot-setup`"
             " prior to running the bot."
         )
         sys.exit(1)
-    else:
+    try:
         basic_config = config[instance_name]
+    except KeyError:
+        print(
+            "Instance with this name doesn't exist."
+            " You can create new instance using `redbot-setup` prior to running the bot."
+        )
+        sys.exit(1)
 
 
 def _base_data_path() -> Path:


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Downloader] AttributeError with [p]findcog help
#### Command name

`[p]findcog`

#### What cog is this command from?

Downloader

#### What were you expecting to happen?

The bot is supposed to send which cog this command comes from, or if it isn't from a cog like for this command send something else.

#### What actually happened?

I got this error:
```py
Exception in command 'findcog'
Traceback (most recent call last):
  File "/home/test/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/test/.local/lib/python3.7/site-packages/redbot/cogs/downloader/downloader.py", line 593, in findcog
    cog_name = self.cog_name_from_instance(command.cog)
  File "/home/test/.local/lib/python3.7/site-packages/redbot/cogs/downloader/downloader.py", line 577, in cog_name_from_instance
    splitted = instance.__module__.split(".")
AttributeError: 'NoneType' object has no attribute '__module__'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/test/.local/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
    await ctx.command.invoke(ctx)
  File "/home/test/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/test/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute '__module__'
```

#### How can we reproduce this issue?

Use `[p]findcog help`



Discussion:

Resolving patch:
diff --git a/redbot/cogs/downloader/downloader.py b/redbot/cogs/downloader/downloader.py
--- a/redbot/cogs/downloader/downloader.py
+++ b/redbot/cogs/downloader/downloader.py
@@ -590,12 +590,16 @@ async def findcog(self, ctx: commands.Context, command_name: str):
             return
 
         # Check if in installed cogs
-        cog_name = self.cog_name_from_instance(command.cog)
-        installed, cog_installable = await self.is_installed(cog_name)
-        if installed:
-            msg = self.format_findcog_info(command_name, cog_installable)
+        cog = command.cog
+        if cog:
+            cog_name = self.cog_name_from_instance(cog)
+            installed, cog_installable = await self.is_installed(cog_name)
+            if installed:
+                msg = self.format_findcog_info(command_name, cog_installable)
+            else:
+                # Assume it's in a base cog
+                msg = self.format_findcog_info(command_name, cog)
         else:
-            # Assume it's in a base cog
-            msg = self.format_findcog_info(command_name, command.cog)
+            msg = _("This command is not provided by a cog.")
 
         await ctx.send(box(msg))


Test patch: