This repository has been archived by the owner on Oct 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·127 lines (100 loc) · 3.42 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
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
#!/usr/bin/env python3
"""
STORYTELLER BOT
-------------------------
[2020] Code by Xinverse
NOTICE: The copyrights of the games belong to their respective holders,
unless otherwise specified. This project is an independent adaptation
of commercial board games into Discord bot format; the Developer is not
affiliated with them in any way.
"""
import atexit
import os
import sys
from datetime import datetime
import discord
import psutil
from discord.ext import commands
import demoji
import pytz
import globvars # isort: split
import cmd
import botc
import botutils
from botutils import bot_text
from config import DISABLE_PINGS, OWNER_ID, PREFIX, TOKEN
if __name__ == "__main__":
try:
with open("botc.pid") as fd:
pid = int(fd.read())
except (FileNotFoundError, ValueError):
pass
else:
if psutil.pid_exists(pid):
print(f"Error: Another instance of the bot is already running (PID {pid}). Please close it before starting a new instance.")
sys.exit(1)
else:
print("PID file is stale, removing")
os.unlink("botc.pid")
with open("botc.pid", "w") as fd:
fd.write(str(os.getpid()))
def remove_pidfile():
os.unlink("botc.pid")
atexit.register(remove_pidfile)
last_downloaded = demoji.last_downloaded_timestamp()
if last_downloaded is None or (datetime.now(pytz.utc) - last_downloaded).days > 100:
# Download emojis
print(f"===== DOWNLOADING EMOJI DATA =====")
demoji.download_codes()
globvars.init_client()
globvars.init_master_state()
def command_prefix(bot, message):
if message.guild is None:
return (PREFIX, "")
else:
return PREFIX
# The help command
help_command = cmd.Help(
verify_checks = False,
show_hidden = False,
dm_help = True,
dm_help_threshold = 700,
no_category = bot_text["system"]["others_cog"],
command_attrs = {
"brief" : bot_text["doc"]["help"]["brief"],
"help" : bot_text["doc"]["help"]["help"],
"description" : bot_text["doc"]["help"]["description"]
}
)
intents = discord.Intents.default()
intents.members = True
intents.presences = True
if DISABLE_PINGS:
allowed_mentions = discord.AllowedMentions.none()
else:
allowed_mentions = discord.AllowedMentions(everyone=False)
# The bot
globvars.client = commands.Bot(
command_prefix = command_prefix,
owner_id = OWNER_ID,
case_insensitive = True,
description = "〘 Blood on the Clocktower Storyteller Bot 〙 - by Xinverse#4011",
paginator = commands.Paginator(),
help_command = help_command,
intents = intents,
allowed_mentions = allowed_mentions,
)
globvars.client.add_check(botutils.check_if_not_ignored)
botutils.rate_limit_commands.start()
# Loading game packs
print("===== LOADING GAME PACKS =====")
botc.load_pack(globvars.master_state)
print(globvars.master_state.game_packs)
extensions = ["admin", "gameplay", "miscellaneous", "listeners"]
# Loading command extensions
print("===== LOADING COMMAND EXTENSIONS =====")
for extension in extensions:
globvars.client.load_extension(f"cmd.{extension}")
print(f"> {extension} cog successfully loaded")
print("===== LOGGING IN =====")
globvars.client.run(TOKEN)