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

Issue:
[V3]  Dev commands and discord.ext.commands

Right now, debug/eval (and repl, maybe?) expose `discord.ext.commands` as `commands` Given that we subclass various things in this for our use in `redbot.core.commands`, shouldn't we be exposing our version? In either case, the other is still importable, but it seems our default should be to use our version.


Discussion:

Resolving patch:
diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py
--- a/redbot/core/dev_commands.py
+++ b/redbot/core/dev_commands.py
@@ -84,7 +84,7 @@ async def debug(self, ctx, *, code):
             author   - command author's member object
             message  - the command's message object
             discord  - discord.py library
-            commands - discord.py commands extension
+            commands - redbot.core.commands
             _        - The result of the last dev command.
         """
         env = {
@@ -138,7 +138,7 @@ async def _eval(self, ctx, *, body: str):
             author   - command author's member object
             message  - the command's message object
             discord  - discord.py library
-            commands - discord.py commands extension
+            commands - redbot.core.commands
             _        - The result of the last dev command.
         """
         env = {


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

Issue:
[V3 ModLog] Error in command "case"
# Command bugs


#### Command name

[p]case

#### What cog is this command from?

ModLog

#### What were you expecting to happen?

To show me information about a case.


#### What actually happened?
I get this error:
![image](https://user-images.githubusercontent.com/30272172/43678766-a4a40388-97d6-11e8-90c7-d48ae2c54239.png)



#### How can we reproduce this issue?

1. Have a modlog with cases.
2. Do [p]case



Discussion:
Hi, thanks for submitting this issue! Looks like a simple fix.

Resolving patch:
diff --git a/redbot/cogs/modlog/modlog.py b/redbot/cogs/modlog/modlog.py
--- a/redbot/cogs/modlog/modlog.py
+++ b/redbot/cogs/modlog/modlog.py
@@ -95,7 +95,10 @@ async def case(self, ctx: commands.Context, number: int):
             await ctx.send(_("That case does not exist for that server"))
             return
         else:
-            await ctx.send(embed=await case.get_case_msg_content())
+            if await ctx.embed_requested():
+                await ctx.send(embed=await case.message_content(embed=True))
+            else:
+                await ctx.send(await case.message_content(embed=False))
 
     @commands.command(usage="[case] <reason>")
     @commands.guild_only()


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

Issue:
[CI] Travis builds broken due to link checking
Oracle/Java has blocked the Travis server from connecting to their site. This is resulting in every build failing whereby Travis is blocked from accessing the Java site.

**Temporary solution:**
I've disabled the enforcement of rules on Maintainers. **Handle with care.**

**Second temporary solution:**
Link checking is currently disabled (And the flag has been re-added to the command), this will ensure that builds will be able to run without interference.

**Proposed solution:**
Allow the build matrix to ignore the status of the Docs builds.
https://docs.travis-ci.com/user/customizing-the-build#Rows-that-are-Allowed-to-Fail


Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -190,6 +190,13 @@
 ]
 
 
+# -- Options for linkcheck builder ----------------------------------------
+
+# A list of regular expressions that match URIs that should not be
+# checked when doing a linkcheck build.
+linkcheck_ignore = [r"https://java.com*"]
+
+
 # Example configuration for intersphinx: refer to the Python standard library.
 intersphinx_mapping = {
     "python": ("https://docs.python.org/3.6", None),


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

Issue:
[V3] Addrole command errors on hierarchy issue
Cleaner output for hierarchy issue with [p] addrole instead of giving error.
![image](https://user-images.githubusercontent.com/10146271/43022519-788fd718-8c5f-11e8-8979-95143db2c567.png)



Discussion:
Hi, thanks for opening this issue! This should be a very simple fix. Self-assigning it now.

Resolving patch:
diff --git a/redbot/cogs/admin/admin.py b/redbot/cogs/admin/admin.py
--- a/redbot/cogs/admin/admin.py
+++ b/redbot/cogs/admin/admin.py
@@ -136,7 +136,7 @@ async def addrole(
             # noinspection PyTypeChecker
             await self._addrole(ctx, user, rolename)
         else:
-            await self.complain(ctx, USER_HIERARCHY_ISSUE, member=ctx.author)
+            await self.complain(ctx, USER_HIERARCHY_ISSUE, member=ctx.author, role=rolename)
 
     @commands.command()
     @commands.guild_only()


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

Issue:
[V3/Streams] streamalert list command is missing a doc string.
#### What were you trying to do?
call `[p]help` on streamalert list`

#### What were you expecting to happen?
Help message from the doc string would be displayed.

#### What actually happened?

No help message information was displayed, because the doc string was missing.

#### How can we reproduce this issue?
Call help on `[p]streamalert list` or see the missing short doc on `[p]help streamalert`



Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -209,6 +209,7 @@ async def streamalert_stop(self, ctx: commands.Context, _all: bool = False):
 
     @streamalert.command(name="list")
     async def streamalert_list(self, ctx: commands.Context):
+        """List all active stream alerts in this server."""
         streams_list = defaultdict(list)
         guild_channels_ids = [c.id for c in ctx.guild.channels]
         msg = _("Active alerts:\n\n")


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

Issue:
[V3 Reports] Error when report interact is used in DM
# Command bugs

#### Command name

[p]report interact <case_no>

#### What cog is this command from?

Reports

#### What were you expecting to happen?

For this command to not be usable in DMs

#### What actually happened?

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/redbot/cogs/reports/reports.py", line 322, in response
    rec = await self.config.custom("REPORT", guild.id, ticket_number).report()
AttributeError: 'NoneType' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/commands/commands.py", line 159, in invoke
    await super().invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 927, in invoke
    yield from ctx.invoked_subcommand.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 514, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 71, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'
```

#### How can we reproduce this issue?

Use [p]report interact in a DM.



Discussion:

Resolving patch:
diff --git a/redbot/cogs/reports/reports.py b/redbot/cogs/reports/reports.py
--- a/redbot/cogs/reports/reports.py
+++ b/redbot/cogs/reports/reports.py
@@ -317,6 +317,7 @@ async def on_message(self, message: discord.Message):
             if msgs:
                 self.tunnel_store[k]["msgs"] = msgs
 
+    @commands.guild_only()
     @checks.mod_or_permissions(manage_members=True)
     @report.command(name="interact")
     async def response(self, ctx, ticket_number: int):
@@ -329,7 +330,6 @@ async def response(self, ctx, ticket_number: int):
         Tunnels do not persist across bot restarts.
         """
 
-        # note, mod_or_permissions is an implicit guild_only
         guild = ctx.guild
         rec = await self.config.custom("REPORT", guild.id, ticket_number).report()
 


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

Issue:
[V3 Streams] Misleading error message
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

`[p]streamalert twitch channel #name_of_a_discord_channel`

#### What cog is this command from?

Streams

#### What were you expecting to happen?

The bot telling me that I screwed up

#### What actually happened?

The bot told me that my Twitch token is invalid

#### How can we reproduce this issue?

1) Set a valid Twitch client ID
2) Issue `[p]streamalert twitch channel #name_of_a_discord_channel`


Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -141,14 +141,20 @@ async def check_online(self, ctx: commands.Context, stream):
     async def streamalert(self, ctx: commands.Context):
         pass
 
-    @streamalert.group(name="twitch")
-    async def _twitch(self, ctx: commands.Context):
+    @streamalert.group(name="twitch", invoke_without_command=True)
+    async def _twitch(self, ctx: commands.Context, channel_name: str = None):
         """Twitch stream alerts"""
-        pass
+        if channel_name is not None:
+            await ctx.invoke(self.twitch_alert_channel, channel_name)
+        else:
+            await ctx.send_help()
 
     @_twitch.command(name="channel")
     async def twitch_alert_channel(self, ctx: commands.Context, channel_name: str):
         """Sets a Twitch alert notification in the channel"""
+        if re.fullmatch(r"<#\d+>", channel_name):
+            await ctx.send("Please supply the name of a *Twitch* channel, not a Discord channel.")
+            return
         await self.stream_alert(ctx, TwitchStream, channel_name.lower())
 
     @_twitch.command(name="community")


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

Issue:
[Streams] Config being saved once for every poll
As you can see here, streams is saving to config every 60 seconds, even when there is not change in status of any streamalerts:
![image](https://user-images.githubusercontent.com/7438501/44614935-df8b0180-a871-11e8-96be-3c78883047fe.png)

The write should only be occurring when something has actually changed.


Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -508,6 +508,8 @@ async def check_streams(self):
             try:
                 embed = await stream.is_online()
             except OfflineStream:
+                if not stream._messages_cache:
+                    continue
                 for message in stream._messages_cache:
                     try:
                         autodelete = await self.db.guild(message.guild).autodelete()
@@ -558,6 +560,8 @@ async def check_communities(self):
                 print(_("The Community {} was not found!").format(community.name))
                 continue
             except OfflineCommunity:
+                if not community._messages_cache:
+                    continue
                 for message in community._messages_cache:
                     try:
                         autodelete = await self.db.guild(message.guild).autodelete()


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

Issue:
[CustomCom] Old custom commands causing issues with new changes
Calling an old custom command created prior to #2051 results in the following traceback:
```py
[09/09/2018 14:13] ERROR events on_error 182: Exception in message
Traceback (most recent call last):
  File "/home/tobyh/Red-DiscordBot/.venv/lib/python3.7/site-packages/discord/client.py", line 221, in _run_event
    await coro(*args, **kwargs)
  File "/home/tobyh/Red-DiscordBot/.venv/lib/python3.7/site-packages/redbot/cogs/customcom/customcom.py", line 325, in on_message
    await self.call_cc_command(ctx, raw_response, message)
  File "/home/tobyh/Red-DiscordBot/.venv/lib/python3.7/site-packages/redbot/cogs/customcom/customcom.py", line 334, in call_cc_command
    await self.cc_command(*ctx.args, **ctx.kwargs, raw_response=raw_response)
  File "/home/tobyh/Red-DiscordBot/.venv/lib/python3.7/site-packages/redbot/cogs/customcom/customcom.py", line 352, in cc_command
    low = min(int(result[1]) for result in results)
ValueError: min() arg is an empty sequence
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/customcom/customcom.py b/redbot/cogs/customcom/customcom.py
--- a/redbot/cogs/customcom/customcom.py
+++ b/redbot/cogs/customcom/customcom.py
@@ -349,11 +349,12 @@ async def cc_command(self, ctx, *cc_args, raw_response, **cc_kwargs) -> None:
             param = self.transform_parameter(result, ctx.message)
             raw_response = raw_response.replace("{" + result + "}", param)
         results = re.findall(r"\{((\d+)[^\.}]*(\.[^:}]+)?[^}]*)\}", raw_response)
-        low = min(int(result[1]) for result in results)
-        for result in results:
-            index = int(result[1]) - low
-            arg = self.transform_arg(result[0], result[2], cc_args[index])
-            raw_response = raw_response.replace("{" + result[0] + "}", arg)
+        if results:
+            low = min(int(result[1]) for result in results)
+            for result in results:
+                index = int(result[1]) - low
+                arg = self.transform_arg(result[0], result[2], cc_args[index])
+                raw_response = raw_response.replace("{" + result[0] + "}", arg)
         await ctx.send(raw_response)
 
     def prepare_args(self, raw_response) -> Mapping[str, Parameter]:


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

Issue:
[V3] local blacklist ignores roles
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

localblacklist

#### What cog is this command from?

core

#### What were you expecting to happen?

Adding a role to the local blacklist would/should disallow the person to use commands.

#### What actually happened?

The user with the blacklisted role could sue the command without issues.

#### How can we reproduce this issue?

1. Blacklist a role
2. Assign the role to someone and let them use any command

#### Code

Support for blacklisting roles was added here:
https://github.com/Cog-Creators/Red-DiscordBot/blob/2784730f7f0d2eff5d59bb9947663210c281c769/redbot/core/core_commands.py#L1492-L1498

But it looks like it was missed during the actual check:
https://github.com/Cog-Creators/Red-DiscordBot/blob/2784730f7f0d2eff5d59bb9947663210c281c769/redbot/core/global_checks.py#L29-L34



Discussion:

Resolving patch:
diff --git a/redbot/core/global_checks.py b/redbot/core/global_checks.py
--- a/redbot/core/global_checks.py
+++ b/redbot/core/global_checks.py
@@ -26,7 +26,7 @@ async def local_perms(ctx: commands.Context):
         local_blacklist = await guild_settings.blacklist()
         local_whitelist = await guild_settings.whitelist()
 
-        _ids = [r.id for r in ctx.author.roles if not r.is_default]
+        _ids = [r.id for r in ctx.author.roles if not r.is_default()]
         _ids.append(ctx.author.id)
         if local_whitelist:
             return any(i in local_whitelist for i in _ids)


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

Issue:
[Cleanup] No member converter on "Cleanup user"
# Command bugs
#### Command name
``cleanup user <user> <amount>``

#### What cog is this command from?
Cleanup

#### What were you expecting to happen?
Cleaning up the amount of user.

#### What actually happened?
See Traceback:
```
[11/10/2018 11:04] ERROR events on_command_error 208: Exception in command 'cleanup user'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 61, in wrapped
    ret = await coro(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/redbot/cogs/cleanup/cleanup.py", line 172, in user
    member = await commands.converter.MemberConverter().convert(ctx, user)
AttributeError: module 'redbot.core.commands.converter' has no attribute 'MemberConverter'
[11/10/2018 11:04] ERROR events on_command_error 213: Exception in command 'cleanup user'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 61, in wrapped
    ret = await coro(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/redbot/cogs/cleanup/cleanup.py", line 172, in user
    member = await commands.converter.MemberConverter().convert(ctx, user)
AttributeError: module 'redbot.core.commands.converter' has no attribute 'MemberConverter'
```
#### How can we reproduce this issue?
``cleanup user <user> <amount>``


Discussion:

Resolving patch:
diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py
--- a/redbot/cogs/cleanup/cleanup.py
+++ b/redbot/cogs/cleanup/cleanup.py
@@ -169,7 +169,7 @@ async def user(
 
         member = None
         try:
-            member = await commands.converter.MemberConverter().convert(ctx, user)
+            member = await commands.MemberConverter().convert(ctx, user)
         except commands.BadArgument:
             try:
                 _id = int(user)


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

Issue:
[Streams] discord.NotFound error on load
This was reported as an error received by a user when trying to load streams:
```py
Exception during loading of cog
Traceback (most recent call last):
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/core_commands.py", line 100, in _load
    await bot.load_extension(spec)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/bot.py", line 228, in load_extension
    await lib.setup(self)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/__init__.py", line 6, in setup
    await cog.initialize()
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 74, in initialize
    self.streams = await self.load_streams()
  File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 629, in load_streams
    msg = await chn.get_message(raw_msg["message"])
  File "/home/jjay/rewrite/lib/python3.6/site-packages/discord/abc.py", line 844, in get_message
    data = await self._state.http.get_message(channel.id, id)
  File "/home/jjay/rewrite/lib/python3.6/site-packages/discord/http.py", line 211, in request
    raise NotFound(r, data)
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -626,8 +626,13 @@ async def load_streams(self):
             raw_stream["_messages_cache"] = []
             for raw_msg in raw_msg_cache:
                 chn = self.bot.get_channel(raw_msg["channel"])
-                msg = await chn.get_message(raw_msg["message"])
-                raw_stream["_messages_cache"].append(msg)
+                if chn is not None:
+                    try:
+                        msg = await chn.get_message(raw_msg["message"])
+                    except discord.HTTPException:
+                        pass
+                    else:
+                        raw_stream["_messages_cache"].append(msg)
             token = await self.db.tokens.get_raw(_class.__name__, default=None)
             if token is not None:
                 raw_stream["token"] = token
@@ -646,8 +651,13 @@ async def load_communities(self):
             raw_community["_messages_cache"] = []
             for raw_msg in raw_msg_cache:
                 chn = self.bot.get_channel(raw_msg["channel"])
-                msg = await chn.get_message(raw_msg["message"])
-                raw_community["_messages_cache"].append(msg)
+                if chn is not None:
+                    try:
+                        msg = await chn.get_message(raw_msg["message"])
+                    except discord.HTTPException:
+                        pass
+                    else:
+                        raw_community["_messages_cache"].append(msg)
             token = await self.db.tokens.get_raw(_class.__name__, default=None)
             communities.append(_class(token=token, **raw_community))
 


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

Issue:
[Downloader/Converter] _ is not Defined
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

cog uninstall

#### What cog is this command from?

Downloader & Converters.py

#### What were you expecting to happen?

Normal error saying "cog is not installed

#### What actually happened?

error saying _ is not defined

#### How can we reproduce this issue?

[p]cog uninstall OwO



Discussion:

Resolving patch:
diff --git a/redbot/cogs/downloader/converters.py b/redbot/cogs/downloader/converters.py
--- a/redbot/cogs/downloader/converters.py
+++ b/redbot/cogs/downloader/converters.py
@@ -1,7 +1,10 @@
 import discord
 from redbot.core import commands
+from redbot.core.i18n import Translator
 from .installable import Installable
 
+_ = Translator("Koala", __file__)
+
 
 class InstalledCog(Installable):
     @classmethod


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

Issue:
[Downloader] Cogs don't get unloaded after uninstalling.
# Other bugs


#### What were you trying to do?

When uninstalling a cog from downloader the cog does not get unloaded.

#### What were you expecting to happen?

The cog being deleted **&** unloaded.

#### What actually happened?

The cog only got deleted, The cog stayed active and in memory.

#### How can we reproduce this issue?

``cog uninstall <3rd party cog>``
Check that the cog is still loaded in memory
``cogs``



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
@@ -325,13 +325,12 @@ async def _cog_uninstall(self, ctx, cog: InstalledCog):
         You may only uninstall cogs which were previously installed
         by Downloader.
         """
-        # noinspection PyUnresolvedReferences,PyProtectedMember
         real_name = cog.name
 
         poss_installed_path = (await self.cog_install_path()) / real_name
         if poss_installed_path.exists():
+            ctx.bot.unload_extension(real_name)
             await self._delete_cog(poss_installed_path)
-            # noinspection PyTypeChecker
             await self._remove_from_installed(cog)
             await ctx.send(
                 _("Cog `{cog_name}` was successfully uninstalled.").format(cog_name=real_name)


Test patch: