File tree 4 files changed +37
-4
lines changed
4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -133,5 +133,4 @@ def isGroupMember(chat_id, user_id):
133
133
if (response ['ok' ] == True ):
134
134
return True
135
135
else :
136
- return False
137
-
136
+ return False
Original file line number Diff line number Diff line change 2
2
"sudoers": [
3
3
49681384
4
4
],
5
+ "authorized_chats": [
6
+ -7016014,
7
+ -1001049208929
8
+ ],
5
9
"authorized_users": [
6
10
49681384,
7
11
14160874,
24
28
102544375,
25
29
52433246,
26
30
78977189
31
+ ],
32
+ "automatically_authorized_users": [
33
+
27
34
],
28
35
"enabled_plugins": {
29
36
"^[!/]melembra(?:@MercuriumBot)? ?([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?(?: (.+))?$": "melenbra",
Original file line number Diff line number Diff line change 3
3
from os import environ
4
4
import requests
5
5
import json
6
+ import psycopg2 as psql
7
+ from os import environ as env
6
8
from api import send_message
7
9
10
+ SQLPARAMS = "dbname=mercurium user=mercurium password=" + env ['REBORNKEY' ]
11
+
8
12
# Isso deve ser suficiente para transplantar as estatísticas para
9
13
# um plugin independente
10
14
def on_msg_received (msg , matches ):
@@ -29,6 +33,12 @@ def return_statistics(chat):
29
33
else :
30
34
return "n ten isotirco nesste xet ;()"
31
35
36
+ # Conecta-se à base SQL
37
+ #conn = psql.connect(SQLPARAMS)
38
+
39
+
40
+
41
+
32
42
dictofdicts = {}
33
43
34
44
# Passa cada usuário do chat pro dictofdicts, onde a chave é o nome e o valor é a qtde.
Original file line number Diff line number Diff line change @@ -80,16 +80,33 @@ def is_authorized(msg):
80
80
81
81
if msg ["from" ]["id" ] in config .config ["authorized_users" ]:
82
82
return True
83
+ elif msg ["from" ]["id" ] in config .config ["automatically_authorized_users" ]:
84
+ return True # Para usuários autorizados automaticamente com base no pertencimento
85
+ # a grupos. Por ora, só podem ser removidos manualmente
83
86
else :
84
87
# Como eu não sei a ID de todos os indivíduos romanos, resolvi fazer uma query para ver se o caboclo
85
88
# pertence ao chat...
86
- # TODO: Criar um modo de adicionar o caboclo à lista de permissões
87
- if api .isGroupMember (msg ["chat" ]["id" ], msg ["from" ]["id" ]) is True :
89
+
90
+ if isAuthorizedGroupMember (msg ["from" ]["id" ]) is True :
91
+ # Adiciona o indivíduo de vez, economizando essa consulta burra e redundante
92
+ config .config ["automatically_authorized_users" ].append (msg ["from" ]["id" ])
93
+ config .save_config ()
88
94
return True
89
95
else :
90
96
return False
91
97
92
98
99
+ # Verifica se o caboclo faz parte de algum dos chats autorizados
100
+ def isAuthorizedGroupMember (user_id ):
101
+
102
+ for gid in config .config ["authorized_chats" ]:
103
+ if api .isGroupMember (gid , user_id ):
104
+ return True
105
+
106
+ return False # Solução estranha, porém funcional e razoavelmente elegante
107
+
108
+
109
+
93
110
def msg_matches (msg_text ):
94
111
for query , plugin in config .plugins .items ():
95
112
pattern = re .compile (query )
You can’t perform that action at this time.
0 commit comments