This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathyata.py
154 lines (131 loc) · 4.2 KB
/
yata.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
Copyright 2020 [email protected]
This file is part of yata-bot.
yata 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
any later version.
yata 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.
You should have received a copy of the GNU General Public License
along with yata-bot. If not, see <https://www.gnu.org/licenses/>.
"""
# import standard modules
import os
import sys
import json
import psycopg2
import logging
import logging.config
import time
import sys
import discord
# change folder for .env file if
if len(sys.argv) > 1:
from decouple import AutoConfig
print(os.path.join(os.getcwd(), sys.argv[1]))
config = AutoConfig(search_path=os.path.join(os.getcwd(), sys.argv[1]))
else:
from decouple import config
# import bot
from bots.yata import YataBot
# import cogs
from cogs.verify import Verify
from cogs.loot import Loot
from cogs.api import API
from cogs.chain import Chain
from cogs.racket import Racket
from cogs.war import War
from cogs.admin import Admin
from cogs.revive import Revive
from cogs.misc import Misc
from cogs.crimes import Crimes
# from cogs.elimination import Elimination
# import includes
from inc.yata_db import load_configurations
# configure intents
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
intents.members = True
# logging
logging.config.fileConfig('logging.conf')
logging.Formatter.converter = time.gmtime
logging.debug("debug")
logging.info("info")
logging.warning("warning")
logging.error("error")
# get basic config
bot_id = config("BOT_ID", default=1)
github_token = config("GITHUB_TOKEN", default="")
main_server_id = config("MAIN_SERVER_ID", default=581227228537421825)
master_key = config("MASTER_KEY", default="")
logging.info(f'Starting bot: bot id = {bot_id}')
# databse
database = {
"host": config("DB_HOST", cast=str),
"database": config("DB_DATABASE", cast=str),
"user": config("DB_USER", cast=str),
"password": config("DB_PASSWORD", cast=str),
"port": config("DB_PORT", cast=int),
"min_size": config("DB_MIN_SIZE", cast=int, default=1),
"max_size": config("DB_MAX_SIZE", cast=int, default=5)
}
# sentry
if config("ENABLE_SENTRY", default=False, cast=bool):
logging.info(f'Sentry: enabled')
import sentry_sdk
sentry_sdk.init(
dsn=config("SENTRY_DSN"),
traces_sample_rate=config("SENTRY_SAMPLE_RATE", default=1.0, cast=float),
environment=config("SENTRY_ENVIRONMENT"),
)
else:
logging.info(f'Sentry: disabled')
# get configurations from YATA's database
token, configurations = load_configurations(bot_id, database)
def get_prefix(client, message):
if message.guild:
prefix = client.configurations.get(message.guild.id, {}).get("admin", {}).get("prefix", "!")
return prefix
else:
return "!"
# init yata bot
bot = YataBot(configurations=configurations,
command_prefix=get_prefix,
bot_id=bot_id,
main_server_id=main_server_id,
github_token=github_token,
master_key=master_key,
database=database,
intents=intents)
bot.remove_command('help')
# load classes
bot.add_cog(Admin(bot))
# bot ids:
# 1: Chappie (dev bot)
# 3: YATA (the public bot)
# 6: YATA Legacy (the legacy public bot)
if int(bot_id) in [1]:
bot.add_cog(Misc(bot))
# bot.add_cog(JFK(bot))
# bot.add_cog(Verify(bot))
# bot.add_cog(Chain(bot))
# bot.add_cog(Crimes(bot))
# bot.add_cog(API(bot))
# bot.add_cog(Elimination(bot, config("ELIM_API_TOKEN")))
elif int(bot_id) in [3, 6]:
bot.add_cog(Verify(bot))
bot.add_cog(Loot(bot))
bot.add_cog(Racket(bot))
bot.add_cog(War(bot))
bot.add_cog(Revive(bot))
bot.add_cog(Crimes(bot))
bot.add_cog(API(bot))
bot.add_cog(Chain(bot))
bot.add_cog(Misc(bot))
# bot.add_cog(Elimination(bot, config("ELIM_API_TOKEN")))
# run bot
bot.run(token)