lunarflu HF Staff commited on
Commit
57216eb
·
verified ·
1 Parent(s): 7e071fa

test log search

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py CHANGED
@@ -7,6 +7,7 @@ import json
7
  import random
8
  import time
9
  import re
 
10
  from discord import Embed, Color
11
  from discord.ext import commands, tasks
12
  from gradio_client import Client
@@ -37,6 +38,54 @@ logging.basicConfig(level=logging.DEBUG)
37
  message_cache = {}
38
 
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # twitter
41
  WATCHED_USER = 'Awk20000'
42
  CHANNEL_ID = 123456789012345678
 
7
  import random
8
  import time
9
  import re
10
+ import io
11
  from discord import Embed, Color
12
  from discord.ext import commands, tasks
13
  from gradio_client import Client
 
38
  message_cache = {}
39
 
40
 
41
+
42
+ LOG_CHANNEL_IDS = {
43
+ "posted": 1380960802990854204,
44
+ "edited": 1380960825795411978,
45
+ "deleted": 1380960864990924941,
46
+ }
47
+
48
+
49
+ # test
50
+ @bot.command()
51
+ async def search(ctx, target_id: str):
52
+ collected = []
53
+
54
+ for log_type, channel_id in LOG_CHANNEL_IDS.items():
55
+ channel = bot.get_channel(channel_id)
56
+ if not channel:
57
+ await ctx.send(f"Could not access log channel: {log_type}")
58
+ continue
59
+
60
+ async for message in channel.history(limit=1000): # adjust limit as needed
61
+ if not message.embeds:
62
+ continue
63
+
64
+ embed = message.embeds[0]
65
+ for field in embed.fields:
66
+ if field.name.startswith("ID") and target_id in field.value:
67
+ entry = {
68
+ "log_type": log_type,
69
+ "timestamp": str(embed.timestamp),
70
+ "author": embed.author.name,
71
+ "description": embed.description,
72
+ "fields": {f.name: f.value for f in embed.fields},
73
+ "jump_url": embed.url if embed.url else "N/A",
74
+ }
75
+ collected.append(entry)
76
+ break
77
+
78
+ if not collected:
79
+ await ctx.send(f"No logs found for ID `{target_id}`.")
80
+ return
81
+
82
+ # Save results to a JSON file in-memory
83
+ json_data = json.dumps(collected, indent=2)
84
+ file = discord.File(io.BytesIO(json_data.encode()), filename=f"{target_id}_logs.json")
85
+
86
+ await ctx.send(f"Found {len(collected)} logs for ID `{target_id}`:", file=file)
87
+
88
+
89
  # twitter
90
  WATCHED_USER = 'Awk20000'
91
  CHANNEL_ID = 123456789012345678