ソースを参照

Improvements to social media preview URL regexes

main
Rocketsoup 2週間前
コミット
99281f1377
1個のファイルの変更9行の追加6行の削除
  1. 9
    6
      rocketbot/cogs/videopreviewcog.py

+ 9
- 6
rocketbot/cogs/videopreviewcog.py ファイルの表示

73
 		brief='whether to show video previews for Twitter links',
73
 		brief='whether to show video previews for Twitter links',
74
 	)
74
 	)
75
 
75
 
76
-	REGEX_INSTAGRAM_POST = r'https?:\/\/(?:www\.)?instagram\.com\/(?:p|reel)\/[a-zA-Z0-9_-]+\/?'
77
-	REGEX_FACEBOOK_POST = r'https?:\/\/(?:www\.)?facebook\.com\/share\/[rv]\/[a-zA-Z0-9_-]+\/?'
78
-	REGEX_TWITTER_POST = r'https?:\/\/(?:twitter|x)\.com\/[a-zA-Z0-9_-]+/status/[0-9]+'
76
+	REGEX_INSTAGRAM_POST = r'(https?:\/\/(?:www\.)?)\w*(instagram\.com\/\w+/\w+\/?)'
77
+	REGEX_FACEBOOK_POST = r'(https?:\/\/(?:www\.)?)\w*(facebook\.com(?:\/\w+)+\/\w+\/?)'
78
+	REGEX_TWITTER_POST = r'(https?:\/\/(?:www\.)?)\w*((?:twitter|x)\.com\/\w+\/status\/[0-9]+)'
79
 
79
 
80
 	REGEX_SPOILERS = '\|\|.+\|\|'
80
 	REGEX_SPOILERS = '\|\|.+\|\|'
81
 
81
 
125
 		has_spoilers = re.match(Self.REGEX_SPOILERS, content) is not None
125
 		has_spoilers = re.match(Self.REGEX_SPOILERS, content) is not None
126
 		if self.get_guild_setting(message.guild, Self.SETTING_INSTAGRAM):
126
 		if self.get_guild_setting(message.guild, Self.SETTING_INSTAGRAM):
127
 			for link in re.findall(Self.REGEX_INSTAGRAM_POST, content):
127
 			for link in re.findall(Self.REGEX_INSTAGRAM_POST, content):
128
-				links.append(MessageLink(link, 'instagram', has_spoilers))
128
+				url = link[0] + link[1]
129
+				links.append(MessageLink(url, 'instagram', has_spoilers))
129
 		if self.get_guild_setting(message.guild, Self.SETTING_FACEBOOK):
130
 		if self.get_guild_setting(message.guild, Self.SETTING_FACEBOOK):
130
 			for link in re.findall(Self.REGEX_FACEBOOK_POST, content):
131
 			for link in re.findall(Self.REGEX_FACEBOOK_POST, content):
131
-				links.append(MessageLink(link, 'facebook', has_spoilers))
132
+				url = link[0] + link[1]
133
+				links.append(MessageLink(url, 'facebook', has_spoilers))
132
 		if self.get_guild_setting(message.guild, Self.SETTING_TWITTER):
134
 		if self.get_guild_setting(message.guild, Self.SETTING_TWITTER):
133
 			for link in re.findall(Self.REGEX_TWITTER_POST, content):
135
 			for link in re.findall(Self.REGEX_TWITTER_POST, content):
134
-				links.append(MessageLink(link, 'twitter', has_spoilers))
136
+				url = link[0] + link[1]
137
+				links.append(MessageLink(url, 'twitter', has_spoilers))
135
 		# TODO: Custom patterns
138
 		# TODO: Custom patterns
136
 		return links
139
 		return links
137
 
140
 

読み込み中…
キャンセル
保存