Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf762661

Browse files
committed
Search-only branch for v13.x
1 parent631faab commitf762661

File tree

4 files changed

+79
-135
lines changed

4 files changed

+79
-135
lines changed

‎components/callbacks.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
importdatetimeasdtm
22
importhtml
33
importlogging
4+
importrandom
45
importtime
56
fromcollectionsimportdeque
6-
importrandom
77
fromcopyimportdeepcopy
88
fromtypingimportcast,Match,List,Dict,Any,Optional,Tuple
99

@@ -34,7 +34,6 @@
3434
ONTOPIC_RULES,
3535
OFFTOPIC_RULES,
3636
OFFTOPIC_CHAT_ID,
37-
GITHUB_PATTERN,
3837
ONTOPIC_RULES_MESSAGE_LINK,
3938
OFFTOPIC_RULES_MESSAGE_LINK,
4039
NEW_CHAT_MEMBERS_LIMIT_SPACING,
@@ -52,7 +51,6 @@
5251
reply_or_edit,
5352
try_to_delete,
5453
)
55-
fromcomponents.githubimportgithub_issues
5654

5755

5856
defstart(update:Update,context:CallbackContext)->None:
@@ -85,10 +83,10 @@ def inlinequery_help(update: Update, context: CallbackContext) -> None:
8583
f"but you need an{char}InlineQueryHandler{char} for it.\n\n"
8684
f"*becomes:*\n"
8785
f"I 💙 [InlineQueries]("
88-
"https://python-telegram-bot.readthedocs.io/en/latest/telegram.html#telegram"
86+
"https://python-telegram-bot.readthedocs.io/en/stable/telegram.html#telegram"
8987
f".InlineQuery), but you need an [InlineQueryHandler]("
9088
f"https://python-telegram-bot.readthedocs.io/en"
91-
f"/latest/telegram.ext.html#telegram.ext.InlineQueryHandler) for it.\n\n"
89+
f"/stable/telegram.ext.html#telegram.ext.InlineQueryHandler) for it.\n\n"
9290
f"Some wiki pages have spaces in them. Please replace such spaces with underscores. "
9391
f"The bot will automatically change them back desired space."
9492
)
@@ -130,7 +128,7 @@ def docs(update: Update, _: CallbackContext) -> None:
130128
message=cast(Message,update.effective_message)
131129
text= (
132130
"You can find our documentation at "
133-
"[Read the Docs](https://python-telegram-bot.readthedocs.io/)"
131+
"[Read the Docs](https://python-telegram-bot.readthedocs.io/en/stable)"
134132
)
135133
reply_id=message.reply_to_message.message_idifmessage.reply_to_messageelseNone
136134
message.reply_text(
@@ -148,7 +146,7 @@ def wiki(update: Update, _: CallbackContext) -> None:
148146
message=cast(Message,update.effective_message)
149147
text= (
150148
"You can find our wiki on "
151-
"[GitHub](https://github.com/python-telegram-bot/python-telegram-bot/wiki)"
149+
"[GitHub](https://github.com/python-telegram-bot/v13.x-wiki/wiki)"
152150
)
153151
message.reply_text(
154152
text,
@@ -268,39 +266,12 @@ def keep_typing(last: float, chat: Chat, action: str) -> float:
268266
defreply_search(update:Update,context:CallbackContext)->None:
269267
message=cast(Message,update.effective_message)
270268
last=0.0
271-
thing_matches:List[Tuple[int,Tuple[str,str,str,str,str]]]= []
272269
things:List[Tuple[int,BaseEntry]]= []
273270

274271
no_entity_text=get_text_not_in_entities(message).strip()
275272

276-
# Parse exact matches for GitHub threads & ptbcontrib things first
277-
formatchinGITHUB_PATTERN.finditer(no_entity_text):
278-
logging.debug(match.groupdict())
279-
owner,repo,number,sha,ptbcontrib= [
280-
cast(str,match.groupdict()[x])
281-
forxin ("owner","repo","number","sha","ptbcontrib")
282-
]
283-
ifnumberorshaorptbcontrib:
284-
thing_matches.append((match.start(), (owner,repo,number,sha,ptbcontrib)))
285-
286-
forthing_matchinthing_matches:
287-
last=keep_typing(last,cast(Chat,update.effective_chat),ChatAction.TYPING)
288-
owner,repo,number,sha,ptbcontrib=thing_match[1]
289-
ifnumber:
290-
issue=github_issues.get_issue(int(number),owner,repo)
291-
ifissueisnotNone:
292-
things.append((thing_match[0],issue))
293-
elifsha:
294-
commit=github_issues.get_commit(sha,owner,repo)
295-
ifcommitisnotNone:
296-
things.append((thing_match[0],commit))
297-
elifptbcontrib:
298-
contrib=github_issues.ptbcontribs.get(ptbcontrib)
299-
ifcontrib:
300-
things.append((thing_match[0],contrib))
301-
302273
# Parse fuzzy search next
303-
ifno_entity_text.startswith("!search")orno_entity_text.endswith("!search"):
274+
ifno_entity_text.endswith("!search13")orno_entity_text.endswith("!searchv13"):
304275
formatchinENCLOSED_REGEX.finditer(no_entity_text):
305276
last=keep_typing(last,cast(Chat,update.effective_chat),ChatAction.TYPING)
306277
things.append((match.start(),search.search(match.group(0),amount=1)[0]))

‎components/const.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
OFFTOPIC_RULES_MESSAGE_ID=161133
2929
OFFTOPIC_RULES_MESSAGE_LINK="https://t.me/pythontelegrambottalk/161133"
3030
PTBCONTRIB_LINK="https://github.com/python-telegram-bot/ptbcontrib/"
31-
DOCS_URL="https://python-telegram-bot.readthedocs.io/"
31+
DOCS_URL="https://python-telegram-bot.readthedocs.io/en/stable/"
3232
OFFICIAL_URL="https://core.telegram.org/bots/api"
3333
PROJECT_URL=urljoin(GITHUB_URL,DEFAULT_REPO+"/")
34-
WIKI_URL=urljoin(PROJECT_URL,"wiki/")
34+
WIKI_URL="https://github.com/python-telegram-bot/v13.x-wiki/wiki/"
3535
WIKI_CODE_SNIPPETS_URL=urljoin(WIKI_URL,"Code-snippets")
3636
WIKI_FAQ_URL=urljoin(WIKI_URL,"Frequently-Asked-Questions")
3737
WIKI_FRDP_URL=urljoin(WIKI_URL,"Frequently-requested-design-patterns")
@@ -58,10 +58,10 @@
5858
- If you have a userbot, deactivate it in here. Otherwise you'll get banned at least temporarily.
5959
6060
Before asking, please take a look at our <a href="https://github.com/python-telegram-bot/\
61-
python-telegram-bot/wiki">wiki</a> and <a href="https://github.com/python-telegram-bot/\
61+
v13.x-wiki/wiki">wiki</a> and <a href="https://github.com/python-telegram-bot/\
6262
python-telegram-bot/tree/master/examples">example bots</a> or, depending on your question, the\
6363
<a href="https://core.telegram.org/bots/api">official API docs</a> and <a href="https://\
64-
python-telegram-bot.readthedocs.io">python-telegram-bot docs</a>).
64+
python-telegram-bot.readthedocs.io/en/stable/">python-telegram-bot docs</a>).
6565
For off-topic discussions, please use our <a href="https://telegram.me/pythontelegrambottalk">\
6666
off-topic group</a>.
6767
"""

‎components/taghints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"askright": {
1818
"message": (
1919
'{query} Please read <a href="https://github.com/python-telegram-bot/'
20-
'python-telegram-bot/wiki/Ask-Right">this short article</a> and try again ;)'
20+
'v13.x-wiki/wiki/Ask-Right">this short article</a> and try again ;)'
2121
),
2222
"help":"The wiki page about asking technical questions",
2323
"default": (
@@ -27,8 +27,8 @@
2727
},
2828
"mwe": {
2929
"message": (
30-
'{query} Have a look at <a href="https://github.com/python-telegram-bot/python-'
31-
'telegram-bot/wiki/MWE">this short article</a> for information on what a MWE is.'
30+
'{query} Have a look at <a href="https://github.com/python-telegram-bot/v13.x-wiki'
31+
'/wiki/MWE">this short article</a> for information on what a MWE is.'
3232
),
3333
"help":"How to build an MWE for PTB.",
3434
"default":"Hey. Please provide a minimal working example (MWE).",

‎rules_bot.py

Lines changed: 66 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,29 @@
66
ParseMode,
77
Bot,
88
Update,
9-
BotCommandScopeAllPrivateChats,
10-
BotCommandScopeChat,
11-
BotCommandScopeAllGroupChats,
12-
BotCommandScopeChatAdministrators,
139
)
1410
fromtelegram.errorimportBadRequest,Unauthorized
1511
fromtelegram.extimport (
16-
CommandHandler,
1712
Updater,
1813
MessageHandler,
1914
Filters,
2015
Defaults,
21-
ChatMemberHandler,
2216
InlineQueryHandler,
23-
CallbackQueryHandler,
2417
)
2518

2619
fromcomponentsimportinlinequeries
2720
fromcomponents.callbacksimport (
28-
start,
29-
rules,
30-
docs,
31-
wiki,
32-
help_callback,
33-
off_on_topic,
34-
sandwich,
3521
reply_search,
36-
delete_new_chat_members_message,
37-
greet_new_chat_members,
38-
tag_hint,
39-
say_potato_command,
40-
say_potato_button,
41-
ban_sender_channels,
4222
)
43-
fromcomponents.errorhandlerimporterror_handler
4423
fromcomponents.constimport (
4524
OFFTOPIC_RULES,
46-
OFFTOPIC_USERNAME,
4725
ONTOPIC_RULES,
48-
ONTOPIC_USERNAME,
4926
ONTOPIC_RULES_MESSAGE_ID,
5027
OFFTOPIC_RULES_MESSAGE_ID,
5128
ONTOPIC_CHAT_ID,
5229
OFFTOPIC_CHAT_ID,
5330
)
54-
fromcomponents.taghintsimportTagHintFilter
55-
fromcomponents.utilimport (
56-
rate_limit_tracker,
57-
build_command_list,
58-
)
31+
fromcomponents.errorhandlerimporterror_handler
5932
fromcomponents.githubimportgithub_issues
6033

6134
ifos.environ.get("ROOLSBOT_DEBUG"):
@@ -102,63 +75,63 @@ def main() -> None:
10275

10376
# Note: Order matters!
10477

105-
dispatcher.add_handler(MessageHandler(~Filters.command,rate_limit_tracker),group=-1)
106-
dispatcher.add_handler(
107-
MessageHandler(
108-
Filters.sender_chat.channel&~Filters.is_automatic_forward,ban_sender_channels
109-
)
110-
)
111-
112-
# Simple commands
113-
# The first one also handles deep linking /start commands
114-
dispatcher.add_handler(CommandHandler("start",start))
115-
dispatcher.add_handler(CommandHandler("rules",rules))
116-
dispatcher.add_handler(CommandHandler("docs",docs))
117-
dispatcher.add_handler(CommandHandler("wiki",wiki))
118-
dispatcher.add_handler(CommandHandler("help",help_callback))
119-
120-
# Stuff that runs on every message with regex
121-
dispatcher.add_handler(
122-
MessageHandler(
123-
Filters.regex(r"(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?"),sandwich
124-
)
125-
)
126-
dispatcher.add_handler(MessageHandler(Filters.regex("/(on|off)_topic"),off_on_topic))
127-
128-
# Tag hints - works with regex
129-
dispatcher.add_handler(MessageHandler(TagHintFilter(),tag_hint))
78+
#dispatcher.add_handler(MessageHandler(~Filters.command, rate_limit_tracker), group=-1)
79+
#dispatcher.add_handler(
80+
# MessageHandler(
81+
# Filters.sender_chat.channel & ~Filters.is_automatic_forward, ban_sender_channels
82+
# )
83+
#)
84+
85+
##Simple commands
86+
##The first one also handles deep linking /start commands
87+
#dispatcher.add_handler(CommandHandler("start", start))
88+
#dispatcher.add_handler(CommandHandler("rules", rules))
89+
#dispatcher.add_handler(CommandHandler("docs", docs))
90+
#dispatcher.add_handler(CommandHandler("wiki", wiki))
91+
#dispatcher.add_handler(CommandHandler("help", help_callback))
92+
93+
##Stuff that runs on every message with regex
94+
#dispatcher.add_handler(
95+
# MessageHandler(
96+
# Filters.regex(r"(?i)[\s\S]*?((sudo )?make me a sandwich)[\s\S]*?"), sandwich
97+
# )
98+
#)
99+
#dispatcher.add_handler(MessageHandler(Filters.regex("/(on|off)_topic"), off_on_topic))
100+
101+
##Tag hints - works with regex
102+
#dispatcher.add_handler(MessageHandler(TagHintFilter(), tag_hint))
130103

131104
# We need several matches so Filters.regex is basically useless
132105
# therefore we catch everything and do regex ourselves
133106
dispatcher.add_handler(
134107
MessageHandler(Filters.text&Filters.update.messages&~Filters.command,reply_search)
135108
)
136109

137-
# Status updates
138-
dispatcher.add_handler(
139-
ChatMemberHandler(greet_new_chat_members,chat_member_types=ChatMemberHandler.CHAT_MEMBER)
140-
)
141-
dispatcher.add_handler(
142-
MessageHandler(
143-
Filters.chat(username=[ONTOPIC_USERNAME,OFFTOPIC_USERNAME])
144-
&Filters.status_update.new_chat_members,
145-
delete_new_chat_members_message,
146-
),
147-
group=1,
148-
)
110+
##Status updates
111+
#dispatcher.add_handler(
112+
# ChatMemberHandler(greet_new_chat_members, chat_member_types=ChatMemberHandler.CHAT_MEMBER)
113+
#)
114+
#dispatcher.add_handler(
115+
# MessageHandler(
116+
# Filters.chat(username=[ONTOPIC_USERNAME, OFFTOPIC_USERNAME])
117+
# & Filters.status_update.new_chat_members,
118+
# delete_new_chat_members_message,
119+
# ),
120+
# group=1,
121+
#)
149122

150123
# Inline Queries
151124
dispatcher.add_handler(InlineQueryHandler(inlinequeries.inline_query))
152125

153-
# Captcha for userbots
154-
dispatcher.add_handler(
155-
CommandHandler(
156-
"say_potato",
157-
say_potato_command,
158-
filters=Filters.chat(username=[ONTOPIC_USERNAME,OFFTOPIC_USERNAME]),
159-
)
160-
)
161-
dispatcher.add_handler(CallbackQueryHandler(say_potato_button,pattern="^POTATO"))
126+
##Captcha for userbots
127+
#dispatcher.add_handler(
128+
# CommandHandler(
129+
# "say_potato",
130+
# say_potato_command,
131+
# filters=Filters.chat(username=[ONTOPIC_USERNAME, OFFTOPIC_USERNAME]),
132+
# )
133+
#)
134+
#dispatcher.add_handler(CallbackQueryHandler(say_potato_button, pattern="^POTATO"))
162135

163136
# Error Handler
164137
dispatcher.add_error_handler(error_handler)
@@ -176,25 +149,25 @@ def main() -> None:
176149
github_issues.init_ptb_contribs(dispatcher.job_queue)# type: ignore[arg-type]
177150
github_issues.init_issues(dispatcher.job_queue)# type: ignore[arg-type]
178151

179-
# set commands
180-
updater.bot.set_my_commands(
181-
build_command_list(private=True),
182-
scope=BotCommandScopeAllPrivateChats(),
183-
)
184-
updater.bot.set_my_commands(
185-
build_command_list(private=False),
186-
scope=BotCommandScopeAllGroupChats(),
187-
)
188-
189-
forgroup_namein [ONTOPIC_CHAT_ID,OFFTOPIC_CHAT_ID]:
190-
updater.bot.set_my_commands(
191-
build_command_list(private=False,group_name=group_name),
192-
scope=BotCommandScopeChat(group_name),
193-
)
194-
updater.bot.set_my_commands(
195-
build_command_list(private=False,group_name=group_name,admins=True),
196-
scope=BotCommandScopeChatAdministrators(group_name),
197-
)
152+
##set commands
153+
#updater.bot.set_my_commands(
154+
# build_command_list(private=True),
155+
# scope=BotCommandScopeAllPrivateChats(),
156+
#)
157+
#updater.bot.set_my_commands(
158+
# build_command_list(private=False),
159+
# scope=BotCommandScopeAllGroupChats(),
160+
#)
161+
#
162+
#for group_name in [ONTOPIC_CHAT_ID, OFFTOPIC_CHAT_ID]:
163+
# updater.bot.set_my_commands(
164+
# build_command_list(private=False, group_name=group_name),
165+
# scope=BotCommandScopeChat(group_name),
166+
# )
167+
# updater.bot.set_my_commands(
168+
# build_command_list(private=False, group_name=group_name, admins=True),
169+
# scope=BotCommandScopeChatAdministrators(group_name),
170+
# )
198171

199172
updater.idle()
200173

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp