-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclippy.py
219 lines (196 loc) · 5.94 KB
/
clippy.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""
Prints you a clippy using the input text you give it
"""
import sys
import math
import subprocess
import random
import signal
import os
import MEMES
message_list = sys.argv[1:]
length_of_input = sum(len(x) + 1 for x in message_list)
max_length = 204 #70 - width of clippy and bubble * 4
nope = [r"""
< NOPE >
------
\
\
__
/ \
| |
@ @
| |
|| |/
|| ||
|\_/|
\___/ """,
r"""
__________
< NICE TRY >
----------
\
\
__
/ \
| |
@ @
| |
|| |/
|| ||
|\_/|
\___/"""
]
angry_clippy = r"""
_.-;:q=._
.' j=""^k;:\.
; .F ";`Y
,;.J_ ;'j
,-;"^7F : .F _________________
,-'-_<. ;gj. _.,---""'' .'
; _,._`\. : `T"5, ;
: `?8w7 `J ,-'" -^q. ` ; Y O U
\;._ _,=' ; n58L Y. .'
F;"; .' k_ `^' j' ; H A V E
J;:: ; "y:-=' ;
L;;== |:; jT\ ; B E E N
L;:;J J:L 7:;' _ ;
I;|:.L |:k J:.' , ' . ; W A R N E D
|;J:.| ;.I F.: . :
;J;:L:: |.| |.J , ' ` ; ;
.' J:`J.`. :.J |. L . ; ;
; L :k:`._ ,',j J; | ` , ; ;
.' I :`=.:."_".' L J `.' DO NOT TRY TO EXIT AGAIN
.' |.: `"-=-' |.J ;
_.-' `: : ;:; _ ;
_.-'" J: : /.;' ; ;
='_ k;.. _.;:Y' , .' "---..__Y;."-=';:=' , .' ""
"""
clippy = r"""
____
/ \
| |
0 0
|| ||
|| ||
|\_ /|
\____/
"""
end_box = r"""
\
|
|
|
|
|
/
"""
first_box = r"""
/
|
|
<--|
|
|
\_
"""
# NAUGHTY NAUGHTY.
restrictedCommands = ["reboot", "shutdown", "fuck", "suck", "you", "rm"]
def process_Command(command):
if (command.find("cd") != -1):
result = os.chdir(command[1])
return result
for restrictedCommand in restrictedCommands:
if (command.find(restrictedCommand) != -1):
print(angry_clippy)
return 1
command_List = command.split()
print(command_List)
result = subprocess.call(command_List, shell = True)
print(result)
return result
def print_Clippy(message):
global clippy
global first_box
global end_box
clippyList = clippy.split("\n")
first_boxList = first_box.split("\n")
end_boxList = end_box.split("\n")
length_of_line = 0
words_per_line = 30
message_list = message.split()
#so there is enough space
#print words_per_line, length_of_line
usedwords = 0
for line in xrange(len(first_boxList)):
if ((line != len(first_boxList)-2 and line >= 3) ):
tempstr = 0
current_words = 0
while ((usedwords < len(message_list) and current_words < words_per_line)):
this_word = message_list[usedwords]
#output.append((length_of_line - len(this_word) ) * " ")
current_words += 1
usedwords +=1
tempstr += (len(this_word)+1)
if tempstr > length_of_line:
length_of_line = tempstr
for line in xrange(len(first_boxList)):
if (line == 1) or (line == len(first_boxList)-2):
spacer = "_"
else:
spacer = " "
#Prints spacing, to prevent the text from appearing at the top.
if (line < len(first_boxList)/3) or (line == len(first_boxList)-2):
s = clippyList[line] + " " + first_boxList[line] + ((length_of_line * spacer) + end_boxList[line])
print s
#Prints words
elif line >= len(first_boxList)/3:
output = []
output.append(clippyList[line] + " ")
output.append(first_boxList[line])
current_words = 0
tempstr = 0
while (current_words < words_per_line) and (len(message_list) > 0):
this_word = (message_list).pop(0)
output.append(this_word + " ")
#output.append((length_of_line - len(this_word) ) * " ")
current_words += 1
tempstr += len(this_word)+1
output.append((length_of_line - tempstr) * " ")
output.append(end_boxList[line])
print "".join(output)
def generate_Text(command):
command_List = command.split()
random.seed()
commandResult = "RESULT IS AN ERROR."
rand_Int = random.randint(0, len(command_List)-1)
pregenerated_Text = ["Unable to find command.", command_List[rand_Int] + " is not a real word.", \
"Would you like me to do this?", "This quite ineffective", \
"You have mispelled " + command_List[rand_Int], \
"Happily processing your command!", "Thank you, sir", \
"The following are the result of your command:\n" + commandResult, \
"ERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERRORERROR"]
random.seed()
rand_Int = random.randint(0, len(pregenerated_Text)-1)
text = pregenerated_Text[rand_Int]
return text
def trigger_warning(signal, frame):
global angry_clippy
print(angry_clippy)
return
def TRIGGERED(signal, frame):
global nope
print(nope[random.randint(0,len(nope)-1)])
return
def main():
#Welcome message
print_Clippy("Hello, I'm Clippy, everyone's favorite personal assistant!")
while 1:
command = raw_input(">")
process_Command(command)
message = generate_Text(command)
print_Clippy(message)
if __name__ == "__main__":
signal.signal(signal.SIGINT, trigger_warning)
signal.signal(signal.SIGTSTP, TRIGGERED)
main()