From 6f103174aac58f1566fdb7ed2cd78d522b5dc491 Mon Sep 17 00:00:00 2001 From: Redjumpman Date: Fri, 20 Oct 2017 14:29:55 -0500 Subject: [PATCH] V3/start screen (#1038) * Added new start screen * Added Bordered util Bordered function required for boxes in start screen * Update events.py Added Color to the Title Added Shard count * Update events.py Added Discord.py version Added package checking for docs and tests Added package checking for voice * Update chat_formatting.py Cleaned up the border function a bit. --- redbot/core/events.py | 66 ++++++++++++++++++++++++---- redbot/core/utils/chat_formatting.py | 19 ++++++++ 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/redbot/core/events.py b/redbot/core/events.py index 4771e5ec3..1854fa24b 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -1,21 +1,30 @@ import datetime import logging import traceback +from pkg_resources import get_distribution +from importlib.util import find_spec as find_package + import discord from .sentry_setup import should_log from discord.ext import commands -from .utils.chat_formatting import inline +from .data_manager import storage_type +from .utils.chat_formatting import inline, bordered from .core_commands import find_spec +from colorama import Fore, Style log = logging.getLogger("red") sentry_log = logging.getLogger("red.sentry") -INTRO = ("{0}===================\n" - "{0} Red - Discord Bot \n" - "{0}===================\n" - "".format(" " * 20)) +INTRO = """ +______ _ ______ _ _ ______ _ +| ___ \ | | | _ (_) | | | ___ \ | | +| |_/ /___ __| | ______ | | | |_ ___ ___ ___ _ __ __| | | |_/ / ___ | |_ +| // _ \/ _` | |______| | | | | / __|/ __/ _ \| '__/ _` | | ___ \/ _ \| __| +| |\ \ __/ (_| | | |/ /| \__ \ (_| (_) | | | (_| | | |_/ / (_) | |_ +\_| \_\___|\__,_| |___/ |_|___/\___\___/|_| \__,_| \____/ \___/ \__| +""" def init_events(bot, cli_flags): @@ -32,8 +41,6 @@ def init_events(bot, cli_flags): bot.uptime = datetime.datetime.utcnow() - print(INTRO) - if cli_flags.no_cogs is False: print("Loading packages...") failed = [] @@ -62,12 +69,53 @@ def init_events(bot, cli_flags): else: invite_url = None + prefixes = await bot.db.prefix() + lang = await bot.db.locale() + INFO = [str(bot.user), "Prefixes: {}".format(', '.join(prefixes)), + 'Language: {}'.format(lang), + "Red Bot Version: {}".format(get_distribution('Red_DiscordBot').version), + "Discord.py Version: {}".format(get_distribution('discord.py').version), + "Shards: {}".format(bot.shard_count)] if guilds: - print("Ready and operational on {} servers with a total of {} " - "users.".format(guilds, users)) + INFO.extend(("Servers: {}".format(guilds), "Users: {}".format(users))) else: print("Ready. I'm not in any server yet!") + + + INFO.append('{} cogs with {} commands'.format(len(bot.cogs), len(bot.commands))) + + INFO2 = [] + sentry = await bot.db.enable_sentry() + test_docs = all(find_package(x) for x in ['sphinx', 'sphinxcontrib', 'sphinx_rtd_theme', + 'pytest_asyncio', 'pytest']) + voice = find_package('PyNaCl') + + if sentry: + INFO2.append("√ Report Errors") + else: + INFO2.append("X Report Errors") + + if storage_type() == "JSON": + INFO2.append("X MongoDB") + else: + INFO2.append("√ MongoDB") + + if voice: + INFO2.append("√ Voice") + else: + INFO2.append("X Voice") + + if test_docs: + INFO2.append("√ Tests and Docs") + else: + INFO2.append("X Tests and Docs") + + + print(Fore.RED + INTRO) + print(Style.RESET_ALL) + print(bordered(INFO, INFO2)) + if invite_url: print("\nInvite URL: {}\n".format(invite_url)) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index bc05a2995..afe4b5588 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -1,3 +1,5 @@ +import itertools + def error(text): return "\N{NO ENTRY SIGN} {}".format(text) @@ -31,6 +33,23 @@ def italics(text): return "*{}*".format(text) +def bordered(text1: list, text2: list): + width1, width2 = max((len(s1) + 9, len(s2) + 9) for s1 in text1 for s2 in text2) + res = ['┌{}┐{}┌{}┐'.format("─"*width1, " "*4, "─"*width2)] + flag = True + for x, y in itertools.zip_longest(text1, text2): + if y: + m = "│{}│{}│{}│".format((x + " " * width1)[:width1], " "*4, (y + " " * width2)[:width2]) + elif x and flag and not y: + m = "│{}│{}└{}┘".format((x + " " * width1)[:width1], " "*4, "─" * width2) + flag = False + else: + m = "│{}│".format((x + " " * width1)[:width1]) + res.append(m) + res.append("└" + "─" * width1 + "┘") + return "\n".join(res) + + def pagify(text, delims=["\n"], *, escape_mass_mentions=True, shorten_by=8, page_length=2000): """DOES NOT RESPECT MARKDOWN BOXES OR INLINE CODE"""