Esempio n. 1
0
def main():
    with open("config/config.json") as f:
        dat = json.load(f)
    if not dat["sentry_dsn"] or dat["sentry_dsn"] != "nO":
        use_sentry(
            bot,  # it is typically named client or bot
            dsn=str(dat["sentry_dsn"])
            # put in any sentry keyword arguments (**kwargs) here
        )

    initial_extensions = [
        "cogs.appeals",
        "cogs.autoresponse",
        # "cogs.censor",
        # "cogs.chat",
        "cogs.coin",
        "cogs.core",
        "cogs.dev",
        "cogs.error_handler",
        "cogs.levels",
        "cogs.lockdown",
        "cogs.memes",
        "cogs.moderation",
        "cogs.applications",
        # "cogs.search",
        # "cogs.verify",
        "utils.checks",
        "cogs.corona",
        "cogs.vc_things",
    ]
    for ext in initial_extensions:
        try:
            bot.load_extension(ext)
            log("Load", f"Loaded {ext}")
        except commands.ExtensionError:
            errors.append((ext, str(traceback.format_exc())))
            log("Load", f"Failed to load {ext}", LogLevel.ERROR)

    log("Login", "Logging in")
    while True:
        try:
            bot.run()
        except discord.errors.LoginFailure:
            log("Login", f"Login failed:\n{traceback.format_exc()}",
                LogLevel.ERROR)
            return
        except SystemExit:
            log("Stop", "Stopped bot")
            bot.save()
            logfile.close()
            with open("latest.log") as latest, open(log_name,
                                                    "wb+") as compressed:
                compressed.write(compress(latest.read()))
Esempio n. 2
0
def main():
    with open('config/config.json') as f:
        dat = json.load(f)
    if not dat["sentry_dsn"] or dat["sentry_dsn"] != "nO":
        use_sentry(
            bot,  # it is typically named client or bot
            dsn=str(dat["sentry_dsn"])
            # put in any sentry keyword arguments (**kwargs) here
        )

    initial_extensions = [
        "cogs.appeals",
        "cogs.autoresponse",
        "cogs.coin",
        "cogs.core",
        "cogs.dev",
        "cogs.error_handler",
        "cogs.levels",
        "cogs.lockdown",
        "cogs.moderation",
        "cogs.chat",
        "cogs.verify",
        "cogs.log",
        "utils.checks",
    ]
    for ext in initial_extensions:
        try:
            bot.load_extension(ext)
            log("Load", f"Loaded {ext}")
        except ExtensionError:
            errors.append((ext, str(traceback.format_exc())))
            log("Load", f"Failed to load {ext}")

    log("Login", "Logging in")
    while True:
        try:
            bot.run()
        except discord.errors.LoginFailure:
            log("Login", f"Login failed:\n{traceback.format_exc()}")
            return
        except SystemExit:
            log("Stop", "Stopped bot")
            return bot.save()
Esempio n. 3
0
async def determine_prefix(bot, message):
    if message.guild is None:
        return "$"

    prefix = await config.get(message.guild.id, "CommandPrefix")
    return "$" if prefix is False else prefix


discordbot = commands.Bot(command_prefix=determine_prefix,
                          help_command=EmbedHelpCommand(),
                          allowed_mentions=discord.AllowedMentions(
                              everyone=False, users=True, roles=False),
                          intents=discord.Intents.all())

if os.environ.get("SENTRY_URL"):
    use_sentry(discordbot, dsn=os.environ.get("SENTRY_URL"))

discordbot.load_extension("alttprbot_discord.cogs.admin")
discordbot.load_extension("alttprbot_discord.cogs.aqttp")
discordbot.load_extension("alttprbot_discord.cogs.alttprgen")
discordbot.load_extension("alttprbot_discord.cogs.audit")
discordbot.load_extension("alttprbot_discord.cogs.bontamw")
discordbot.load_extension("alttprbot_discord.cogs.daily")
discordbot.load_extension("alttprbot_discord.cogs.discord_servers")
discordbot.load_extension("alttprbot_discord.cogs.league")
discordbot.load_extension("alttprbot_discord.cogs.misc")
discordbot.load_extension("alttprbot_discord.cogs.moderation")
discordbot.load_extension("alttprbot_discord.cogs.nickname")
discordbot.load_extension("alttprbot_discord.cogs.role")
# discordbot.load_extension("alttprbot_discord.cogs.sgl")
discordbot.load_extension("alttprbot_discord.cogs.smvaria")
Esempio n. 4
0
intents.reactions = True
intents.members = True
intents.presences = True

#Defining client and SlashCommands
client = commands.Bot(command_prefix=config['prefix'],
                      intents=intents,
                      case_insensitive=True)
client.remove_command("help")

#Sentry Panel Stuff -
from discord_sentry_reporting import use_sentry

use_sentry(
    client,  # it is typically named client or bot
    dsn=
    "https://[email protected]/5579376",
    traces_sample_rate=1.0)

#Logging
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log',
                              encoding='utf-8',
                              mode='w')
handler.setFormatter(
    logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
now = datetime.now().strftime("%H:%M:%S")

logger.info(f"PortalBot has started! {now}")
Esempio n. 5
0
    load_dotenv(dotenv_path)

    token = os.getenv('DISCORD_BOT_TOKEN')
    dsn = os.getenv('SENTRY_DSN')

    if token is None:
        raise FileNotFoundError("Token not found error!")
    if dsn is None:
        raise FileNotFoundError("dsn not found error!")

    logging.basicConfig(level=logging.INFO,
                        format='%(levelname)s: %(message)s')
    logging.disable(logging.INFO)

    sentry_logging = LoggingIntegration(
        level=logging.INFO,  # Capture info and above as breadcrumbs
        event_level=logging.WARNING  # Send errors as events
    )

    currentpath = os.path.dirname(os.path.abspath(__file__))

    bot = MyBot(command_prefix=commands.when_mentioned_or('/'))
    with open(currentpath + "/data/specific_setting.json",
              encoding='utf-8') as f:
        json_data = json.load(f)

    use_sentry(bot,
               dsn=dsn,
               integrations=[AioHttpIntegration(), sentry_logging])
    bot.run(token)
Esempio n. 6
0
# The code in this event is executed every time a command has been *successfully* executed
@bot.event
async def on_command_completion(ctx):
    fullCommandName = ctx.command.qualified_name
    guild_name = "DMs"
    if ctx.guild is not None:
        guild_name = ctx.guild.name
    logger.debug(
        f"Executed '{fullCommandName}' command in {guild_name} by {ctx.message.author} (ID: {ctx.message.author.id})"
    )


if "SENTRY_URL" in os.environ:
    logger.debug("Initializing Sentry error logging")
    from discord_sentry_reporting import use_sentry

    use_sentry(bot, dsn=os.environ["SENTRY_URL"])

if __name__ == "__main__":
    extensions = load_cogs('cogs')
    for extension in extensions:
        try:
            bot.load_extension('cogs.' + extension)
            logger.success(f'Loaded {extension} cog.')
        except Exception as error:
            logger.exception(
                f"Extension {extension} could not be loaded. [{error}]")

    bot.run(os.environ["TOKEN"])