-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
87 lines (70 loc) · 2.65 KB
/
main.py
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
82
83
84
85
86
87
import asyncio
import logging
import os
import alaric
from alaric import Cursor
from dotenv import load_dotenv
from logoo import PrimaryLogger
import suggestions
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format="%(levelname)-8s | %(asctime)s | %(filename)19s:%(funcName)-27s | %(message)s",
datefmt="%d/%m/%Y %I:%M:%S %p",
)
# logging.getLogger("asyncio").setLevel(logging.DEBUG)
disnake_logger = logging.getLogger("disnake")
disnake_logger.setLevel(logging.INFO)
gateway_logger = logging.getLogger("disnake.gateway")
gateway_logger.setLevel(logging.WARNING)
client_logger = logging.getLogger("disnake.client")
client_logger.setLevel(logging.WARNING)
http_logger = logging.getLogger("disnake.http")
http_logger.setLevel(logging.WARNING)
shard_logger = logging.getLogger("disnake.shard")
shard_logger.setLevel(logging.WARNING)
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING)
logoo_logger = logging.getLogger("logoo")
logoo_logger.setLevel(logging.INFO)
suggestions_logger = logging.getLogger("suggestions")
suggestions_logger.setLevel(logging.DEBUG)
member_stats_logger = logging.getLogger("suggestions.objects.stats.member_stats")
member_stats_logger.setLevel(logging.INFO)
async def run_bot():
# tracemalloc.start()
log = logging.getLogger(__name__)
bot = await suggestions.create_bot()
logger: PrimaryLogger = PrimaryLogger(
__name__,
base_url="https://logs.suggestions.gg",
org="default",
stream="prod_bot" if bot.is_prod else "test_bot",
username=os.environ["LOGOO_USER"],
password=os.environ["LOGOO_PASSWORD"],
poll_time=15,
global_metadata={
"cluster": bot.cluster_id,
"bot_version": bot.version,
},
)
await logger.start_consumer()
# Make sure we don't shutdown due to a previous shutdown request
cursor: Cursor = (
Cursor.from_document(bot.db.cluster_shutdown_requests)
.set_sort(("timestamp", alaric.Descending))
.set_limit(1)
)
items = await cursor.execute()
if items:
entry = items[0]
if bot.cluster_id not in entry["responded_clusters"]:
entry["responded_clusters"].append(bot.cluster_id)
await bot.db.cluster_shutdown_requests.upsert({"_id": entry["_id"]}, entry)
log.debug("Marked old shutdown request as satisfied")
await bot.load()
TOKEN = os.environ["PROD_TOKEN"] if bot.is_prod else os.environ["TOKEN"]
log.info("About to start SuggestionsBot | %s", bot.version)
log.info("We are in prod" if bot.is_prod else "We are launching in non-prod")
await bot.start(TOKEN)
asyncio.run(run_bot())