-
Notifications
You must be signed in to change notification settings - Fork 11
/
database.py
108 lines (90 loc) · 2.79 KB
/
database.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
from pymongo import MongoClient
from datetime import datetime
class Storage(object):
def __init__(self):
self.database = MongoClient()['tg_spamer']
def check_auth(self, user, password):
keys = self.database['keys'].find_one(
{ 'type' : 'usr_pswd' }
)
#first use, no keys in database, defaut is [admin, admin]
if keys == None:
if user == 'admin' == password:
return True
return False
if user == keys['username'] and password == keys['password']:
return True
return False
def registration(self, new_user, new_pass):
self.database['keys'].update_one(
{ 'type' : 'usr_pswd' },
{
'$set' : { 'username' : new_user, 'password' : new_pass }
},
upsert=True
)
def add_account(self, data, key):
data['activated'] = False
data['session_id'] = key
self.database['accounts'].insert_one(
data
)
def get_session_id_by_phone(self, phone):
doc = self.database['accounts'].find_one(
{ 'phone' : phone }
)
return doc['session_id']
def get_accounts_list(self):
return self.database['accounts'].find()
def del_account(self, phone):
self.database['accounts'].delete_one(
{
'phone' : phone
}
)
def activate_account(self, phone):
self.database['accounts'].update_one(
{
'phone' : phone
},
{
'$set' : { 'activated' : True }
}
)
def register_api(self, api_id, api_hash):
self.database['keys'].update_one(
{ 'type' : 'api_keys' },
{
'$set' : { 'api_id' : api_id, 'api_hash' : api_hash }
},
upsert=True
)
def get_api_keys(self):
return self.database['keys'].find_one(
{ 'type' : 'api_keys' },
)
def insert_spam_job(self, users, message):
self.database['spam_jobs'].update_one(
{ 'message' : message },
{
'$set' : {
'delivery' : { user : False for user in users }
}
},
upsert=True
)
def user_invoiced(self, message, user):
self.database['spam_jobs'].update_one(
{ 'message' : message },
{
'$set' : {
'delivery.{}'.format(user) : True
}
}
)
def get_spam_jobs(self):
return self.database['spam_jobs'].find()
def delete_spam_job(self, message):
self.database['spam_jobs'].delete_one(
{ 'message' : message }
)