- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrunner.py
More file actions
Latest commit
60 lines (44 loc) · 1.39 KB
/
Copy pathrunner.py
File metadata and controls
60 lines (44 loc) · 1.39 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
importcontextlib
importjson
importlogging
importos
importdiscord
fromdiscord.extimportcommands
frombotimportRustBot
@contextlib.contextmanager
defsetup_logging():
logger=logging.getLogger("bot")
logger.setLevel(logging.INFO)
try:
dt_fmt="%Y-%m-%d %H:%M:%S"
formatter=logging.Formatter(
"[{asctime}] [{levelname:<7}] {name}: {message}", dt_fmt, style="{"
)
file_handler=logging.FileHandler(
filename="logging.log", encoding="utf-8", mode="w"
)
file_handler.setFormatter(formatter)
stream_handler=logging.StreamHandler()
stream_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
yield
finally:
handlers=logger.handlers[:]
forhandlerinhandlers:
handler.close()
logger.removeHandler(handler)
defmain():
withopen("config.json") asf:
config=json.load(f)
intents=discord.Intents.default()
intents.members=True
withsetup_logging():
bot=RustBot(
command_prefix=commands.when_mentioned_or(*config["prefixes"]),
config=config,
intents=intents,
)
bot.run(os.environ["DISCORD_TOKEN"])
if__name__=="__main__":
main()