-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
kbot
executable file
·105 lines (97 loc) · 3.49 KB
/
kbot
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
#!/usr/bin/env python3
import argparse
import asyncio
import klib
import re
import sys
def nameOrID():
while "the answer is invalid":
reply = str(input("quizName or quizID? [n/i] > ")).lower().strip()
if reply[:1] == 'n':
return True
if reply[:1] == 'i':
return False
def checkID(qID):
res = re.search(r"(([a-zA-Z0-9]){8}(-([a-zA-Z0-9]){4}){3}-([a-zA-Z0-9]){12})", qID)
if not res:
print('Invalid UUID. It must take the form x8-x4-x4-x4-x12, where x8 means 8 alphanumeric characters')
exit()
return res.group(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-s', "--search",
help="Search for a quiz without joining a Kahoot. Cancels nick and pin options.",
action="store_true")
parser.add_argument('-d', "--debug", help="Output go brrrrrrrrrrrrr", action="store_true")
parser.add_argument('-e', "--email", help="The email used to login to create.kahoot.it")
parser.add_argument('-a', "--password", help="The corresponding password used to login to create.kahoot.it")
parser.add_argument('-n', "--nick", help="The nickname to join the Kahoot with")
parser.add_argument('-p', "--pin", help="The game pin")
parser.add_argument('-q', "--quizName", help="The quiz's name")
parser.add_argument('-i', "--quizID", help="The quiz's ID")
parser.add_argument('-m', "--maxCount", help="How many quizzes to look for when searching by name")
args = parser.parse_args()
email = args.email
password = args.password
nickname = args.nick
pin = args.pin
searchOnly = args.search
quizID = args.quizID
quizName = args.quizName
maxCount = args.maxCount
debug = args.debug
try:
if debug:
print("In debug mode: output will go brrrrrrrrrrrr")
else:
sys.tracebacklimit = 0
if searchOnly:
print("In searchOnly mode: kbot will not join a Kahoot")
if quizID:
user = klib.Kahoot(quizID=checkID(quizID), DEBUG=debug)
elif quizName:
if email and password:
user = klib.Kahoot(quizName=quizName, maxCount=maxCount, DEBUG=debug)
else:
print('Authentication required when searching for quizzes by name')
exit()
else:
if email and password:
if nameOrID():
user = klib.Kahoot(quizName=input('quizName > '), maxCount=maxCount, DEBUG=debug)
else:
user = klib.Kahoot(quizID=checkID(input('quizID > ')), DEBUG=debug)
else:
user = klib.Kahoot(quizID=checkID(input('quizID > ')), DEBUG=debug)
else:
if not nickname:
nickname = input('name > ')
if not pin:
pin = input('pin > ')
if quizID:
user = klib.Kahoot(pin=pin, nickname=nickname, quizID=checkID(quizID), DEBUG=debug)
elif quizName:
if email and password:
user = klib.Kahoot(pin=pin, nickname=nickname, quizName=quizName, maxCount=maxCount, DEBUG=debug)
else:
print('Authentication required when searching for quizzes by name')
exit()
else:
if email and password:
if nameOrID():
user = klib.Kahoot(pin=pin, nickname=nickname, quizName=input('quizName > '), maxCount=maxCount,
DEBUG=debug)
else:
user = klib.Kahoot(pin=pin, nickname=nickname, quizID=checkID(input('quizID > ')), DEBUG=debug)
else:
user = klib.Kahoot(pin=pin, nickname=nickname, quizID=checkID(input('quizID > ')), DEBUG=debug)
if email and password and user:
user.authenticate(email, password)
if searchOnly:
user.search()
else:
user.checkPin()
user.startGame()
except (KeyboardInterrupt, asyncio.exceptions.CancelledError):
print("\nBYE!")
exit()