mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
godcmd: add temp passwd
This commit is contained in:
@@ -2,9 +2,13 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def _get_logger():
|
def _reset_logger(log):
|
||||||
log = logging.getLogger('log')
|
for handler in log.handlers:
|
||||||
log.setLevel(logging.INFO)
|
handler.close()
|
||||||
|
log.removeHandler(handler)
|
||||||
|
del handler
|
||||||
|
log.handlers.clear()
|
||||||
|
log.propagate = False
|
||||||
console_handle = logging.StreamHandler(sys.stdout)
|
console_handle = logging.StreamHandler(sys.stdout)
|
||||||
console_handle.setFormatter(logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
|
console_handle.setFormatter(logging.Formatter('[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d] - %(message)s',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S'))
|
datefmt='%Y-%m-%d %H:%M:%S'))
|
||||||
@@ -13,6 +17,11 @@ def _get_logger():
|
|||||||
datefmt='%Y-%m-%d %H:%M:%S'))
|
datefmt='%Y-%m-%d %H:%M:%S'))
|
||||||
log.addHandler(file_handle)
|
log.addHandler(file_handle)
|
||||||
log.addHandler(console_handle)
|
log.addHandler(console_handle)
|
||||||
|
|
||||||
|
def _get_logger():
|
||||||
|
log = logging.getLogger('log')
|
||||||
|
_reset_logger(log)
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
return log
|
return log
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import time
|
import time
|
||||||
import pip
|
import pip
|
||||||
|
from pip._internal import main as pipmain
|
||||||
|
from common.log import logger,_reset_logger
|
||||||
|
|
||||||
def install(package):
|
def install(package):
|
||||||
pip.main(['install', package])
|
pipmain(['install', package])
|
||||||
|
|
||||||
def install_requirements(file):
|
def install_requirements(file):
|
||||||
pip.main(['install', '-r', file, "--upgrade"])
|
pipmain(['install', '-r', file, "--upgrade"])
|
||||||
|
_reset_logger(logger)
|
||||||
|
|
||||||
def check_dulwich():
|
def check_dulwich():
|
||||||
needwait = False
|
needwait = False
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import string
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from bridge.bridge import Bridge
|
from bridge.bridge import Bridge
|
||||||
@@ -158,7 +160,11 @@ class Godcmd(Plugin):
|
|||||||
else:
|
else:
|
||||||
with open(config_path,"r") as f:
|
with open(config_path,"r") as f:
|
||||||
gconf=json.load(f)
|
gconf=json.load(f)
|
||||||
|
if gconf["password"] == "":
|
||||||
|
self.temp_password = "".join(random.sample(string.digits, 4))
|
||||||
|
logger.info("[Godcmd] 因未设置口令,本次的临时口令为%s。"%self.temp_password)
|
||||||
|
else:
|
||||||
|
self.temp_password = None
|
||||||
custom_commands = conf().get("clear_memory_commands", [])
|
custom_commands = conf().get("clear_memory_commands", [])
|
||||||
for custom_command in custom_commands:
|
for custom_command in custom_commands:
|
||||||
if custom_command and custom_command.startswith("#"):
|
if custom_command and custom_command.startswith("#"):
|
||||||
@@ -167,7 +173,7 @@ class Godcmd(Plugin):
|
|||||||
COMMANDS["reset"]["alias"].append(custom_command)
|
COMMANDS["reset"]["alias"].append(custom_command)
|
||||||
|
|
||||||
self.password = gconf["password"]
|
self.password = gconf["password"]
|
||||||
self.admin_users = gconf["admin_users"] # 预存的管理员账号,这些账号不需要认证 TODO: 用户名每次都会变,目前不可用
|
self.admin_users = gconf["admin_users"] # 预存的管理员账号,这些账号不需要认证。itchat的用户名每次都会变,不可用
|
||||||
self.isrunning = True # 机器人是否运行中
|
self.isrunning = True # 机器人是否运行中
|
||||||
|
|
||||||
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
|
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
|
||||||
@@ -358,9 +364,6 @@ class Godcmd(Plugin):
|
|||||||
if isadmin:
|
if isadmin:
|
||||||
return False,"管理员账号无需认证"
|
return False,"管理员账号无需认证"
|
||||||
|
|
||||||
if len(self.password) == 0:
|
|
||||||
return False,"未设置口令,无法认证"
|
|
||||||
|
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
return False,"请提供口令"
|
return False,"请提供口令"
|
||||||
|
|
||||||
@@ -368,6 +371,9 @@ class Godcmd(Plugin):
|
|||||||
if password == self.password:
|
if password == self.password:
|
||||||
self.admin_users.append(userid)
|
self.admin_users.append(userid)
|
||||||
return True,"认证成功"
|
return True,"认证成功"
|
||||||
|
elif password == self.temp_password:
|
||||||
|
self.admin_users.append(userid)
|
||||||
|
return True,"认证成功,请尽快设置口令"
|
||||||
else:
|
else:
|
||||||
return False,"认证失败"
|
return False,"认证失败"
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ class PluginManager:
|
|||||||
if os.path.exists(os.path.join(dirname,"requirements.txt")):
|
if os.path.exists(os.path.join(dirname,"requirements.txt")):
|
||||||
logger.info("detect requirements.txt,installing...")
|
logger.info("detect requirements.txt,installing...")
|
||||||
pkgmgr.install_requirements(os.path.join(dirname,"requirements.txt"))
|
pkgmgr.install_requirements(os.path.join(dirname,"requirements.txt"))
|
||||||
return True, "安装插件成功,请扫描插件或重启程序"
|
return True, "安装插件成功,请使用#scanp命令扫描插件或重启程序"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to install plugin, {}".format(e))
|
logger.error("Failed to install plugin, {}".format(e))
|
||||||
return False, "安装插件失败,"+str(e)
|
return False, "安装插件失败,"+str(e)
|
||||||
@@ -254,6 +254,9 @@ class PluginManager:
|
|||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(dirname)
|
shutil.rmtree(dirname)
|
||||||
rawname = self.plugins[name].name
|
rawname = self.plugins[name].name
|
||||||
|
for event in self.listening_plugins:
|
||||||
|
if name in self.listening_plugins[event]:
|
||||||
|
self.listening_plugins[event].remove(name)
|
||||||
del self.plugins[name]
|
del self.plugins[name]
|
||||||
del self.pconf["plugins"][rawname]
|
del self.pconf["plugins"][rawname]
|
||||||
self.loaded[dirname] = None
|
self.loaded[dirname] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user