-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstartbot.py
61 lines (50 loc) · 1.97 KB
/
startbot.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
# Copyright (C) 2024, Kurzgesagt Community Devs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
"""
This is the entrypoint used to start the bot.
It provides command-line arguments to specify which instance of the bot to run (beta, alpha, or main).
It loads the necessary environment variables from a .env file and starts the bot with the specified token.
Usage:
python3 startbot.py [-b] [-a]
Options:
-b, --beta Run the beta instance of the bot
-a, --alpha Run the alpha instance of the bot
"""
import argparse
import asyncio
import logging
import os
import dotenv
from app.birdbot import BirdBot, setup
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--beta", help="Run the beta instance of the bot", action="store_true")
parser.add_argument("-a", "--alpha", help="Run the alpha instance of the bot", action="store_true")
async def main() -> None:
with setup():
logger = logging.getLogger("Startbot")
dotenv.load_dotenv()
args = parser.parse_args()
bot = BirdBot.from_parseargs(args)
if args.beta:
token: str | None = os.environ.get("BETA_BOT_TOKEN")
elif args.alpha:
token: str | None = os.environ.get("ALPHA_BOT_TOKEN")
else:
token: str | None = os.environ.get("MAIN_BOT_TOKEN")
async with bot:
if token:
await bot.start(token, reconnect=True)
else:
logger.critical("No token found")
exit(-1)
if __name__ == "__main__":
asyncio.run(main())