-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
75 lines (66 loc) · 2.37 KB
/
test.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
#! /usr/bin/python3.9
import mydb
# conf = {
# "guilds": [os.getcwd()+f"{dir_div}guilds.db", "Guild"],
# "users": [os.getcwd()+f"{dir_div}users.db", "User"]}
debug = True
users = mydb.DataBase("users")
guilds = mydb.DataBase("guilds", config=None, models=None, now = False) # you can read the source if you doesn't understand
"""
can load your own config, be sure to have same name in _modelos.py
can load your own models you can use the _modelos.py as an example.
"""
def add(database, name: str):
"""
@params
database: from mydb.Database(table)
name: str,
"""
cuser = database.get_object(name, ex=dict(lang='en', prefix="/"))
if debug:
print(cuser.__dir__(), cuser.id, cuser.name, cuser.lang, cuser.prefix, cuser.created_at)
def set_to(database, name: str, key="prefix", value="."):
"""
@params
database: class where is the database,
name: of the key to search in the database
what_to_change: the key must be on the _modelos that was loaded to the database.
value: this can be string or int, be sure of what you are saving
This is just an example of making changes to a user in database but I used in my bots.
Exmple;
eval set_to(users, name, key, value)
eval set_to(guilds, name, key, value)
"""
if value:
if len(value) <=2:
database.update_row_by_name(name, key, value)
msg = "{} changed to {} for user {}".format(key, value, name)
else: msg = "prefix is long..."
else:
msg = "eval set_to('user1', key='lang', value='es')"
if debug:
print(msg)
def test(name: str = "test1"):
"""THis is just going to create a user in users database"""
add(users, name) # databases are converted in class
set_to(users, name) # this is just a test, im not going to complicate.
add(guilds, name) # using guilds as database
def testing():
"""write; eval test()"""
while True:
_input = str(input(">>"))
if len(_input.split(' ')) > 1:
cmd, args = _input.split(' ', 1)
args = args.split()
else:
cmd = _input.lower()
args = []
if cmd == "eval" and args:
try:
ret = repr(eval(" ".join(args)))
except Exception as e:
ret = str(e)
print(repr(ret))
elif cmd in ['q', 'quit']:
break
testing()