-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.py
121 lines (91 loc) · 4 KB
/
config.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
from typing import NamedTuple, Any
from prettyconf import config as _config
_config_registry = []
class _ConfigItem(NamedTuple):
name: str
value: Any
suppress_log: bool = False
def log(self, logger_method, indent=False):
value = "***PRIVATE***" if self.suppress_log else self.value
indentation = ' ' if indent else ''
logger_method(f"{indentation}{self.name} = {value}")
def config(item, cast=lambda v: v, suppress_log=False, **kwargs):
value = _config(item, cast, **kwargs)
global _config_registry
_config_registry.append(_ConfigItem(item, value, suppress_log))
return value
def log(logger_method):
logger_method("Bot configuration:")
for config_item in _config_registry:
config_item.log(logger_method, indent=True)
TELEGRAM_BOT_TOKEN = config(
"TELEGRAM_BOT_TOKEN", default="put here the token of your bot", suppress_log=True
)
# How likely is the bot to be triggered by one of the patterns it recognises.
# - Allowed values: A float from 0 to 1 (0 will disable bot replies)
VERBOSITY = config("BOT_VERBOSITY", float, default=0.33)
# Log level, default is WARNING
LOG_LEVEL = config('LOG_LEVEL', default='WARNING')
# Poll interval for telegram API request, default is 3 seconds
POLL_INTERVAL = config('POLL_INTERVAL', int, default=3)
# Bot message for start command
BOT_GREETING = config(
'BOT_GREETING',
default="<b>Hi!</b> I'm a friendly, <s>crazy</s> slightly psychopath robot",
)
# A username longer than this will be considered non-human
# - Allowed values: An integer larger than 1
MAX_HUMAN_USERNAME_LENGTH = config('MAX_HUMAN_USERNAME_LENGTH', int, default=100)
# We have found, through empiric evidence, that a large ration of Chinese
# characters usually indicates the user is a spammer or bot.
# This sets the maximum allowed percent of Chinese characters before
# considering the user a bot.
# - Allowed values: A float from 0 to 1
MAX_CHINESE_CHARS_PERCENT = config('MAX_CHINESE_CHARS_PERCENT', float, default=0.15)
# Delay (in seconds) to wait before sending welcome message. New users have
# 5 minutes to solve a captcha. The default delay is 5 and a half minutes.
WELCOME_DELAY = config('WELCOME_DELAY', int, default=330)
def bot_replies_enabled() -> bool:
return VERBOSITY > 0
THE_ZEN_OF_PYTHON = [
"Beautiful is better than ugly.",
"Explicit is better than implicit.",
"Simple is better than complex.",
"Complex is better than complicated.",
"Flat is better than nested.",
"Sparse is better than dense.",
"Readability counts.",
"Special cases aren't special enough to break the rules.",
"Although practicality beats purity.",
"Errors should never pass silently.",
"Unless explicitly silenced.",
"In the face of ambiguity, refuse the temptation to guess.",
"There should be one-- and preferably only one --obvious way to do it.",
"Although that way may not be obvious at first unless you're Dutch.",
"Now is better than never.",
"Although never is often better than <b>right</b> now.",
"If the implementation is hard to explain, it's a bad idea.",
"If the implementation is easy to explain, it may be a good idea.",
"Namespaces are one honking great idea -- let's do more of those!",
]
REPLIES = {
("java",): "BIBA JABA!! ☕️",
("cobol",): "BIBA KOBOL!! 💾",
("javascript",): "BIBA JABAESKRIPT!! 🔮",
("php",): "BIBA PEHACHEPÉ!.! ⛱",
("chatgpt", "gpt", "openai"): "BIBA CHATJEPETÉ!! 🤖",
(
"he visto",
"has visto",
"han visto",
"visteis",
"vieron",
"vi",
): "Yo he visto cosas que vosotros no creeríais. Atacar naves en llamas "
"más allá de Orión. He visto Rayos-C brillar en la oscuridad cerca de "
"la puerta de Tannhäuser. Todos esos momentos se perderán en el "
"tiempo... como lágrimas en la lluvia. Es hora de morir. 🔫",
("python", "pitón", "piton"): THE_ZEN_OF_PYTHON,
}
MAXLEN_FOR_USERNAME_TO_TREAT_AS_HUMAN = 100
CHINESE_CHARS_MAX_PERCENT = 0.15