Skip to content

Commit

Permalink
Add support for spoilers
Browse files Browse the repository at this point in the history
  • Loading branch information
greeeen-dev committed Feb 15, 2025
1 parent 782719a commit 1441548
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions revolt_bridge_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async def fetch_message(self, channel, message_id):
return await channel.fetch_message(message_id)

async def make_friendly(self, text):
# Convert emojis to a URL, if there's only one emoji in the message
if text.startswith(':') and text.endswith(':'):
try:
emoji_id = text.replace(':', '', 1)[:-1]
Expand All @@ -258,6 +259,7 @@ async def make_friendly(self, text):
except:
pass

# Convert pings to regular text
components = text.split('<@')
offset = 0
if text.startswith('<@'):
Expand All @@ -277,6 +279,7 @@ async def make_friendly(self, text):
f'<@!{userid}>', f'@{display_name or user.name}')
offset += 1

# Convert channels to regular text
components = text.split('<#')
offset = 0
if text.startswith('<#'):
Expand All @@ -300,6 +303,7 @@ async def make_friendly(self, text):
f'<#!{channelid}>', f'#{channel.name}')
offset += 1

# Convert emojis to regular text
components = text.split('<:')
offset = 0
if text.startswith('<:'):
Expand All @@ -313,6 +317,7 @@ async def make_friendly(self, text):
text = text.replace(f'<:{emojiname}:{emojiafter}', f':{emojiname}\\:')
offset += 1

# Convert animated emojis to regular text
components = text.split('<a:')
offset = 0
if text.startswith('<a:'):
Expand All @@ -326,6 +331,7 @@ async def make_friendly(self, text):
text = text.replace(f'<a:{emojiname}:{emojiafter}', f':{emojiname}\\:')
offset += 1

# Convert subtext to Revolt format
components = text.split('\n')
newlines = []
for line in components:
Expand All @@ -338,6 +344,11 @@ async def make_friendly(self, text):

text = '\n'.join(newlines)

# Convert spoilers to Discord format
components = text.split('!!')
to_replace = (len(components) - 1) - ((len(components) - 1) % 2)
text = text.replace('!!', '||', to_replace)

return text

async def to_discord_file(self, file):
Expand Down Expand Up @@ -432,6 +443,11 @@ def to_color(color):
newlines.append(line)
content = '\n'.join(newlines)

# Convert spoilers to Revolt format
components = content.split('||')
to_replace = (len(components) - 1) - ((len(components) - 1) % 2)
content = content.replace('||', '!!', to_replace)

try:
msg = await channel.send(
content,
Expand Down

0 comments on commit 1441548

Please sign in to comment.