-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconstants.py
295 lines (231 loc) · 7.64 KB
/
constants.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import dataclasses
import enum
from datetime import UTC, datetime
from os import environ
from pydantic_settings import BaseSettings
from pydis_core.utils import logging
log = logging.get_logger(__name__)
class EnvConfig(
BaseSettings,
env_file=".env",
env_file_encoding="utf-8",
env_nested_delimiter="__",
extra="ignore",
):
"""Our default configuration for models that should load from .env files."""
@dataclasses.dataclass
class AdventOfCodeLeaderboard:
"""Config required for a since AoC leaderboard."""
id: str
_session: str
join_code: str
# If we notice that the session for this board expired, we set
# this attribute to `True`. We will emit a Sentry error so we
# can handle it, but, in the meantime, we'll try using the
# fallback session to make sure the commands still work.
use_fallback_session: bool = False
@property
def session(self) -> str:
"""Return either the actual `session` cookie or the fallback cookie."""
if self.use_fallback_session:
log.trace(f"Returning fallback cookie for board `{self.id}`.")
return AdventOfCode.fallback_session
return self._session
class _AdventOfCode(EnvConfig, env_prefix="AOC_"):
@staticmethod
def _parse_aoc_leaderboard_env() -> dict[str, AdventOfCodeLeaderboard]:
"""
Parse the environment variable containing leaderboard information.
A leaderboard should be specified in the format `id,session,join_code`,
without the backticks. If more than one leaderboard needs to be added to
the constant, separate the individual leaderboards with `::`.
Example ENV: `id1,session1,join_code1::id2,session2,join_code2`
"""
raw_leaderboards = environ.get("AOC_RAW_LEADERBOARDS", "")
if not raw_leaderboards:
return {}
leaderboards = {}
for leaderboard in raw_leaderboards.split("::"):
leaderboard_id, session, join_code = leaderboard.split(",")
leaderboards[leaderboard_id] = AdventOfCodeLeaderboard(leaderboard_id, session, join_code)
return leaderboards
# Information for the several leaderboards we have
leaderboards: dict[str, AdventOfCodeLeaderboard] = _parse_aoc_leaderboard_env()
staff_leaderboard_id: str | None = None
fallback_session: str | None = None
ignored_days: tuple[int, ...] | None = None
leaderboard_displayed_members: int = 10
leaderboard_cache_expiry_seconds: int = 1800
max_day_and_star_results: int = 15
year: int = datetime.now(tz=UTC).year
AdventOfCode = _AdventOfCode()
class _Channels(EnvConfig, env_prefix="CHANNEL_"):
advent_of_code: int = 897932085766004786
advent_of_code_commands: int = 897932607545823342
bot_commands: int = 267659945086812160
devlog: int = 622895325144940554
code_jam_planning: int = 490217981872177157
summer_aoc_main: int = 988979042847957042
summer_aoc_discussion: int = 996438901331861554
sir_lancebot_playground: int = 607247579608121354
summer_code_jam_announcements: int = 988765608172736542
off_topic_0: int = 291284109232308226
off_topic_1: int = 463035241142026251
off_topic_2: int = 463035268514185226
voice_chat_0: int = 412357430186344448
voice_chat_1: int = 799647045886541885
roles: int = 851270062434156586
Channels = _Channels()
class _Categories(EnvConfig, env_prefix="CATEGORY_"):
summer_code_jam: int = 987738098525937745
Categories = _Categories()
class Month(enum.IntEnum):
"""
Enum lookup between Months & month numbers.
Can bre replaced with the below when upgrading to 3.12
https://docs.python.org/3/library/calendar.html#calendar.Month
"""
JANUARY = 1
FEBRUARY = 2
MARCH = 3
APRIL = 4
MAY = 5
JUNE = 6
JULY = 7
AUGUST = 8
SEPTEMBER = 9
OCTOBER = 10
NOVEMBER = 11
DECEMBER = 12
def __str__(self) -> str:
return self.name.title()
class _Bot(EnvConfig, env_prefix="BOT_"):
name: str = "Sir Robin"
guild: int = 267624335836053506
prefix: str = "&"
token: str
debug: bool = True
trace_logging: bool = False
in_ci: bool = False
github_bot_repo: str = "https://github.com/python-discord/sir-robin"
# Override seasonal locks: 1 (January) to 12 (December)
month_override: Month | None = None
sentry_dsn: str = ""
Bot = _Bot()
class _Codejam(EnvConfig, env_prefix="CODE_JAM_"):
api: str = "http://code-jam-management.apis.svc.cluster.local:8000"
api_key: str = "badbot13m0n8f570f942013fc818f234916ca531"
Codejam = _Codejam()
class _Emojis(EnvConfig, env_prefix="EMOJI_"):
check_mark: str = "\u2705"
envelope: str = "\U0001F4E8"
trashcan: str = "<:trashcan:637136429717389331>"
star: str = "\u2B50"
christmas_tree: str = "\U0001F384"
team_tuple: str = "<:team_tuple:1224089419003334768>"
team_list: str = "<:team_list:1224089544257962134>"
team_dict: str = "<:team_dict:1224089495373353021>"
Emojis = _Emojis()
class _Roles(EnvConfig, env_prefix="ROLE_"):
admins: int = 267628507062992896
advent_of_code: int = 518565788744024082
code_jam_event_team: int = 787816728474288181
events_lead: int = 778361735739998228
event_runner: int = 940911658799333408
summer_aoc: int = 988801794668908655
code_jam_participants: int = 991678713093705781
code_jam_support: int = 1254657197535920141
helpers: int = 267630620367257601
aoc_completionist: int = 1191547731873894440
bots: int = 277546923144249364
moderation_team: int = 267629731250176001
team_list: int = 1222691191582097418
team_dict: int = 1222691368653033652
team_tuple: int = 1222691399246286888
Roles = _Roles()
class _RedisConfig(EnvConfig, env_prefix="REDIS_"):
host: str = "redis.databases.svc.cluster.local"
port: int = 6379
password: str | None = None
use_fakeredis: bool = False
RedisConfig = _RedisConfig()
class Colours:
"""Colour hex values commonly used throughout the bot."""
blue = 0x0279FD
twitter_blue = 0x1DA1F2
bright_green = 0x01D277
dark_green = 0x1F8B4C
orange = 0xE67E22
pink = 0xCF84E0
purple = 0xB734EB
soft_green = 0x68C290
soft_orange = 0xF9CB54
soft_red = 0xCD6D6D
yellow = 0xF9F586
python_blue = 0x4B8BBE
python_yellow = 0xFFD43B
grass_green = 0x66FF00
gold = 0xE6C200
# Git SHA for Sentry
GIT_SHA = environ.get("GIT_SHA", "development")
# Whitelisted channels
WHITELISTED_CHANNELS = (
Channels.bot_commands,
Channels.sir_lancebot_playground,
Channels.off_topic_0,
Channels.off_topic_1,
Channels.off_topic_2,
Channels.voice_chat_0,
Channels.voice_chat_1,
)
# Bot replies
ERROR_REPLIES = (
"Please don't do that.",
"You have to stop.",
"Do you mind?",
"In the future, don't do that.",
"That was a mistake.",
"You blew it.",
"You're bad at computers.",
"Are you trying to kill me?",
"Noooooo!!",
"I can't believe you've done this",
)
NEGATIVE_REPLIES = (
"Noooooo!!",
"Nope.",
"I'm sorry Dave, I'm afraid I can't do that.",
"I don't think so.",
"Not gonna happen.",
"Out of the question.",
"Huh? No.",
"Nah.",
"Naw.",
"Not likely.",
"No way, José.",
"Not in a million years.",
"Fat chance.",
"Certainly not.",
"NEGATORY.",
"Nuh-uh.",
"Not in my house!",
)
POSITIVE_REPLIES = (
"Yep.",
"Absolutely!",
"Can do!",
"Affirmative!",
"Yeah okay.",
"Sure.",
"Sure thing!",
"You're the boss!",
"Okay.",
"No problem.",
"I got you.",
"Alright.",
"You got it!",
"ROGER THAT",
"Of course!",
"Aye aye, cap'n!",
"I'll allow it.",
)