Last active
March 8, 2025 18:55
-
-
Save martinellimarco/2774c4df1344986004f9ae74a3bdcc20 to your computer and use it in GitHub Desktop.
Script to remove all your messages from all chats in Skype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skpy import Skype, SkypeSingleChat, SkypeGroupChat | |
import time | |
import getpass | |
import argparse | |
import sys | |
def delete_all_messages(username, password, skip_confirmation=False): | |
try: | |
# Login to Skype | |
print("Logging in to Skype...") | |
sk = Skype(username, password) | |
print("Login successful!") | |
chat_count = 0 | |
processed_chat_ids = set() | |
# Outer loop to exhaust all chats by repeatedly calling recent() | |
while True: | |
# Get next batch of chats | |
print(f"Retrieving batch of chats (already processed {chat_count} chats)...") | |
new_chats = sk.chats.recent() | |
# Filter out already processed chats | |
unprocessed_chats = {chat_id: chat for chat_id, chat in new_chats.items() | |
if chat_id not in processed_chat_ids} | |
if not unprocessed_chats: | |
print("No more chats to process.") | |
break | |
print(f"Found {len(unprocessed_chats)} new chats in this batch.") | |
# Process each chat in the batch | |
for chat_id, chat in unprocessed_chats.items(): | |
chat_count += 1 | |
processed_chat_ids.add(chat_id) | |
# Get chat name safely | |
if isinstance(chat, SkypeGroupChat) and hasattr(chat, 'topic'): | |
chat_name = chat.topic or 'Unnamed group chat' | |
elif isinstance(chat, SkypeSingleChat) and hasattr(chat, 'user'): | |
chat_name = getattr(chat.user, 'name', 'Unknown contact') | |
else: | |
chat_name = f"Chat {chat_id}" | |
print(f"Processing chat {chat_count}: {chat_name}") | |
message_count = 0 | |
deleted_count = 0 | |
# Inner loop to exhaust all messages in this chat | |
while True: | |
try: | |
# Get next batch of messages | |
messages = list(chat.getMsgs()) | |
if not messages: | |
print(f" No more messages in this chat.") | |
break | |
print(f" Found {len(messages)} more messages.") | |
# Delete each message in this batch | |
for msg in messages: | |
message_count += 1 | |
try: | |
# Check if message belongs to the user | |
if msg.content == '': | |
print(f" Message already removed "+msg.id) | |
elif msg.userId == sk.userId: | |
print(f" Deleting message {message_count} "+msg.id+" "+msg.type) | |
msg.delete() | |
deleted_count += 1 | |
# Sleep to avoid rate limiting | |
time.sleep(0.55) | |
except Exception as e: | |
error_message = str(e) | |
print(f" Error deleting message: {error_message}") | |
if "Rate limit exceeded" in error_message: | |
print("Rate limit hit, sleeping for 10 minutes...") | |
time.sleep(600) | |
continue | |
except Exception as e: | |
print(f" Error retrieving messages for chat: {str(e)}") | |
break | |
print(f"Completed chat {chat_count}: {chat_name}") | |
print(f"Processed {message_count} messages, deleted {deleted_count} messages.") | |
print(f"All done! Processed {chat_count} chats in total.") | |
except Exception as e: | |
print(f"Error: {str(e)}") | |
def print_usage(): | |
print("Usage: python delete_skype_messages.py [options]") | |
print("Options:") | |
print(" --username, -u Your Skype username/email") | |
print(" --password, -p Your Skype password") | |
print(" --confirm, -c Skip confirmation prompt") | |
print("\nExamples:") | |
print(" python delete_skype_messages.py -u [email protected] -p your_password -c") | |
print(" python delete_skype_messages.py --username [email protected]") | |
def main(): | |
parser = argparse.ArgumentParser(description='Delete all your messages from Skype chats') | |
parser.add_argument('--username', '-u', type=str, help='Your Skype username/email') | |
parser.add_argument('--password', '-p', type=str, help='Your Skype password') | |
parser.add_argument('--confirm', '-c', action='store_true', help='Skip confirmation prompt') | |
args = parser.parse_args() | |
# Print warning and usage if no arguments | |
if len(sys.argv) == 1: | |
print("WARNING: This script will delete ALL of your messages from ALL of your Skype chats.") | |
print("This action CANNOT be undone. Make sure you have backed up any important messages.\n") | |
print_usage() | |
print("\nPress Enter to continue with interactive prompts or Ctrl+C to exit.") | |
input() | |
# Get username if not provided | |
if not args.username: | |
args.username = input("Enter your Skype username/email: ") | |
# Get password if not provided | |
if not args.password: | |
args.password = getpass.getpass("Enter your Skype password: ") | |
# Check for confirmation | |
if not args.confirm: | |
print("WARNING: This script will delete ALL of your messages from ALL of your Skype chats.") | |
print("This action CANNOT be undone. Make sure you have backed up any important messages.") | |
confirmation = input("Type 'DELETE ALL MY MESSAGES' to confirm: ") | |
if confirmation != "DELETE ALL MY MESSAGES": | |
print("Operation cancelled.") | |
return | |
delete_all_messages(args.username, args.password, args.confirm) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment