Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
telegram_bot_antispammer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иванова Мария Кирилловна
telegram_bot_antispammer
Commits
71ec1518
Commit
71ec1518
authored
Apr 15, 2025
by
Иванова Мария Кирилловна
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dbfix' into 'master'
fix db connection via DB_PATH env See merge request
!3
parents
e2cf6ee0
a80471cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
12 deletions
+11
-12
bot.py
bot.py
+3
-4
sqlite_tools.py
sqlite_tools.py
+8
-8
No files found.
bot.py
View file @
71ec1518
...
...
@@ -23,7 +23,7 @@ load_dotenv()
bot_token
=
os
.
getenv
(
"BOT_TOKEN"
)
log_chat_id
=
os
.
getenv
(
"LOG_CHAT_ID"
)
main_chat_id
=
os
.
getenv
(
"MAIN_CHAT_ID"
)
db_path
=
os
.
getenv
(
"DB_PATH"
)
# Вызов функции для создания базы данных или подключения к существующей
create_db
()
...
...
@@ -156,7 +156,7 @@ async def handle_message(message: Message):
text
=
" "
.
join
(
normalize_text_to_infinitive
(
text
,
chat_id
))
# Убедимся, что это строка
# Проверяем, если это первое сообщение пользователя
conn
=
sqlite3
.
connect
(
'users.db'
)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
'SELECT messages_checked FROM users WHERE id = ?'
,
(
user_id
,))
...
...
@@ -314,4 +314,4 @@ async def main():
if
__name__
==
"__main__"
:
create_db
()
# Создание базы данных и таблиц
asyncio
.
run
(
main
())
\ No newline at end of file
asyncio
.
run
(
main
())
sqlite_tools.py
View file @
71ec1518
...
...
@@ -2,9 +2,10 @@
import
sqlite3
import
os
db_path
=
os
.
getenv
(
"DB_PATH"
)
def
create_db
():
db_path
=
os
.
getenv
(
"DB_PATH"
)
# Подключаемся к базе данных (если она не существует, она будет создана)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
...
...
@@ -43,7 +44,7 @@ def create_db():
# Функция для добавления пользователя в базу данных
def
add_user
(
user_id
,
first_name
,
last_name
,
username
):
conn
=
sqlite3
.
connect
(
'users.db'
)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
'''
...
...
@@ -56,7 +57,7 @@ def add_user(user_id, first_name, last_name, username):
# Функция для проверки, есть ли пользователь в базе данных
def
user_exists
(
user_id
):
conn
=
sqlite3
.
connect
(
'users.db'
)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
'SELECT id FROM users WHERE id = ?'
,
(
user_id
,))
...
...
@@ -67,7 +68,7 @@ def user_exists(user_id):
# Функция для перемещения пользователя в таблицу забаненных
def
ban_user
(
user_id
,
first_name
,
last_name
,
username
,
ban_reason
):
conn
=
sqlite3
.
connect
(
'users.db'
)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
# Добавляем в таблицу забаненных
...
...
@@ -83,11 +84,11 @@ def ban_user(user_id, first_name, last_name, username, ban_reason):
conn
.
close
()
def
is_user_banned
(
user_id
):
conn
=
sqlite3
.
connect
(
'users.db'
)
conn
=
sqlite3
.
connect
(
db_path
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
'SELECT id FROM banned_users WHERE id = ?'
,
(
user_id
,))
result
=
cursor
.
fetchone
()
conn
.
close
()
return
result
is
not
None
\ No newline at end of file
return
result
is
not
None
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment