File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88from cloudbot import hook
99from cloudbot .util import timeformat , formatting
1010
11- reddit_re = re .compile (r'.*(//((www\.)?reddit\.com/r|redd\.it)[^ ]+)' , re .I )
11+ reddit_re = re .compile (
12+ r"""
13+ https? # Scheme
14+ ://
15+
16+ # Domain
17+ (?:
18+ redd\.it|
19+ (?:www\.)?reddit\.com/r
20+ )
21+
22+ (?:/(?:[A-Za-z0-9!$&-.:;=@_~\u00A0-\u10FFFD]|%[A-F0-9]{2})*)* # Path
23+
24+ (?:\?(?:[A-Za-z0-9!$&-;=@_~\u00A0-\u10FFFD]|%[A-F0-9]{2})*)? # Query
25+ """ ,
26+ re .IGNORECASE | re .VERBOSE
27+ )
1228
1329base_url = "https://reddit.com/r/{}"
1430short_url = "https://redd.it/{}"
@@ -51,11 +67,11 @@ def format_output(item, show_url=False):
5167
5268@hook .regex (reddit_re , singlethread = True )
5369def reddit_url (match , bot ):
54- url = match .group (1 )
70+ url = match .group ()
5571 url = URL (url ).with_scheme ("https" )
5672
5773 if url .host .endswith ("redd.it" ):
58- response = requests .get (url )
74+ response = requests .get (url , headers = { 'User-Agent' : bot . user_agent } )
5975 response .raise_for_status ()
6076 url = URL (response .url ).with_scheme ("https" )
6177
You can’t perform that action at this time.
0 commit comments