This repository was archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgcheck.py
45 lines (34 loc) · 1.49 KB
/
msgcheck.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
def msgchecker(msg):
command = msg[0].lower()
args = msg[1:]
response = 'Invalid command'
if command == 'hello':
response = 'World!'
if command == 'repeat':
response = ' '.join(args)
if command == 'challenge':
if args[0] == 'add':
chal = ' '.join(args[1:-1])
flag = str(args[-1])
if flag[:7] == 'pieCTF{' and flag[-1] == '}':
with open('chal.txt' ,'a') as chalfile:
chalfile.write('Challenge: ' + chal + ' ' + flag + '\n')
response = 'Hurray\nNew challenge added.'
else:
response = 'Sorry, the challenge is not added.\nIt must be in the form \"!challenge add challenge_statement flag\" \nand the flag must be in form pieCTF\{flag_with_no_spaces\}'
if args[0] == 'look':
line = int(args[1])-1
with open('chal.txt' ,'r') as chalfile:
challine = chalfile.readlines()[line].split()
chaltext = ' '.join(challine[1:-1])
response = f'Challenge #{line+1}: {chaltext}'
if args[0] == 'submit':
line = int(args[1])-1
with open('chal.txt' ,'r') as chalfile:
challine = chalfile.readlines()[line].split()
flag = challine[-1]
if args[2] == flag:
response = 'Wow! You are right!'
else:
response = 'Sorry! Try again!'
return response