mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
committed by
Toby Harradine
parent
dae75521d3
commit
889fa63aff
@@ -16,7 +16,6 @@ from . import Config, i18n, commands, errors
|
||||
from .cog_manager import CogManager
|
||||
from .help_formatter import Help, help as help_
|
||||
from .rpc import RPCMixin
|
||||
from .sentry import SentryManager
|
||||
from .utils import common_filters
|
||||
|
||||
|
||||
@@ -47,7 +46,6 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
|
||||
owner=None,
|
||||
whitelist=[],
|
||||
blacklist=[],
|
||||
enable_sentry=None,
|
||||
locale="en",
|
||||
embeds=True,
|
||||
color=15158332,
|
||||
@@ -120,23 +118,8 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
|
||||
|
||||
self.add_command(help_)
|
||||
|
||||
self._sentry_mgr = None
|
||||
self._permissions_hooks: List[commands.CheckPredicate] = []
|
||||
|
||||
def enable_sentry(self):
|
||||
"""Enable Sentry logging for Red."""
|
||||
if self._sentry_mgr is None:
|
||||
sentry_log = logging.getLogger("red.sentry")
|
||||
sentry_log.setLevel(logging.WARNING)
|
||||
self._sentry_mgr = SentryManager(sentry_log)
|
||||
self._sentry_mgr.enable()
|
||||
|
||||
def disable_sentry(self):
|
||||
"""Disable Sentry logging for Red."""
|
||||
if self._sentry_mgr is None:
|
||||
return
|
||||
self._sentry_mgr.disable()
|
||||
|
||||
async def _dict_abuse(self, indict):
|
||||
"""
|
||||
Please blame <@269933075037814786> for this.
|
||||
@@ -516,8 +499,6 @@ class Red(RedBase, discord.AutoShardedClient):
|
||||
|
||||
async def logout(self):
|
||||
"""Logs out of Discord and closes all connections."""
|
||||
if self._sentry_mgr:
|
||||
await self._sentry_mgr.close()
|
||||
|
||||
await super().logout()
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
|
||||
from redbot.core.bot import Red
|
||||
|
||||
|
||||
def confirm(m=""):
|
||||
return input(m).lower().strip() in ("y", "yes")
|
||||
@@ -42,26 +40,9 @@ def interactive_config(red, token_set, prefix_set):
|
||||
if prefix:
|
||||
loop.run_until_complete(red.db.prefix.set([prefix]))
|
||||
|
||||
ask_sentry(red)
|
||||
|
||||
return token
|
||||
|
||||
|
||||
def ask_sentry(red: Red):
|
||||
loop = asyncio.get_event_loop()
|
||||
print(
|
||||
"\nThank you for installing Red V3! Red is constantly undergoing\n"
|
||||
" improvements, and we would like to ask if you are comfortable with\n"
|
||||
" the bot automatically submitting fatal error logs to the development\n"
|
||||
' team. If you wish to opt into the process please type "yes":\n'
|
||||
)
|
||||
if not confirm("> "):
|
||||
loop.run_until_complete(red.db.enable_sentry.set(False))
|
||||
else:
|
||||
loop.run_until_complete(red.db.enable_sentry.set(True))
|
||||
print("\nThank you for helping us with the development process!")
|
||||
|
||||
|
||||
def parse_cli_flags(args):
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Red - Discord Bot", usage="redbot <instance_name> [arguments]"
|
||||
|
||||
@@ -1015,23 +1015,6 @@ class Core(commands.Cog, CoreLogic):
|
||||
|
||||
await ctx.send(_("Locale has been set."))
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def sentry(self, ctx: commands.Context, on_or_off: bool):
|
||||
"""Enable or disable Sentry logging.
|
||||
|
||||
Sentry is the service Red uses to manage error reporting. This should
|
||||
be disabled if you have made your own modifications to the redbot
|
||||
package.
|
||||
"""
|
||||
await ctx.bot.db.enable_sentry.set(on_or_off)
|
||||
if on_or_off:
|
||||
ctx.bot.enable_sentry()
|
||||
await ctx.send(_("Done. Sentry logging is now enabled."))
|
||||
else:
|
||||
ctx.bot.disable_sentry()
|
||||
await ctx.send(_("Done. Sentry logging is now disabled."))
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def custominfo(self, ctx: commands.Context, *, text: str = None):
|
||||
|
||||
@@ -19,34 +19,18 @@ from .utils.chat_formatting import inline, bordered, format_perms_list
|
||||
from .utils import fuzzy_command_search, format_fuzzy_results
|
||||
|
||||
log = logging.getLogger("red")
|
||||
sentry_log = logging.getLogger("red.sentry")
|
||||
init()
|
||||
|
||||
INTRO = """
|
||||
______ _ ______ _ _ ______ _
|
||||
| ___ \ | | | _ (_) | | | ___ \ | |
|
||||
| |_/ /___ __| | ______ | | | |_ ___ ___ ___ _ __ __| | | |_/ / ___ | |_
|
||||
______ _ ______ _ _ ______ _
|
||||
| ___ \ | | | _ (_) | | | ___ \ | |
|
||||
| |_/ /___ __| | ______ | | | |_ ___ ___ ___ _ __ __| | | |_/ / ___ | |_
|
||||
| // _ \/ _` | |______| | | | | / __|/ __/ _ \| '__/ _` | | ___ \/ _ \| __|
|
||||
| |\ \ __/ (_| | | |/ /| \__ \ (_| (_) | | | (_| | | |_/ / (_) | |_
|
||||
| |\ \ __/ (_| | | |/ /| \__ \ (_| (_) | | | (_| | | |_/ / (_) | |_
|
||||
\_| \_\___|\__,_| |___/ |_|___/\___\___/|_| \__,_| \____/ \___/ \__|
|
||||
"""
|
||||
|
||||
|
||||
def should_log_sentry(exception) -> bool:
|
||||
e = exception
|
||||
while e.__cause__ is not None:
|
||||
e = e.__cause__
|
||||
|
||||
tb = e.__traceback__
|
||||
tb_frame = None
|
||||
while tb is not None:
|
||||
tb_frame = tb.tb_frame
|
||||
tb = tb.tb_next
|
||||
|
||||
module = tb_frame.f_globals.get("__name__")
|
||||
return module is not None and module.startswith("redbot")
|
||||
|
||||
|
||||
def init_events(bot, cli_flags):
|
||||
@bot.event
|
||||
async def on_connect():
|
||||
@@ -142,7 +126,6 @@ def init_events(bot, cli_flags):
|
||||
)
|
||||
INFO2 = []
|
||||
|
||||
sentry = await bot.db.enable_sentry()
|
||||
mongo_enabled = storage_type() != "JSON"
|
||||
reqs_installed = {"docs": None, "test": None}
|
||||
for key in reqs_installed.keys():
|
||||
@@ -155,7 +138,6 @@ def init_events(bot, cli_flags):
|
||||
reqs_installed[key] = True
|
||||
|
||||
options = (
|
||||
("Error Reporting", sentry),
|
||||
("MongoDB", mongo_enabled),
|
||||
("Voice", True),
|
||||
("Docs", reqs_installed["docs"]),
|
||||
@@ -177,10 +159,6 @@ def init_events(bot, cli_flags):
|
||||
|
||||
bot.color = discord.Colour(await bot.db.color())
|
||||
|
||||
@bot.event
|
||||
async def on_error(event_method, *args, **kwargs):
|
||||
sentry_log.exception("Exception in {}".format(event_method))
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx, error):
|
||||
if isinstance(error, commands.MissingRequiredArgument):
|
||||
@@ -201,11 +179,6 @@ def init_events(bot, cli_flags):
|
||||
"Exception in command '{}'".format(ctx.command.qualified_name),
|
||||
exc_info=error.original,
|
||||
)
|
||||
if should_log_sentry(error):
|
||||
sentry_log.exception(
|
||||
"Exception in command '{}'".format(ctx.command.qualified_name),
|
||||
exc_info=error.original,
|
||||
)
|
||||
|
||||
message = "Error in command '{}'. Check your console or logs for details.".format(
|
||||
ctx.command.qualified_name
|
||||
@@ -245,13 +218,6 @@ def init_events(bot, cli_flags):
|
||||
)
|
||||
else:
|
||||
log.exception(type(error).__name__, exc_info=error)
|
||||
try:
|
||||
sentry_error = error.original
|
||||
except AttributeError:
|
||||
sentry_error = error
|
||||
|
||||
if should_log_sentry(sentry_error):
|
||||
sentry_log.exception("Unhandled command error.", exc_info=sentry_error)
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from raven import Client
|
||||
from raven.handlers.logging import SentryHandler
|
||||
from raven_aiohttp import AioHttpTransport
|
||||
|
||||
from redbot.core import __version__
|
||||
|
||||
__all__ = ("SentryManager",)
|
||||
|
||||
|
||||
class SentryManager:
|
||||
"""Simple class to manage sentry logging for Red."""
|
||||
|
||||
def __init__(self, logger: logging.Logger):
|
||||
self.client = Client(
|
||||
dsn=(
|
||||
"https://62402161d4cd4ef18f83b16f3e22a020:9310ef55a502442598203205a84da2bb@"
|
||||
"sentry.io/253983"
|
||||
),
|
||||
release=__version__,
|
||||
include_paths=["redbot"],
|
||||
enable_breadcrumbs=False,
|
||||
transport=AioHttpTransport,
|
||||
)
|
||||
self.handler = SentryHandler(self.client)
|
||||
self.logger = logger
|
||||
|
||||
def enable(self):
|
||||
"""Enable error reporting for Sentry."""
|
||||
self.logger.addHandler(self.handler)
|
||||
|
||||
def disable(self):
|
||||
"""Disable error reporting for Sentry."""
|
||||
self.logger.removeHandler(self.handler)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(self.close())
|
||||
|
||||
async def close(self):
|
||||
"""Wait for the Sentry client to send pending messages and shut down."""
|
||||
await self.client.remote.get_transport().close()
|
||||
Reference in New Issue
Block a user