-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (65 loc) · 2.64 KB
/
Copy pathmain.py
File metadata and controls
81 lines (65 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
import discord
from discord import app_commands
from discord.ext import commands
from api_logger import install as install_api_logging, install_inbound_hooks
from config import BOT_TOKEN, LOG_LEVEL, validate_config
validate_config()
assert BOT_TOKEN is not None # narrowed by validate_config()
logging.basicConfig(
level=getattr(logging, LOG_LEVEL, logging.INFO),
format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',
)
logger = logging.getLogger('quillbot')
# Patches aiohttp + httpx before any client (discord.py REST, OpenAI SDK,
# tavily) is constructed.
install_api_logging()
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
# Nothing in message content pings by default: several replies echo user or
# LLM text, which could otherwise smuggle in @everyone / role / user pings.
# Code paths that should notify opt in per message (see ping_send_kwargs).
# replied_user stays on so replies keep notifying their author.
bot = commands.Bot(
command_prefix='!',
intents=intents,
allowed_mentions=discord.AllowedMentions(
everyone=False, users=False, roles=False, replied_user=True,
),
)
# Load order matters: log_analyzer's on_message (pattern matching) runs before
# docs_rag's on_message (follow-up replies). Do not reorder without reviewing
# listener interactions.
COGS = ['cogs.log_analyzer', 'cogs.history_rag', 'cogs.commands', 'cogs.plugins', 'cogs.spark', 'cogs.docs_rag', 'cogs.memory', 'cogs.scheduler', 'cogs.monitors', 'cogs.summary']
@bot.tree.error
async def on_app_command_error(
interaction: discord.Interaction, error: app_commands.AppCommandError
):
if isinstance(error, app_commands.CommandOnCooldown):
await interaction.response.send_message(
f'⏳ Aguarde {error.retry_after:.0f}s antes de usar este comando novamente.',
ephemeral=True,
)
return
logger.exception("Unhandled command error: %s", error)
msg = 'Ocorreu um erro inesperado. Tente novamente.'
if interaction.response.is_done():
await interaction.followup.send(msg, ephemeral=True)
else:
await interaction.response.send_message(msg, ephemeral=True)
@bot.event
async def on_ready():
logger.info('Logged on as %s', bot.user)
synced = await bot.tree.sync()
logger.info('Synced %d slash command(s) with Discord', len(synced))
async def main():
install_inbound_hooks(bot)
async with bot:
for cog in COGS:
await bot.load_extension(cog)
logger.info('Loaded cog: %s', cog)
await bot.start(BOT_TOKEN)
if __name__ == '__main__':
import asyncio
asyncio.run(main())