-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiMessageSpam.py
102 lines (96 loc) · 4.32 KB
/
iMessageSpam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import subprocess
from nlp import *
def runAppleScript(applescript):
arguments = [item for x in [("-e", l.strip()) for l in applescript.split('\n') if l.strip() != ''] for item in x]
proc = subprocess.Popen(["osascript"] + arguments, stdout=subprocess.PIPE)
proc.stdout.flush()
def sendList(listOfStrings: list, appleIDorPhone: str, verbose=False):
num = 0
try:
for m in listOfStrings:
# Leyla is the inspiration for this program, FYI ;)
script = '''
on run
tell application "Messages"
set iMessageService to 1st service whose service type = iMessage
set leyla to buddy "''' + appleIDorPhone + '''" of iMessageService
send "''' + m + '''" to leyla
end tell
end run'''
runAppleScript(script)
num += 1
if verbose:
print("Sent {} spam message{} to {}".format(num, '' if num == 1 else "s", appleIDorPhone))
except KeyboardInterrupt:
print("Total spam messages sent to {}: {}".format(appleIDorPhone, num))
sys.exit()
print("Total spam messages sent to {}: {}".format(appleIDorPhone, num))
if __name__ == "__main__":
HELP = """OPTIONS:
-v (verbose) prints a tally of spam messages sent
-c <number> specify a set number of messages to send
--bible sends spam from the Word of God
--random random crap spam
-w --from-file <text file> send each word in the specified file
-s --from-file <text file> send each sentence in the file
-l --from-file <text file> send each line in the file"""
import sys
import random
import string
args = sys.argv
try:
spam = [arg for arg in args if arg.startswith("--")][0]
except IndexError:
print("\n" + HELP + "\n")
sys.exit()
if len(args) == 1:
print("\n" + HELP + "\n")
elif len(args) == 2:
print("\n" + HELP + "\n")
elif len(args) >= 3:
appleID = args[-1]
for x in appleID:
if x not in string.digits:
if '@' not in appleID:
sys.exit("error: Invalid AppleID or Phone number: {}".format(appleID))
try:
flags = [x for x in args if x.startswith("-") and not x.startswith("--") if len(x) > 2][0]
except IndexError:
flags = []
verbose = True if ("-v" in args) or ("v" in flags) else False
try:
numberOfSpams = int(args[args.index("-c") + 1]) if "-c" in args else int(args[args.index(flags) + 1]) if "c" in flags else False
except ValueError:
sys.exit("error: -c called but no number specified")
if spam == "--bible":
if numberOfSpams:
sendList(getVerses("theBible.txt")[:numberOfSpams], appleID, verbose=verbose)
else:
sendList(getVerses("theBible.txt"), appleID, verbose=verbose)
elif spam == "--random":
if not numberOfSpams:
numberOfSpams = random.randint(1, 1000)
messages = []
for _ in range(numberOfSpams):
message = ''
for __ in range(random.randint(10, 300)):
message += random.choice(list("\n" + string.ascii_letters + " "))
messages.append(message)
sendList(messages, appleID, verbose=verbose)
elif spam == "--from-file":
file = args[args.index("--from-file") + 1]
if "-w" in args or "w" in flags:
if numberOfSpams:
sendList(getWords(file)[:numberOfSpams], appleID, verbose=verbose)
else:
sendList(getWords(file), appleID, verbose=verbose)
elif "-s" in args or "s" in flags:
if numberOfSpams:
sendList(getSentences(file)[:numberOfSpams], appleID, verbose=verbose)
else:
sendList(getSentences(file), appleID, verbose=verbose)
elif "-l" in args or "l" in flags:
if numberOfSpams:
sendList(getLines(file)[:numberOfSpams], appleID, verbose=verbose)
else:
sendList(getLines(file), appleID, verbose=verbose)