-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathconst.py
257 lines (249 loc) · 8.5 KB
/
const.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
import re
from urllib.parse import urljoin
ARROW_CHARACTER = "➜"
GITHUB_URL = "https://github.com/"
DEFAULT_REPO_OWNER = "python-telegram-bot"
DEFAULT_REPO_NAME = "python-telegram-bot"
PTBCONTRIB_REPO_NAME = "ptbcontrib"
DEFAULT_REPO = f"{DEFAULT_REPO_OWNER}/{DEFAULT_REPO_NAME}"
# Require x non-command messages between each /rules etc.
RATE_LIMIT_SPACING = 2
# Welcome new chat members at most ever X minutes
NEW_CHAT_MEMBERS_LIMIT_SPACING = 60
USER_AGENT = "Github: python-telegram-bot/rules-bot"
DEFAULT_HEADERS = {"User-Agent": USER_AGENT}
ENCLOSING_REPLACEMENT_CHARACTER = "+"
_ERC = ENCLOSING_REPLACEMENT_CHARACTER
ENCLOSED_REGEX = re.compile(rf"\{_ERC}([^{_ERC}]*)\{_ERC}")
OFFTOPIC_USERNAME = "pythontelegrambottalk"
ONTOPIC_USERNAME = "pythontelegrambotgroup"
DEV_GROUP_USERNAME = "pythontelegrambotdev"
OFFTOPIC_CHAT_ID = "@" + OFFTOPIC_USERNAME
ONTOPIC_CHAT_ID = "@" + ONTOPIC_USERNAME
ERROR_CHANNEL_CHAT_ID = -1001397960657
TELEGRAM_SUPERSCRIPT = "ᵀᴱᴸᴱᴳᴿᴬᴹ"
FAQ_CHANNEL_ID = "@ptbfaq"
SELF_BOT_NAME = "roolsbot"
PTBCONTRIB_LINK = "https://github.com/python-telegram-bot/ptbcontrib/"
DOCS_URL = "https://docs.python-telegram-bot.org/"
OFFICIAL_URL = "https://core.telegram.org/bots/api"
PROJECT_URL = urljoin(GITHUB_URL, DEFAULT_REPO + "/")
WIKI_URL = urljoin(PROJECT_URL, "wiki/")
WIKI_CODE_SNIPPETS_URL = urljoin(WIKI_URL, "Code-snippets")
WIKI_FAQ_URL = urljoin(WIKI_URL, "Frequently-Asked-Questions")
WIKI_FRDP_URL = urljoin(WIKI_URL, "Frequently-requested-design-patterns")
EXAMPLES_URL = urljoin(DOCS_URL, "/examples.html")
ALLOWED_USERNAMES = (OFFTOPIC_USERNAME, ONTOPIC_USERNAME, DEV_GROUP_USERNAME)
ALLOWED_CHAT_IDS = (
ERROR_CHANNEL_CHAT_ID,
-1001494805131, # dev chat
-1001101839433, # Church
)
ONTOPIC_RULES = f"""This group is for questions, answers and discussions around the \
<a href="https://python-telegram-bot.org/">python-telegram-bot library</a> and, to some extent, \
Telegram bots in general.
<b>Rules:</b>
- The group language is English
- Stay on topic
- Advertisement (including coding job offers) or posting as channels is disallowed
- No meta questions (eg. <i>"Can I ask something?"</i>)
- Use a pastebin when you have a question about your code, like <a href="https://www.codepile.net"\
>this one</a>. If you <i>really</i> can't explain your problem without showing a picture, upload\
it somewhere and share a link.
- Use <code>/wiki</code> and <code>/docs</code> in a private chat if possible.
- Only mention or reply to users directly if you're answering their question or following up on a \
conversation with them.
- Please abide by our <a href="{DOCS_URL}coc.html">Code of Conduct</a>
- Use <code>@admin</code> to report spam or abuse and <i>only</i> for that.
- If you have a userbot, deactivate it in here. Otherwise you'll get banned at least temporarily.
- Don't copy-paste answers that were generated by an AI/LLM tool (e.g. ChatGPT).
- If you have asked your question elsewhere before (e.g. StackOverflow or PTBs GitHub repo),
include a link to it in your question.
Before asking, please take a look at our <a href="{WIKI_URL}">wiki</a> and \
<a href="{EXAMPLES_URL}">example bots</a> or, depending on your question, the \
<a href="{OFFICIAL_URL}">official API docs</a> and <a href="{DOCS_URL}">\
python-telegram-bot docs</a>). Please also make sure to read the <a href="{WIKI_URL}Ask-Right">\
wiki page on how to ask good questions</a>.
For off-topic discussions, please use our <a href="https://t.me/{OFFTOPIC_USERNAME}">\
off-topic group</a>.
"""
OFFTOPIC_RULES = f"""<b>Topics:</b>
- Discussions about Python in general
- Meta discussions about <code>python-telegram-bot</code>
- Friendly, respectful talking about non-tech topics
<b>Rules:</b>
- The group language is English
- Advertisement (including coding job offers) or posting as channels is disallowed
- Use a pastebin to share code. If you <i>really</i> can't explain your problem without showing a\
picture, upload it somewhere and share a link.
- No shitposting, flamewars or excessive trolling
- Max. 1 meme per user per day
- Only mention or reply to users directly if you're answering their question or following up on a \
conversation with them.
- Please abide by our <a href="{DOCS_URL}coc.html">Code of Conduct</a>
- Use <code>@admin</code> to report spam or abuse and <i>only</i> for that.
- If you have a userbot, deactivate it in here. Otherwise you'll get banned at least temporarily.
- Don't copy-paste answers that were generated by an AI/LLM tool (e.g. ChatGPT).
- If you have asked your question elsewhere before (e.g. StackOverflow or PTBs GitHub repo),
include a link to it in your question.
"""
# Github Pattern
# This matches two different kinds of things:
# 1. ptbcontrib/description
# 2. owner/repo(#|GH-|PR-|@)number/query, where both owner/ and repo are optional
#
# Per https://github.com/join
# Github username may only contain alphanumeric characters or hyphens.
# Github username cannot have multiple consecutive hyphens.
# Github username cannot begin or end with a hyphen.
# Maximum is 39 characters.
# Therefore we use:
# [a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}
#
# Repo names seem to allow alphanumeric, -, . and _
# And the form at https://github.com/new has a maxlength of 100
# Therefore we use
# [A-Za-z0-9-._]{0,100}
GITHUB_PATTERN = re.compile(
r"""
(?i) # Case insensitivity
[\s\S]*? # Any characters
(?P<full> # Capture for the the whole thing
(?: # Optional non-capture group for owner/repo#number/sha/query matches
(?: # Optional non-capture group for username/repo
# Matches username or org - only if ends with slash
(?:(?P<owner>[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})/)?
(?P<repo>[A-Za-z0-9-._]{0,100})? # Optionally matches repo
)? # End optional non-capture group
(?: # Match either
(
# "#" or "GH-" or "PR-" or "/issues/" or "/pull"
(?P<number_type>\#|GH-|PR-|/issues/|/pull/)
(?: # Followed by either
(?P<number>\d+) # Numbers
| # Or
(?P<query>.+) # A search query (only works inline)
)
)
| # Or
(?:(/commit/|@) # /commit/ or @
(?P<sha>[0-9a-f]{7,40})) # sha: 7-40 hexadecimal chars
)
)
| # Or ptbcontrib match
ptbcontrib/(?P<ptbcontrib>[\w_]+)
)
""",
re.VERBOSE,
)
VEGETABLES = [
"amaranth",
"anise",
"artichoke",
"arugula",
"asparagus",
"aubergine",
"basil",
"beet",
"broccoflower",
"broccoli",
"cabbage",
"calabrese",
"caraway",
"carrot",
"cauliflower",
"celeriac",
"celery",
"chamomile",
"chard",
"chayote",
"chickpea",
"chives",
"cilantro",
"corn",
"corn salad",
"courgette",
"cucumber",
"daikon",
"delicata",
"dill",
"eggplant",
"endive",
"fennel",
"fiddlehead",
"frisee",
"garlic",
"ginger",
"habanero",
"horseradish",
"jalapeno",
"jicama",
"kale",
"kohlrabi",
"lavender",
"leek ",
"legume",
"lentils",
"lettuce",
"mamey",
"mangetout",
"marjoram",
"mushroom",
"nopale",
"okra",
"onion",
"oregano",
"paprika",
"parsley",
"parsnip",
"pea",
"potato",
"pumpkin",
"radicchio",
"radish",
"rhubarb",
"rosemary",
"rutabaga",
"sage",
"scallion",
"shallot",
"skirret",
"spinach",
"squash",
"taro",
"thyme",
"topinambur",
"tubers",
"turnip",
"wasabi",
"watercress",
"yam",
"zucchini",
]
BUY_TEXT = (
"Hello there, {0}. You are writing your job offer in our technical focused groups, which is "
"against our rules. To find a bot developer, please look at agencies dedicated towards "
"freelancers. An example of those would be https://fiverr.com, which we are not "
"associated with."
)
TOKEN_TEXT = "⚠️ You posted a token, go revoke it with @BotFather.\n\n"
COMPAT_ERRORS = re.compile(
r"""
(
(Updater\._{0,2}init_{0,2}\(\))?
(
\ got\ an\ unexpected\ keyword\ argument
\ ['"]*(use_context|token|use_controls|dispatcher)['"]*
|
\ missing\ 1\ required\ positional\ argument:\ ['"]*update_queue['"]*
)
)|(
updater\.(idle\(\)|dispatcher)
)|(
dispatcher.add_handler\(
)|(
cannot\ import\ name\ ['"]*Filters['"]*
)
""",
flags=re.VERBOSE,
)