Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
diff
Browse files
app.py
CHANGED
@@ -17,6 +17,7 @@ from pytz import timezone # for times
|
|
17 |
import asyncio # check if used
|
18 |
import logging
|
19 |
import urllib.parse
|
|
|
20 |
|
21 |
|
22 |
from discord.ui import Button, View
|
@@ -60,6 +61,12 @@ def extract_tenor_gif_url(content):
|
|
60 |
return None
|
61 |
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
@bot.event
|
65 |
async def on_message(message):
|
@@ -216,10 +223,17 @@ async def on_message_edit(before, after):
|
|
216 |
return
|
217 |
|
218 |
if before.content != after.content:
|
|
|
|
|
|
|
219 |
embed = Embed(color=Color.orange())
|
220 |
embed.set_author(name=f"{before.author} ID: {before.author.id}", icon_url=before.author.avatar.url if before.author.avatar else bot.user.avatar.url)
|
221 |
embed.title = "Message Edited"
|
222 |
-
embed.description = f"**Before:** {before.content or '*(empty message)*'}\n**After:** {after.content or '*(empty message)*'}"
|
|
|
|
|
|
|
|
|
223 |
embed.add_field(name="Author Username", value=before.author.name, inline=True)
|
224 |
embed.add_field(name="Channel", value=before.channel.mention, inline=True)
|
225 |
#embed.add_field(name="Message Created On", value=before.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True)
|
@@ -232,6 +246,7 @@ async def on_message_edit(before, after):
|
|
232 |
#embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
|
233 |
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
234 |
await bot.log_channel.send(embed=embed)
|
|
|
235 |
|
236 |
except Exception as e:
|
237 |
print(f"on_message_edit Error: {e}")
|
|
|
17 |
import asyncio # check if used
|
18 |
import logging
|
19 |
import urllib.parse
|
20 |
+
from difflib import ndiff
|
21 |
|
22 |
|
23 |
from discord.ui import Button, View
|
|
|
61 |
return None
|
62 |
|
63 |
|
64 |
+
def generate_diff(before, after):
|
65 |
+
# Only show changed lines
|
66 |
+
diff_lines = list(ndiff([before], [after]))
|
67 |
+
return "```diff\n" + "\n".join(diff_lines) + "\n```"
|
68 |
+
|
69 |
+
|
70 |
|
71 |
@bot.event
|
72 |
async def on_message(message):
|
|
|
223 |
return
|
224 |
|
225 |
if before.content != after.content:
|
226 |
+
diff_text = generate_diff(before.content or "", after.content or "")
|
227 |
+
diff_msg = await bot.log_channel.send(diff_text) # Step 3: this shows colors
|
228 |
+
|
229 |
embed = Embed(color=Color.orange())
|
230 |
embed.set_author(name=f"{before.author} ID: {before.author.id}", icon_url=before.author.avatar.url if before.author.avatar else bot.user.avatar.url)
|
231 |
embed.title = "Message Edited"
|
232 |
+
#embed.description = f"**Before:** {before.content or '*(empty message)*'}\n**After:** {after.content or '*(empty message)*'}"
|
233 |
+
embed.description = "See diff below:"
|
234 |
+
embed.add_field(name="Diff Reference", value=f"[Jump to diff]({diff_msg.jump_url})", inline=False)
|
235 |
+
|
236 |
+
|
237 |
embed.add_field(name="Author Username", value=before.author.name, inline=True)
|
238 |
embed.add_field(name="Channel", value=before.channel.mention, inline=True)
|
239 |
#embed.add_field(name="Message Created On", value=before.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True)
|
|
|
246 |
#embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
|
247 |
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
248 |
await bot.log_channel.send(embed=embed)
|
249 |
+
|
250 |
|
251 |
except Exception as e:
|
252 |
print(f"on_message_edit Error: {e}")
|