@@ -261,49 +261,6 @@ async def specs(self, ctx):
261261 "thumbnail" : os_logos [os_name .lower ()]
262262 })
263263
264- @commands .command (name = "sessionspoofer" , description = "Spoof your session" , usage = "[device]" , aliases = ["sessionspoof" , "spoofsession" ])
265- async def sessionspoofer (self , ctx , device = None ):
266- cfg = self .cfg
267- devices = ["mobile" , "desktop" , "web" , "embedded" ]
268- spoofing , spoofing_device = cfg .get_session_spoofing ()
269-
270- if not spoofing :
271- await cmdhelper .send_message (ctx , {
272- "title" : "Session Spoofing" ,
273- "description" : "Session spoofing is not enabled. Enable it in the config." ,
274- "colour" : "#ff0000"
275- })
276- return
277-
278- if device not in devices :
279- await cmdhelper .send_message (ctx , {
280- "title" : "Session Spoofing" ,
281- "description" : f"Invalid device. Options: { ', ' .join (devices )} " ,
282- "colour" : "#ff0000"
283- })
284- return
285-
286- if device is None :
287- cfg .set_session_spoofing (not spoofing , spoofing_device )
288-
289- await cmdhelper .send_message (ctx , {
290- "title" : "Session Spoofing" ,
291- "description" : f"Session spoofing is now { 'enabled' if not spoofing else 'disabled' } \n Restarting to apply changes..." ,
292- "colour" : "#00ff00" if not spoofing else "#ff0000"
293- })
294-
295- else :
296- cfg .set_session_spoofing (spoofing , device )
297-
298- await cmdhelper .send_message (ctx , {
299- "title" : "Session Spoofing" ,
300- "description" : f"Session spoofing is now enabled as { device } \n Restarting to apply changes..." ,
301- "colour" : "#00ff00"
302- })
303-
304- cfg .save ()
305- await self .restart (ctx , no_response = True )
306-
307264 @commands .command (name = "uptime" , description = "View the bot's uptime" , usage = "" )
308265 async def uptime (self , ctx ):
309266 uptime = time .time () - self .bot .start_time
@@ -345,126 +302,5 @@ async def commandhistory(self, ctx):
345302 description = description
346303 ), delete_after = cfg .get ("message_settings" )["auto_delete_delay" ])
347304
348- @commands .command (name = "spypet" , description = "Get a list of every message a member has sent in mutual servers." , usage = "[member]" )
349- async def spypet (self , ctx , member_id : int ):
350- mutual_guilds = [guild for guild in self .bot .guilds if guild .get_member (member_id )]
351- data = {}
352- tasks = []
353- sem = asyncio .Semaphore (15 )
354- stop_event = asyncio .Event ()
355- last_saved_count = 0
356-
357- def _count_messages ():
358- return sum (len (channels ) for guilds in data .values () for channels in guilds .values ())
359-
360- def _save_data ():
361- nonlocal last_saved_count
362- current_count = _count_messages ()
363- if current_count == last_saved_count :
364- return
365- last_saved_count = current_count
366- with open (files .get_application_support () + "/data/spypet.json" , "w" ) as f :
367- json .dump (data , f , indent = 4 )
368- console .print_info (f"Auto-saved { current_count } messages." )
369-
370- async def _autosave (interval = 5 ):
371- while not stop_event .is_set ():
372- await asyncio .sleep (interval )
373- _save_data ()
374-
375- console .print_info ("Auto-saving stopped. Spypet complete!" )
376-
377- def _add_message (guild , channel , message ):
378- if guild .name not in data : data [guild .name ] = {}
379- if channel .name not in data [guild .name ]: data [guild .name ][channel .name ] = []
380-
381- data [guild .name ][channel .name ].append (message )
382- # _save_data()
383-
384- def _get_permissions (channel ):
385- member = channel .guild .get_member (member_id )
386- member_role = member .top_role
387- bot_role = channel .guild .me .top_role
388-
389- return (channel .permissions_for (member ).read_messages and
390- channel .permissions_for (channel .guild .me ).read_messages or
391- channel .overwrites_for (member_role ).read_messages and
392- channel .overwrites_for (bot_role ).read_messages )
393-
394-
395- async def _fetch_context_channel (channel ):
396- if channel .id == ctx .channel .id :
397- return ctx .channel
398- try :
399- latest_msg = [msg async for msg in channel .history (limit = 1 )][0 ]
400- context = await self .bot .get_context (latest_msg )
401-
402- return context .channel
403- except Exception as e :
404- if "429" in str (e ):
405- await asyncio .sleep (5 )
406- return await _fetch_context_channel (channel )
407-
408- return None
409-
410- async def _get_messages (channel , delay = 0.25 ):
411- async with sem :
412- try :
413- await asyncio .sleep (delay )
414- console .print_info (f"Finding messages in { channel .guild .name } - { channel .name } " )
415-
416- channel = await _fetch_context_channel (channel ) or channel
417- guild = channel .guild
418- messages = []
419-
420- try :
421- async for msg in channel .history (limit = 999999999 , oldest_first = False ):
422- if msg .author .id == member_id :
423- if len (msg .attachments ) > 0 :
424- attachments = "\n " .join ([f"Attachment: { attachment .url } " for attachment in msg .attachments ])
425- msg_string = f"[{ msg .created_at .strftime ('%Y-%m-%d %H:%M:%S' )} ] { msg .content } \n { attachments } "
426- else :
427- msg_string = f"[{ msg .created_at .strftime ('%Y-%m-%d %H:%M:%S' )} ] { msg .content } "
428- messages .append (msg_string )
429- _add_message (guild , channel , msg_string )
430-
431- if len (messages ) > 0 :
432- console .print_success (f"Found messages in { channel .guild .name } - { channel .name } " )
433- else :
434- console .print_error (f"Found no messages in { channel .guild .name } - { channel .name } " )
435- except :
436- console .print_error (f"Failed to fetch messages in { channel .guild .name } - { channel .name } " )
437-
438- _save_data ()
439- except asyncio .CancelledError :
440- console .print_warning ("Process was cancelled! Saving progress..." )
441- stop_event .set ()
442- _save_data ()
443- raise
444- except Exception as e :
445- console .print_error (f"Error in { channel .guild .name } - { channel .name } : { e } " )
446- finally :
447- _save_data ()
448-
449- delay = 0.5
450- autosave_task = asyncio .create_task (_autosave (5 ))
451-
452- for guild in mutual_guilds :
453- for channel in guild .text_channels :
454- if _get_permissions (channel ):
455- tasks .append (asyncio .create_task (_get_messages (channel , delay )))
456- delay += 0.5
457-
458- await asyncio .gather (* tasks )
459- stop_event .set ()
460- await autosave_task
461- _save_data ()
462-
463- console .print_success ("Spypet complete! Data saved to data/spypet.json." )
464- console .print_info (f"Total messages: { _count_messages ()} " )
465- console .print_info (f"Total guilds: { len (data )} " )
466- console .print_info (f"Total channels: { sum (len (channels ) for channels in data .values ())} " )
467- await ctx .send (file = discord .File ("data/spypet.json" ), delete_after = self .cfg .get ("message_settings" )["auto_delete_delay" ])
468-
469305def setup (bot ):
470306 bot .add_cog (Util (bot ))
0 commit comments