From c67b6cd443874af65aa21bd3ec7f65c422291e7c Mon Sep 17 00:00:00 2001 From: Draper <27962761+Drapersniper@users.noreply.github.com> Date: Tue, 10 Dec 2019 01:26:26 +0000 Subject: [PATCH 1/5] [Audio] Say no to busylooping :Awesome: (#3176) * Say no to busylooping :Awesome: Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * chrore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * black y u do dis 2 me Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Return regardless if error is raised here --- changelog.d/audio/3176.misc.1.rst | 1 + redbot/cogs/audio/apis.py | 8 ++++++-- redbot/cogs/audio/audio.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 changelog.d/audio/3176.misc.1.rst diff --git a/changelog.d/audio/3176.misc.1.rst b/changelog.d/audio/3176.misc.1.rst new file mode 100644 index 000000000..d79fa147d --- /dev/null +++ b/changelog.d/audio/3176.misc.1.rst @@ -0,0 +1 @@ +Added an early exist to the `while` loop in the autoplay method, this is to that if a service is blacklisted it doesn't infinitely loop causing heartbeats. \ No newline at end of file diff --git a/redbot/cogs/audio/apis.py b/redbot/cogs/audio/apis.py index fa254ffc2..dd77733c1 100644 --- a/redbot/cogs/audio/apis.py +++ b/redbot/cogs/audio/apis.py @@ -33,7 +33,7 @@ from redbot.core import Config, commands from redbot.core.bot import Red from redbot.core.i18n import Translator, cog_i18n from . import audio_dataclasses -from .errors import InvalidTableError, SpotifyFetchError, YouTubeApiError +from .errors import InvalidTableError, SpotifyFetchError, YouTubeApiError, DatabaseError from .playlists import get_playlist from .utils import CacheLevel, Notifier, is_allowed, queue_duration, track_limit @@ -1098,10 +1098,14 @@ class MusicCache: track = tracks[0] valid = not multiple - + tries = len(tracks) while valid is False and multiple: + tries -= 1 + if tries <= 0: + raise DatabaseError("No valid entry found") track = random.choice(tracks) query = audio_dataclasses.Query.process_input(track) + await asyncio.sleep(0.001) if not query.valid: continue if query.is_local and not query.track.exists(): diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py index 07cbeb91a..209a571bb 100644 --- a/redbot/cogs/audio/audio.py +++ b/redbot/cogs/audio/audio.py @@ -39,7 +39,13 @@ from .apis import MusicCache, HAS_SQL, _ERROR from .checks import can_have_caching from .converters import ComplexScopeParser, ScopeParser, get_lazy_converter, get_playlist_converter from .equalizer import Equalizer -from .errors import LavalinkDownloadFailed, MissingGuild, SpotifyFetchError, TooManyMatches +from .errors import ( + DatabaseError, + LavalinkDownloadFailed, + MissingGuild, + SpotifyFetchError, + TooManyMatches, +) from .manager import ServerManager from .playlists import ( FakePlaylist, @@ -448,7 +454,16 @@ class Audio(commands.Cog): ) if autoplay and not player.queue and player.fetch("playing_song") is not None: if self.owns_autoplay is None: - await self.music_cache.autoplay(player) + try: + await self.music_cache.autoplay(player) + except DatabaseError: + notify_channel = player.fetch("channel") + if notify_channel: + notify_channel = self.bot.get_channel(notify_channel) + await self._embed_msg( + notify_channel, _("Autoplay: Couldn't get a valid track.") + ) + return else: self.bot.dispatch( "red_audio_should_auto_play", @@ -2725,7 +2740,16 @@ class Audio(commands.Cog): if not await self._currency_check(ctx, guild_data["jukebox_price"]): return if self.owns_autoplay is None: - await self.music_cache.autoplay(player) + try: + await self.music_cache.autoplay(player) + except DatabaseError: + notify_channel = player.fetch("channel") + if notify_channel: + notify_channel = self.bot.get_channel(notify_channel) + await self._embed_msg( + notify_channel, _("Autoplay: Couldn't get a valid track.") + ) + return else: self.bot.dispatch( "red_audio_should_auto_play", From b6ae7a6d213c81307ada416886f0773da3306000 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 11 Dec 2019 21:49:57 +0100 Subject: [PATCH 2/5] [Core] Add `redbot --debuginfo` flag (#3183) * [Core] Add `redbot --debuginfo` flag * Update cli.py * Create 3183.enhance.rst * Update __main__.py * Update __main__.py --- changelog.d/3183.enhance.rst | 1 + redbot/__main__.py | 45 +++++++++++++++++++++++++++++++++++- redbot/core/cli.py | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 changelog.d/3183.enhance.rst diff --git a/changelog.d/3183.enhance.rst b/changelog.d/3183.enhance.rst new file mode 100644 index 000000000..03e8473d2 --- /dev/null +++ b/changelog.d/3183.enhance.rst @@ -0,0 +1 @@ +Add ``redbot --debuginfo`` flag that shows useful information for debugging. diff --git a/redbot/__main__.py b/redbot/__main__.py index e947758d0..dce36a305 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -3,9 +3,12 @@ # Discord Version check import asyncio +import getpass import json import logging import os +import pip +import platform import shutil import sys from copy import deepcopy @@ -16,7 +19,7 @@ import discord # Set the event loop policies here so any subsequent `get_event_loop()` # calls, in particular those as a result of the following imports, # return the correct loop object. -from redbot import _update_event_loop_policy +from redbot import _update_event_loop_policy, __version__ _update_event_loop_policy() @@ -73,6 +76,44 @@ def list_instances(): sys.exit(0) +def debug_info(): + """Shows debug information useful for debugging.""" + if sys.platform == "linux": + import distro # pylint: disable=import-error + + IS_WINDOWS = os.name == "nt" + IS_MAC = sys.platform == "darwin" + IS_LINUX = sys.platform == "linux" + + pyver = sys.version + pipver = pip.__version__ + redver = __version__ + dpy_version = discord.__version__ + if IS_WINDOWS: + os_info = platform.uname() + osver = "{} {} (version {})".format(os_info.system, os_info.release, os_info.version) + elif IS_MAC: + os_info = platform.mac_ver() + osver = "Mac OSX {} {}".format(os_info[0], os_info[2]) + else: + os_info = distro.linux_distribution() + osver = "{} {}".format(os_info[0], os_info[1]).strip() + user_who_ran = getpass.getuser() + info = ( + "Debug Info for Red\n\n" + + "Red version: {}\n".format(redver) + + "Python version: {}\n".format(pyver) + + "Python executable: {}\n".format(sys.executable) + + "Discord.py version: {}\n".format(dpy_version) + + "Pip version: {}\n".format(pipver) + + "OS version: {}\n".format(osver) + + "System arch: {}\n".format(platform.machine()) + + "User: {}\n".format(user_who_ran) + ) + print(info) + sys.exit(0) + + def edit_instance(red, cli_flags): no_prompt = cli_flags.no_prompt token = cli_flags.token @@ -231,6 +272,8 @@ def main(): print(description) print("Current Version: {}".format(__version__)) sys.exit(0) + elif cli_flags.debuginfo: + debug_info() elif not cli_flags.instance_name and (not cli_flags.no_instance or cli_flags.edit): print("Error: No instance name was provided!") sys.exit(1) diff --git a/redbot/core/cli.py b/redbot/core/cli.py index b8831f6a8..ead6dc905 100644 --- a/redbot/core/cli.py +++ b/redbot/core/cli.py @@ -73,6 +73,7 @@ def parse_cli_flags(args): description="Red - Discord Bot", usage="redbot [arguments]" ) parser.add_argument("--version", "-V", action="store_true", help="Show Red's current version") + parser.add_argument("--debuginfo", action="store_true", help="Show debug information.") parser.add_argument( "--list-instances", action="store_true", From 335ded674e72f5446efde7ee8806ef45b061eeba Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 11 Dec 2019 22:40:28 +0100 Subject: [PATCH 3/5] [Core] Add Python executable field to `[p]debuginfo` command (#3184) * Update core_commands.py * Create 3184.enhance.rst --- changelog.d/3184.enhance.rst | 1 + redbot/core/core_commands.py | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 changelog.d/3184.enhance.rst diff --git a/changelog.d/3184.enhance.rst b/changelog.d/3184.enhance.rst new file mode 100644 index 000000000..b3c488568 --- /dev/null +++ b/changelog.d/3184.enhance.rst @@ -0,0 +1 @@ +Add Python executable field to `[p]debuginfo` command. diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 763a9391a..970d9eb2d 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1592,12 +1592,14 @@ class Core(commands.Cog, CoreLogic): e.add_field(name="System arch", value=platform.machine(), inline=True) e.add_field(name="User", value=user_who_ran, inline=True) e.add_field(name="OS version", value=osver, inline=False) + e.add_field(name="Python executable", value=sys.executable, inline=False) await ctx.send(embed=e) else: info = ( "Debug Info for Red\n\n" + "Red version: {}\n".format(redver) + "Python version: {}\n".format(pyver) + + "Python executable: {}\n".format(sys.executable) + "Discord.py version: {}\n".format(dpy_version) + "Pip version: {}\n".format(pipver) + "System arch: {}\n".format(platform.machine()) From 988536f96bc66b315717dbf30802663aea9beb91 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 12 Dec 2019 00:28:52 +0100 Subject: [PATCH 4/5] [Downloader] Possible solution for "partial" unload of cog in `[p]cog uninstall` (#3180) * Update downloader.py * Create 3180.bugfix.rst * Rename 3180.bugfix.rst to 3179.bugfix.rst * Update redbot/cogs/downloader/downloader.py Co-Authored-By: Michael H --- changelog.d/downloader/3179.bugfix.rst | 1 + redbot/cogs/downloader/downloader.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog.d/downloader/3179.bugfix.rst diff --git a/changelog.d/downloader/3179.bugfix.rst b/changelog.d/downloader/3179.bugfix.rst new file mode 100644 index 000000000..6739d0dc1 --- /dev/null +++ b/changelog.d/downloader/3179.bugfix.rst @@ -0,0 +1 @@ +``[p]cog uninstall`` now fully unloads cog - bot will not try to load it on next startup. diff --git a/redbot/cogs/downloader/downloader.py b/redbot/cogs/downloader/downloader.py index 26262bcce..8b4978d79 100644 --- a/redbot/cogs/downloader/downloader.py +++ b/redbot/cogs/downloader/downloader.py @@ -647,6 +647,7 @@ class Downloader(commands.Cog): if poss_installed_path.exists(): with contextlib.suppress(commands.ExtensionNotLoaded): ctx.bot.unload_extension(real_name) + await ctx.bot.remove_loaded_package(real_name) await self._delete_cog(poss_installed_path) uninstalled_cogs.append(inline(real_name)) else: From e32eecd6e7ef0289d6cc23e175f25842e3e445c9 Mon Sep 17 00:00:00 2001 From: Michael H Date: Sat, 14 Dec 2019 21:00:08 -0500 Subject: [PATCH 5/5] [Docs] Update windows deps instructions (#3188) * update windows deps instructions * changelog * be more explicit that manual dependency handling is an excersice left to the reader * let's only grab the MSVC C++ stuff here... * Meh * update language * Update install_windows.rst * it's really that easy --- changelog.d/3188.docs.rst | 1 + docs/install_windows.rst | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 changelog.d/3188.docs.rst diff --git a/changelog.d/3188.docs.rst b/changelog.d/3188.docs.rst new file mode 100644 index 000000000..9a9606451 --- /dev/null +++ b/changelog.d/3188.docs.rst @@ -0,0 +1 @@ +update windows docs with up to date dependency instructions diff --git a/docs/install_windows.rst b/docs/install_windows.rst index 54bc87d6f..f5dfd66c5 100644 --- a/docs/install_windows.rst +++ b/docs/install_windows.rst @@ -27,15 +27,30 @@ Then run each of the following commands: Set-ExecutionPolicy Bypass -Scope Process -Force iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) choco install git --params "/GitOnlyOnPath /WindowsTerminal" -y - choco install jre8 python -y; exit + choco install visualstudio2019-workload-vctools -y + choco install python3 --version=3.7.5 -y -From here, continue onto `installing Red `. +For Audio support, you should also run the following command before exiting: + +.. code-block:: none + + choco install adoptopenjdk11jre -y + + +From here, exit the prompt then continue onto `installing Red `. ******************************** Manually installing dependencies ******************************** -* `Python `_ - Red needs Python 3.7.0 or greater +.. attention:: There are additional configuration steps required which are + not documented for installing dependencies manually. + These dependencies are only listed seperately here for + reference purposes. + +* `MSVC Build tools `_ + +* `Python `_ - Red needs Python 3.7.2 or greater .. attention:: Please make sure that the box to add Python to PATH is CHECKED, otherwise you may run into issues when trying to run Red. @@ -44,9 +59,8 @@ Manually installing dependencies .. attention:: Please choose the option to "Git from the command line and also from 3rd-party software" in Git's setup. -* `Java `_ - needed for Audio +* `Java `_ - needed for Audio -.. attention:: Please choose the "Windows Online" installer. .. _installing-red-windows: