Skip to content

Commit

Permalink
提交,
Browse files Browse the repository at this point in the history
  • Loading branch information
xiwangly2 committed Jan 18, 2025
1 parent b26732a commit ba470c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
17 changes: 9 additions & 8 deletions internal/chat_thesaurus.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ async def chat_thesaurus(messages, ws=None):
try:
# 查询开关
bot_switch = Database().db_handler.bot_switch(messages['group_id'])
if bot_switch is None or len(bot_switch) == 0:
if bot_switch is None:
if arg[0] == '/on' and is_admin:
Database().db_handler.bot_switch(messages['group_id'], 1)
text = "Bot started successfully."
return text
except NameError:
bot_switch = '0'
bot_switch = False
if config['debug']:
import traceback
traceback.print_exc()
pass
if bot_switch == '0':
if bot_switch is False:
if arg[0] == '/on' and is_admin:
Database().db_handler.bot_switch(messages['group_id'], 1)
text = "Bot started successfully."
else:
text = None
return text
elif bot_switch == '1':
elif bot_switch is True:
if arg[0] == '/on' and is_admin:
text = "Bot is running."
elif arg[0] == '/off' and is_admin:
Expand Down Expand Up @@ -224,7 +224,6 @@ async def chat_thesaurus(messages, ws=None):
text = None
else:
text = None
print_pink(f"text内容:{text}")
return text


Expand Down Expand Up @@ -279,6 +278,8 @@ async def while_msg(ws):
for message in text:
await send_message(ws, messages, message, False)
except Exception:
print(f"Error: {Exception}")
import traceback
traceback.print_exc()
if config['debug']:
import traceback
traceback.print_exc()
else:
pass
23 changes: 16 additions & 7 deletions internal/database/postgresql_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import traceback
from datetime import datetime
from xmlrpc.client import Boolean

import psycopg2
from psycopg2 import pool
from psycopg2.extras import RealDictCursor
Expand Down Expand Up @@ -53,25 +55,32 @@ def bot_switch(self, group_id='0', switch=None):
cursor = conn.cursor(cursor_factory=RealDictCursor)

if switch is not None:
# Insert SQL record
# Insert or update SQL record
date = datetime.now()
cursor.execute(
"INSERT INTO switch (group_id, switch, time) VALUES (%s, %s, %s) ON CONFLICT (group_id) DO UPDATE SET switch = EXCLUDED.switch, time = EXCLUDED.time",
(group_id, switch, date)
)
conn.commit() # Commit transaction
cursor.close()
self.pool.putconn(conn) # Return connection to pool
return True
else:
cursor.execute(
"SELECT * FROM switch WHERE group_id = %s",
"SELECT switch FROM switch WHERE group_id = %s",
(group_id,)
)
return cursor.fetchall()

conn.commit() # Commit transaction
cursor.close()
self.pool.putconn(conn) # Return connection to pool
result = cursor.fetchone()
cursor.close()
self.pool.putconn(conn) # Return connection to pool
if result:
return result['switch'] == '1'
else:
return False
except Exception:
if config['debug']:
traceback.print_exc()
return False

def image_exists(self, sha256_hash, md5_hash):
try:
Expand Down

0 comments on commit ba470c7

Please sign in to comment.