1515from translations import get_text , LANGUAGE_NAMES , TRANSLATIONS
1616
1717# Version number
18- VERSION = "1.2.3 "
18+ VERSION = "1.2.4 "
1919
2020# Service configuration for link processing
2121SERVICES = {
5353 "patterns" : [r"youtube\.com/watch\?v=([\w-]+)" , r"youtu\.be/([\w-]+)" ],
5454 "replacements" : {"youtube.com" : "koutube.com" , "youtu.be" : "koutube.com/watch?v=" },
5555 "display_format" : "YouTube • {0}"
56+ },
57+ "Bilibili" : {
58+ "patterns" : [r"bilibili\.com/video/([\w]+)" , r"b23\.tv/([\w]+)" ],
59+ "replacements" : {"bilibili.com" : "vxbilibili.com" , "b23.tv" : "vxb23.tv" },
60+ "display_format" : "Bilibili • {0}"
5661 }
5762}
5863
@@ -146,7 +151,7 @@ async def load_settings(db):
146151 mention_users = row [2 ]
147152 delete_original = row [3 ]
148153 language = row [4 ] if len (row ) > 4 else "en"
149- enabled_services_list = eval (enabled_services ) if enabled_services else ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ]
154+ enabled_services_list = eval (enabled_services ) if enabled_services else ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ]
150155 bot_settings [guild_id ] = {
151156 "enabled_services" : enabled_services_list ,
152157 "mention_users" : mention_users if mention_users is not None else True ,
@@ -198,7 +203,7 @@ async def on_ready():
198203 client .launch_time = discord .utils .utcnow ()
199204
200205statuses = itertools .cycle ([
201- "for Twitter links" , "for Reddit links" , "for Instagram links" , "for Threads links" , "for Pixiv links" , "for Bluesky links" , "for YouTube links"
206+ "for Twitter links" , "for Reddit links" , "for Instagram links" , "for Threads links" , "for Pixiv links" , "for Bluesky links" , "for YouTube links" , "for Bilibili links"
202207])
203208
204209@tasks .loop (seconds = 60 )
@@ -276,7 +281,8 @@ async def about(interaction: discord.Interaction):
276281 "- [fixthreads](https://github.com/milanmdev/fixthreads), created by milanmdev\n "
277282 "- [phixiv](https://github.com/thelaao/phixiv), created by thelaao\n "
278283 "- [VixBluesky](https://github.com/Rapougnac/VixBluesky), created by Rapougnac\n "
279- "- [koutube](https://github.com/iGerman00/koutube), created by iGerman00"
284+ "- [koutube](https://github.com/iGerman00/koutube), created by iGerman00\n "
285+ "- [BiliFix](https://www.vxbilibili.com/), created by BiliFix\n "
280286 ),
281287 inline = False )
282288 create_footer (embed , client )
@@ -337,7 +343,7 @@ async def fix_link(interaction: discord.Interaction, link: str):
337343 """Convert a social media link to an embed-friendly version."""
338344 lang = get_guild_lang (interaction .guild .id if interaction .guild else None )
339345 # Standard link pattern to capture all the relevant links
340- link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+)"
346+ link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+|bilibili\.com/video/[\w]+|b23\.tv/[\w]+ )"
341347 match = re .search (link_pattern , link )
342348
343349 if not match :
@@ -396,6 +402,20 @@ async def fix_link(interaction: discord.Interaction, link: str):
396402 display_text = f"YouTube • { video_id } "
397403 modified_link = f"koutube.com/watch?v={ video_id } "
398404
405+ elif 'bilibili.com' in original_link or 'b23.tv' in original_link :
406+ if 'bilibili.com' in original_link :
407+ video_id_match = re .findall (r"bilibili\.com/video/([\w]+)" , original_link )
408+ if video_id_match :
409+ video_id = video_id_match [0 ]
410+ display_text = f"Bilibili • { video_id } "
411+ modified_link = original_link .replace ("bilibili.com" , "vxbilibili.com" )
412+ else :
413+ video_id_match = re .findall (r"b23\.tv/([\w]+)" , original_link )
414+ if video_id_match :
415+ video_id = video_id_match [0 ]
416+ display_text = f"Bilibili • { video_id } "
417+ modified_link = original_link .replace ("b23.tv" , "vxb23.tv" )
418+
399419 if display_text and modified_link :
400420 await interaction .response .send_message (f"[{ display_text } ](https://{ modified_link } )" )
401421 else :
@@ -408,7 +428,7 @@ async def fix_embed_context(interaction: discord.Interaction, message: discord.M
408428 """Convert social media links in a message to embed-friendly versions."""
409429 lang = get_guild_lang (interaction .guild .id if interaction .guild else None )
410430 # Standard link pattern to capture all the relevant links
411- link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+)"
431+ link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+|bilibili\.com/video/[\w]+|b23\.tv/[\w]+ )"
412432 matches = re .findall (link_pattern , message .content )
413433
414434 if not matches :
@@ -469,6 +489,20 @@ async def fix_embed_context(interaction: discord.Interaction, message: discord.M
469489 display_text = f"YouTube • { video_id } "
470490 modified_link = f"koutube.com/watch?v={ video_id } "
471491
492+ elif 'bilibili.com' in original_link or 'b23.tv' in original_link :
493+ if 'bilibili.com' in original_link :
494+ video_id_match = re .findall (r"bilibili\.com/video/([\w]+)" , original_link )
495+ if video_id_match :
496+ video_id = video_id_match [0 ]
497+ display_text = f"Bilibili • { video_id } "
498+ modified_link = original_link .replace ("bilibili.com" , "vxbilibili.com" )
499+ else :
500+ video_id_match = re .findall (r"b23\.tv/([\w]+)" , original_link )
501+ if video_id_match :
502+ video_id = video_id_match [0 ]
503+ display_text = f"Bilibili • { video_id } "
504+ modified_link = original_link .replace ("b23.tv" , "vxb23.tv" )
505+
472506 if display_text and modified_link :
473507 fixed_links .append (f"[{ display_text } ](https://{ modified_link } )" )
474508
@@ -608,10 +642,10 @@ async def callback(self, interaction: discord.Interaction):
608642 view = MentionUsersSettingsView (mention_users , self .interaction , self .settings )
609643 await interaction .response .send_message (embed = embed , view = view , ephemeral = True )
610644 elif self .values [0 ] == "Service Settings" :
611- enabled_services = self .settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ])
645+ enabled_services = self .settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ])
612646 service_status_list = "\n " .join ([
613647 f"{ '🟢' if service in enabled_services else '🔴' } { service } "
614- for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ]
648+ for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ]
615649 ])
616650 embed = discord .Embed (
617651 title = get_text (lang , "service_settings" ),
@@ -639,13 +673,13 @@ def __init__(self, interaction, parent_view, settings):
639673 self .interaction = interaction
640674 self .parent_view = parent_view
641675 self .settings = settings
642- enabled_services = settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ])
676+ enabled_services = settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ])
643677 options = [
644678 discord .SelectOption (
645679 label = service ,
646680 description = f"Activate or deactivate { service } links" ,
647681 emoji = "✅" if service in enabled_services else "❌" )
648- for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ]
682+ for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ]
649683 ]
650684 super ().__init__ (placeholder = "Select services to activate..." ,
651685 min_values = 1 ,
@@ -665,7 +699,7 @@ async def callback(self, interaction: discord.Interaction):
665699
666700 service_status_list = "\n " .join ([
667701 f"{ '🟢' if service in selected_services else '🔴' } { service } "
668- for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ]
702+ for service in ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ]
669703 ])
670704 embed = discord .Embed (
671705 title = "Service Settings" ,
@@ -728,7 +762,7 @@ async def callback(self, interaction: discord.Interaction):
728762 await update_setting (
729763 client .db ,
730764 guild_id ,
731- self .settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ]),
765+ self .settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ]),
732766 self .settings .get ("mention_users" , True ),
733767 self .settings .get ("delete_original" , True ),
734768 selected_lang
@@ -932,7 +966,7 @@ async def on_timeout(self):
932966@client .tree .command (name = 'settings' , description = "Configure FixEmbed's settings" )
933967async def settings (interaction : discord .Interaction ):
934968 guild_id = interaction .guild .id
935- guild_settings = bot_settings .get (guild_id , {"enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ], "mention_users" : True , "delete_original" : True })
969+ guild_settings = bot_settings .get (guild_id , {"enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ], "mention_users" : True , "delete_original" : True })
936970
937971 lang = get_guild_lang (interaction .guild .id )
938972 embed = discord .Embed (title = get_text (lang , "settings_title" ),
@@ -948,22 +982,22 @@ async def on_message(message):
948982
949983 guild_id = message .guild .id
950984 guild_settings = bot_settings .get (guild_id , {
951- "enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ],
985+ "enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ],
952986 "mention_users" : True ,
953987 "delete_original" : True
954988 })
955- enabled_services = guild_settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ])
989+ enabled_services = guild_settings .get ("enabled_services" , ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ])
956990 mention_users = guild_settings .get ("mention_users" , True )
957991 delete_original = guild_settings .get ("delete_original" , True )
958992
959993 if channel_states .get (message .channel .id , True ):
960994 try :
961995 # Standard link pattern to capture all the relevant links
962- link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+)"
996+ link_pattern = r"https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+|bilibili\.com/video/[\w]+|b23\.tv/[\w]+ )"
963997 matches = re .findall (link_pattern , message .content )
964998
965999 # Regex pattern to detect links surrounded by < >
966- surrounded_link_pattern = r"<https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+)>"
1000+ surrounded_link_pattern = r"<https?://(?:www\.)?(twitter\.com/\w+/status/\d+|x\.com/\w+/status/\d+|instagram\.com/(?:p|reel)/[\w-]+|reddit\.com/r/\w+/s/\w+|reddit\.com/r/\w+/comments/\w+/\w+|old\.reddit\.com/r/\w+/comments/\w+/\w+|pixiv\.net/(?:en/)?artworks/\d+|threads\.net/@[^/]+/post/[\w-]+|bsky\.app/profile/[^/]+/post/[\w-]+|youtube\.com/watch\?v=[\w-]+|youtu\.be/[\w-]+|bilibili\.com/video/[\w]+|b23\.tv/[\w]+ )>"
9671001
9681002 valid_link_found = False
9691003
@@ -1036,6 +1070,23 @@ async def on_message(message):
10361070 modified_link = f"koutube.com/watch?v={ video_id } "
10371071 display_text = f"YouTube • { video_id } "
10381072
1073+ elif 'bilibili.com' in original_link or 'b23.tv' in original_link :
1074+ service = "Bilibili"
1075+ if 'bilibili.com' in original_link :
1076+ video_id_match = re .findall (r"bilibili\.com/video/([\w]+)" , original_link )
1077+ if video_id_match :
1078+ video_id = video_id_match [0 ]
1079+ user_or_community = video_id
1080+ modified_link = original_link .replace ("bilibili.com" , "vxbilibili.com" )
1081+ display_text = f"Bilibili • { video_id } "
1082+ elif 'b23.tv' in original_link :
1083+ video_id_match = re .findall (r"b23\.tv/([\w]+)" , original_link )
1084+ if video_id_match :
1085+ video_id = video_id_match [0 ]
1086+ user_or_community = video_id
1087+ modified_link = original_link .replace ("b23.tv" , "vxb23.tv" )
1088+ display_text = f"Bilibili • { video_id } "
1089+
10391090 if service and user_or_community and service in enabled_services :
10401091 if not display_text :
10411092 display_text = f"{ service } • { user_or_community } "
@@ -1048,7 +1099,9 @@ async def on_message(message):
10481099 .replace ("pixiv.net" , "phixiv.net" )\
10491100 .replace ("bsky.app" , "bskyx.app" )\
10501101 .replace ("youtube.com" , "koutube.com" )\
1051- .replace ("youtu.be" , "koutube.com/watch?v=" )
1102+ .replace ("youtu.be" , "koutube.com/watch?v=" )\
1103+ .replace ("bilibili.com" , "vxbilibili.com" )\
1104+ .replace ("b23.tv" , "vxb23.tv" )
10521105 valid_link_found = True
10531106
10541107 if valid_link_found :
@@ -1081,7 +1134,7 @@ async def on_guild_join(guild):
10811134 guild_id = guild .id
10821135 if guild_id not in bot_settings :
10831136 bot_settings [guild_id ] = {
1084- "enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" ],
1137+ "enabled_services" : ["Twitter" , "Instagram" , "Reddit" , "Threads" , "Pixiv" , "Bluesky" , "YouTube" , "Bilibili" ],
10851138 "mention_users" : True ,
10861139 "delete_original" : True ,
10871140 "language" : "en"
@@ -1092,3 +1145,4 @@ async def on_guild_join(guild):
10921145load_dotenv ()
10931146bot_token = os .getenv ('BOT_TOKEN' )
10941147client .run (bot_token )
1148+
0 commit comments