1
0
Fork 0
forked from swee/MeowNex
MeowNex/cc/give

36 lines
1.4 KiB
Text
Raw Normal View History

2024-09-10 21:59:30 -07:00
from sys import argv
import sqlite3
2024-12-28 18:43:11 -08:00
import re
2024-11-14 19:18:46 -08:00
conn = sqlite3.connect("/home/sweebotirc/sbirc.db")
2024-09-10 21:59:30 -07:00
database = conn.cursor()
2024-12-28 18:43:35 -08:00
def getperms(mask: str):
2024-12-28 18:43:11 -08:00
try:
2024-12-28 18:44:08 -08:00
database.execute(f"SELECT * FROM users;")
output = database.fetchall()
2024-12-28 18:43:11 -08:00
for i in output:
if re.match(i[0].replace("*", ".+"), mask):
return i[1]
return ''
except:
print(traceback.format_exc())
return ''
2024-12-28 18:41:29 -08:00
if argv[2] == "full":
2024-09-10 21:59:30 -07:00
if len(argv) == 5:
if argv[3] == argv[2]:
print(argv[1] + ": You wanna give yourself permissions!?")
else:
perms = getperms(argv[3])
2024-12-28 18:43:11 -08:00
if argv[4] in perms:
print("The specified user already has these permissions.")
elif perms != "":
2024-09-10 21:59:30 -07:00
database.execute("UPDATE users SET perms = '" + perms + "," + argv[4] + "' WHERE username = '" + argv[3] + "';")
print(argv[1] + ": Successfully appended '" + argv[4] + "' to the permissions of " + argv[3])
else:
database.execute("INSERT INTO users (username, perms) VALUES ('" + argv[3] + "', '" + argv[4] + "');")
print(argv[1] + ": Successfully created permissions of " + argv[3] + " and set it to '" + argv[4] + "'")
else:
print(argv[1] + ": This command takes 2 arguments, only got " + str(len(argv) - 3) + ".")
else:
print(argv[1]+": Permission denied")
conn.commit()
conn.close()