BDServer/modules/Common.py

168 lines
4.2 KiB
Python
Raw Normal View History

2024-11-19 13:47:45 +02:00
# AGPL 3 or any later version
# (C) J.Y.Amihud ( Blender Dumbass )
import random
clr = {
"norm":"\033[00m", # Reset to normal
"bold":"\033[01m", # Bold Text
"ital":"\033[03m", # Italic Text
"undr":"\033[04m", # Underlined
"blnk":"\033[05m", # Blinking
# Text
"tdbl":"\033[30m", # Dark Black
"tdrd":"\033[31m", # Dark Red
"tdgr":"\033[32m", # Dark Green
"tdyl":"\033[33m", # Dark Yellow
"tdbu":"\033[34m", # Dark Blue
"tdma":"\033[35m", # Dark Magenta
"tdcy":"\033[36m", # Dark Cyan
"tdwh":"\033[37m", # Dark White
"tbbl":"\033[90m", # Bright Black
"tbrd":"\033[91m", # Bright Red
"tbgr":"\033[92m", # Bright Green
"tbyl":"\033[93m", # Bright Yellow
"tbbu":"\033[94m", # Bright Blue
"tbma":"\033[95m", # Bright Magenta
"tbcy":"\033[96m", # Bright Cyan
"tbwh":"\033[97m", # Bright White
# Background
"bdbl":"\033[40m", # Dark Black
"bdrd":"\033[41m", # Dark Red
"bdgr":"\033[42m", # Dark Green
"bdyl":"\033[43m", # Dark Yellow
"bdbu":"\033[44m", # Dark Blue
"bdma":"\033[45m", # Dark Magenta
"bdcy":"\033[46m", # Dark Cyan
"bdwh":"\033[47m", # Dark White
"bbbl":"\033[100m", # Bright Black
"bbrd":"\033[101m", # Bright Red
"bbgr":"\033[102m", # Bright Green
"bbyl":"\033[103m", # Bright Yellow
"bbbu":"\033[104m", # Bright Blue
"bbma":"\033[105m", # Bright Magenta
"bbcy":"\033[106m", # Bright Cyan
"bbwh":"\033[108m" # Bright White
}
2024-11-23 22:34:11 +02:00
def Simplify(text, extrasimple=True):
2024-11-19 13:47:45 +02:00
2024-11-23 22:34:11 +02:00
good = "QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuiopasdfghjklzxcvbnm.1234567890-_:* "
2024-11-19 13:47:45 +02:00
2024-11-24 23:28:19 +02:00
if extrasimple == "file":
good = "QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuiopasdfghjklzxcvbnm.1234567890-_"
elif extrasimple:
2024-11-23 22:34:11 +02:00
good = "qwertyuiopasdfghjklzxcvbnm.1234567890-_:"
text = text.lower()
2024-11-19 13:47:45 +02:00
ntext = ""
for i in text:
if i in good:
ntext = ntext + i
else:
ntext = ntext + "_"
return ntext
def Safe(text):
return text.replace("<", "&lt").replace(">", "&gt")
def RandString(n=50):
# this will make a random string
s = ""
good = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890"
for i in range(n):
s = s + random.choice(good)
return s
2024-12-03 00:30:02 +02:00
IDColors = {" ANONYMOUS ":clr["norm"]}
def consoleForm(obj):
2024-11-25 23:17:19 +02:00
from modules.Render import accounts
# Username preview
username = ""
Accounts = accounts()
for account in Accounts:
if obj in Accounts[account].get("sessions"):
username = account
break
# Function that prints a pretty object info about
2024-11-25 23:17:19 +02:00
if not obj: obj = " ANONYMOUS "
ID = obj
2024-11-25 23:17:19 +02:00
if not username:
NAME = obj[-14:]
else:
NAME = username[:15].upper()
c = IDcolor(ID)
return c + " " + NAME + " " + clr["norm"]
def IDcolor(ID):
# Coloring
if ID not in IDColors:
r = random.random()
g = random.random()
b = random.random()
ct = clr["tbwh"]
if max(r, g, b ) > 0.9 or sum((r, g, b))/3 > 0.5:
ct = clr["tdbl"]
c = clr["bold"] + "\033[48;2;"+str(int(r*256))+";"+str(int(g*256))+";"+str(int(b*256))+"m"+ct
IDColors[ID] = c
c = IDColors[ID]
return c
# Licenses for stuff
Licenses = {
"cc0":{
"name":"CC0 Public Domain",
"link":"https://creativecommons.org/publicdomain/zero/1.0/"
},
"cc-by":{
"name":"Creative Commons Attribution",
"link":"https://creativecommons.org/licenses/by/4.0/"
},
"cc-by-sa":{
"name":"Creative Commons Attribution Share-Alike",
"link":"https://creativecommons.org/licenses/by-sa/4.0/"
},
"gpl3":{
"name":"GNU General Public License Version 3",
"link":"https://www.gnu.org/licenses/gpl.html"
},
"lgpl3":{
"name":"GNU Lesser General Public License Version 3",
"link":"https://www.gnu.org/licenses/lgpl.html"
},
"agpl":{
"name":"GNU Affero General Public License Version 3",
"link":"https://www.gnu.org/licenses/agpl.html"
},
"gpl3-or-later":{
"name":"GNU General Public License Version 3 or any later version",
"link":"https://www.gnu.org/licenses/"
}
}