@TacoCode/

Code demo

Python

No description

fork
loading
Files
  • main.py
  • deencode.py
  • games.py
  • misc.py
  • requirements.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env python

# Built in modules
import sys
import cmd
import time
import os
import random
import shlex
import urllib
import json

#Third party modules
from colored import attr, fg

#Files
import misc
import deencode
import games


def clear(): os.system('cls' if os.name == 'nt' else 'clear')

def getargs(raw_arguments): return shlex.split(raw_arguments)

googleapi_token = os.getenv("PASSWORD")

clear()


CG = fg(46)       #Consolegreen text
RS = attr(0)      #Reset all colors and attributes
CB = fg(25)       #Consoleblue text
BO = attr("bold") #Bold text
WH = fg(15)       #White text
RED = fg(9)       #Red text

#Setting up the intro without going past 
#the 79 caracter limit
raw_INTRO = f"{RS}Welcome to funstuff console! "
raw_INTRO += "Type 'help' to see available commands,"
raw_INTRO += " or type 'clear' to clear the console at any time"


# Main launcher
class funstuff(cmd.Cmd):
	intro = raw_INTRO
	prompt = f'{BO}{CG}[email protected]{WH}:{CB}~{RS}$ '

 # v Clear v -----

	def do_clear(self, arg):
		clear()
    
	def help_clear(self):
		print(" ")
		print("Clears the console")
		print("Usage: 'clear'")
		print("You can also press 'CTRL+C' to clear")
		print(" ")

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

	def do_cowsays(self, arg):
		if len(arg) == 0:
			print(f"{RED}*** Correct usage: 'cowsays \"<message>\"'{RS}")
		else:
			try:
				sentence = getargs(arg)
			except:
				print(f"{RED}*** Remember the closing quotation (\"){RS}")
				return
			misc.cowsays(sentence[0])
			print(" ")

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

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

	def do_dice(self, arg):
		arg =	arg.split()
		try:
			sides = int(arg[0])
		except IndexError:
			print(f"{RED}*** Correct usage: 'dice' <sides>{RS}")
		except ValueError:
			print(f"{RED}*** Argument 'sides' must be a whole number{RS}")
		else:
			print("\n*** Rolling...")
			time.sleep(3)
			print("*** You got " + str(random.randint(1, sides))+ "!\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, raw_args):
		try:
			args = getargs(raw_args)
		except:
			print(f"{RED}*** Remember the closing quotation '\"'{RS}")
			return
		if len(args) != 2:
			print(f"{RED}*** Correct usage: 'decode <secret> \"<message>\"{RS}")
			return
		else:
			try:
				secret = args[0]
				string = args[1]
				secret = round(int(secret), 0)
			except:
				print(f"{RED}*** First arg 'secret' should be a whole number{RS}")
				return
			deencode.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 = getargs(arg)
		if len(arg) < 2:
			print(f"{RED}*** Invalid number of arguments. (Should be two or more.){RS}")
		else:
			try:
				secret = arg[0]
				string = arg[1]
				secret = round(int(secret), 0)
			except:
				print(f"{RED}*** Correct usage: 'decode <secret> \"<message>\"'{RS}")
				return
			deencode.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):
		if len(arg) == 0:
			print(f"{RED}*** Correct usage: 'chickensays \"<message>\"'{RS}")
		else:
			try:
				sentence = getargs(arg)
			except:
				print(f"{RED}*** Remember the closing quotation (\"){RS}")
				return
			misc.chickensays(sentence[0])

			print(" ")

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

 # 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):
		misc.meaningoflife()

	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.path[0])+"/"+__file__)
		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):
		print("Starting", end='')
		for i in range(5):
			sys.stdout.write(".")
			sys.stdout.flush()
			time.sleep(1)
		clear()
		try:
			gamelauncher().cmdloop()
		except:
			return

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

 # v Random droplocation v ----- ^ Game launcher ^

	def do_randomdrop(self, args):
		misc.droplocation()

	def help_randomdrop(self):
		print("Gives you a random drop location in Fortnite battle royale")

 # v Ping v ----- ^ Random droplocation ^
  
	def do_ping(self, raw_args):
		args = getargs(raw_args)
		try:
			SITE = args[0]
		except:
			print(f"{RED}*** Correct usage: 'ping <website>'\n{RS}")
			return
		print(f"*** Pinging {SITE}. Press 'CTRL+C' to exit")
		os.system(f'ping {SITE}')

	def help_ping(self):
		print("*** Pings a website '<site>'")
		print("*** Usage: ping '<site>'")

 # v Shell v ----- ^ Ping ^
	
	def do_shell(self, raw_args):
		if len(raw_args) < 1:
			print(f"{RED}*** Correct usage: 'shell <command>'{RS}")
		os.system(raw_args)
	
	def help_shell(self):
		print("Executes any command you want")
		print("Usage: 'shell <command>'")
		print("NOTE: '!' can be used instead of the keyword 'shell'")

 # v Interest calculator v ----- ^ Shell ^

	def do_interestweek(self, raw_args):
		misc.rent_week()
	
	def do_interestyear(self, raw_args):
		misc.rent_year()
	
	def help_interestweek(self):
		print("Calculates the interest for a savings account per week")
		print("Usage: 'rentweek'")

	def help_interestyear(self):
		print("Calculates the interest for a savings account per year")
		print("Usage: 'rentyear'")

 # v Subcount v ----- ^ Interest calculator ^

	def do_subcount(self, raw_args):
		args = getargs(raw_args)
		print(f"{RED}*** BROKEN / WIP ***{RS}")
		"""
		print("*** NOTE: This has limited functionality at the moment.")
		print("*** This does currently only work with id")
		url_raw = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+ args[0]+"&key="+googleapi_token
		url_processed = urllib.request.urlopen(url_raw).read()
		result = json.loads(url_processed)
		print("Subcount: {}".format(result["items"][0]["statistics"]["subscriberCount"]))
		"""
	
	def help_subcount(self):
		print(f"{RED}*** WIP ***{RS}")

 # v Meme v ----- ^ Subcount ^

	def do_meme(self, raw_args):
		misc.memes()



#Games launcher
class gamelauncher(cmd.Cmd):
	intro = "This is the game launcher. Type 'exit' to leave the game launcher."
	prompt = "(games) "
	doc_header = "Available games"
	undoc_header = "Available commands"
	misc_header = "Wiki"

 # v Ghosthouse v ----- 

	def do_ghosthouse(self, args):
		clear()
		games.ghosthouse_start()
		clear()
	
	def help_ghosthouse(self):
		print("A game where you try not to die")

 # v Exit v ----- ^ Ghosthouse ^

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

 # v Rock, paper, scissors v ----- ^ Exit ^

	def do_rockpaperscissors(self, raw_args):
		args = getargs(raw_args)
		if len(args) < 1:
			print("Missing required arg, <move>")
			return
		games.rock_paper_scissors(args[0])
		
	def help_rockpaperscissors(self):
		print("A simple rock paper scissors game")
		print("Usage: 'rps <move>' OR: 'rockpaperscissors <move>'")

#Starting the main launcher
if __name__ == "__main__":
	while True:
		try:
			funstuff().cmdloop()
		except KeyboardInterrupt:
			print("byebye")
			break