@TacoCode/

working funstuff backup 2 feb-1

Python

No description

fork
loading
Files
  • main.py
  • decode.py
  • encode.py
  • ghosthouse.py
  • loginsys.py
  • main.log
  • meaningoflife.py
  • pswds.txt
  • requirements.txt
  • says.py
  • users.txt
main.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/python3
# -*- coding: UTF-8 -*-

__version__ = "this one"
__author__ = "TACO!"

import logging
logging.basicConfig(level=logging.DEBUG,
		format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
		datefmt='%d-%m %H:%M',
		filename='main.log',
		filemode='w')
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('')

logging.info('Importing modules')
import sys
import cmd
import time
import linecache
import os
import random

logging.info('Importing local modules')
import says
import decode
import encode
import meaningoflife
import ghosthouse
logging.info('Imports done\n')

logging.info('Setting variables')
user = "admin"
os.path.abspath(sys.path[0])
userfile = os.path.join(os.path.abspath(sys.path[0]), "users.txt")
passfile = os.path.join(os.path.abspath(sys.path[0]), "pswds.txt")
clear = lambda: os.system('cls' if os.name=='nt' else 'clear')
clear()
logging.info('Variables done\n')

logging.info('Definitions')
#Gets a line in a file
def getline(filename, userbv):
	with open(filename) as myFile:
		for num, line in enumerate(myFile, 1):
			if userbv in line:
				return num
logging.info('Definitions done\n')




#Main launcher
class funstuff(cmd.Cmd):
	intro = "\u001b[0m" + "Welcome to this thing that i have made. Type 'help' to see available commands, or type 'clear' to remove this message"

	prompt = "\x1b[32m"+"{0}@funstuff".format(user) + "\u001b[0m" + ":" + "\x1b[36m" + "~" + "\u001b[0m" + "$ "

 # v Clear v -----

	def do_clear(self, arg):
		if len(arg) != 0:
			print("***Invalid number of arguments. (There shouldn't be any)")
		else:
			clear()

	def help_clear(self):
		print(" ")
		print("Clears the console")
		print("Usage: 'clear'")
		print(" ")

 # v Cowsays v ----- ^ Clear ^

	def do_cowsays(self, arg):
		l = arg.split()
		sentence = " ".join(l[0:])

		if not len(l) >= 1:
			print("***Invalid number of arguments. (Should be more than, or one)")
		else:
			says.cow(sentence)
			print(" ")

	def help_cowsays(self):
		print("Makes a stupid cow say something.")
		print("Usage: 'cowsays <something>")

 # v Dice v ----- ^ Cowsays ^

	def do_dice(self, arg):
		arg =	arg.split()
		if len(arg) != 1:
			print("***Invalid number of arguments. (Should be one, whole number)")
			return
		try:
			arg = arg[0]
			arg = round(int(arg),0)
		except:
			print("***Argument must be a whole number")
			return
		else:
			print("\nRolling...")
			time.sleep(5)
			print("You got " + str(random.randint(1, arg))+ "!\n")

	def help_dice(self):
		print("Rolls a dice with the amount of sides that you select")
		print("Usage: 'dice <sides>'")

 # v Decode v ----- ^ Dice ^

	def do_encode(self, arg):
		arg = arg.split()
		if len(arg) < 2:
			print("***Invalid number of arguments. (Should be two or more.)")
		else:
			try:
				secret = arg[0]
				string = arg[1:]
				secret = round(int(secret), 0)
			except:
				print("First arg should be a whole number")
				return
			encode.strencode(string, secret)

	def help_encode(self):
		print("Encodes a string using the caesar method")
		print("Usage: encode <secret> <string:>")

 # v Encode v ----- ^ Decode ^

	def do_decode(self, arg):
		arg = arg.split()
		if len(arg) < 2:
			print("***Invalid number of arguments. (Should be two or more.)")
		else:
			try:
				secret = arg[0]
				string = arg[1:]
				secret = round(int(secret), 0)
			except:
				print("First arg should be a whole number")
				return
		decode.strdecode(string, secret)

	def help_decode(self):
		print("Decodes a string using the caesar method")
		print("Usage: encode <secret> <string:>")

 # v Chickensays v ----- ^ Encode ^

	def do_chickensays(self, arg):
		l = arg.split()
		sentence = " ".join(l[0:])

		if not len(l) >= 1:
			print("***Invalid number of arguments. (Should be more than, or one)")
		else:
			says.chicken(sentence)
			print(" ")

	def help_chickensays(self):
		print("Makes a stupid chicken say something.")
		print("Usage: 'chickensays <something>")

 # v Stop v ----- ^ Chickensays ^

	def do_stop(self, args):
		return True

	def help_stop(self):
		print("Stops the interpeter")
		print("Usage: 'stop'")

 # v Meaning of life v ----- ^ Stop ^

	def do_meaningoflife(self, args):
		meaningoflife.run()

	def help_meaningoflife(self):
		print("Calculates the meaning oof life")
		print("Usage: 'meaningoflife'")

 # v Debug v ----- ^ Meaning of life ^

	def do_debug(self, args):
		print("Python version: " + sys.version)
		print("Script position: " + str(sys.argv[0]))
		print("Arguments: " + str(sys.argv[1:]))

	def help_debug(self):
		print("Shows debug info")
		print("Usage: 'debug'")

 # v Game launcher v ----- ^ Debug ^

	def do_games(self, args):
		l = args.split()
		if l[0] == "-i":
			clear()
			games().cmdloop()
		else:
			print("Starting", end='')
			for i in range(5):
				sys.stdout.write(".")
				sys.stdout.flush()
				time.sleep(1)
			clear()
			games().cmdloop()

	def help_games(self):
		print("Starts the game launcher")

 # v  v ----- ^ Game launcher ^


#Games launcher
class games(cmd.Cmd):
	intro = "This is the game launcher. Type 'exit' to leave the game launcher."
	prompt = "(games) "
	doc_header = "Games"
	undoc_header = "Misc. Commands"

	def do_ghosthouse(self, args):
		ghosthouse.start()
	
	def help_ghosthouse(self):
		print("Starts the 'Ghosthouse' game")

	def do_exit(self, args):
		clear()
		return True

#Starting the main launcher
if __name__ == "__main__":
	funstuff().cmdloop()