Skip to content

Commit

Permalink
增加VIP功能和添加删除VIP功能
Browse files Browse the repository at this point in the history
flipturn14 committed Mar 23, 2023
1 parent 69d4bb5 commit 7097548
Showing 6 changed files with 84 additions and 38 deletions.
35 changes: 16 additions & 19 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@



使用基于 ChatGPT (非API-KEY调用) 、Stable Diffusion AI画图(本地部署) 与 官方微信hook接口 的 ChatGPT-3 / ChatGPT4 机器人。(本着开源想法,连Readme都是抄的)
使用基于 ChatGPT (非API-KEY调用) 、Stable Diffusion AI画图(本地部署) 与 官方微信hook接口 的 ChatGPT-3 / ChatGPT4
机器人。(本着开源想法,连Readme都是抄的)

下面是私聊的自我介绍:

@@ -46,13 +47,14 @@
- [x] 重新生成答案
- [x] 回滚对话


## 默认配置 (请在启动前仔细阅读,所有配置文件在config.json中)

```
{
// 本地host运行地址(仅本地)
"server_host": "127.0.0.1:5555",
//两次聊天间隔时间
"chat_interval": 120,
// 在群聊中设置唤醒ChatGPT-3关键词
"groupChatKey": "g",
@@ -76,10 +78,6 @@
}
```





## 启动步骤

1. 安装 `requirements.txt` 中列出的所有包,使用如下命令:
@@ -88,17 +86,18 @@
pip install -r ./requirements.txt
```

2. 在您的计算机上安装 `WeChat-3.6.0.18.exe`**如果您正在使用的微信版本高于3.6.0.18,可以降级覆盖安装。** 之后请登陆您的微信。**
2. 在您的计算机上安装 `WeChat-3.6.0.18.exe`**如果您正在使用的微信版本高于3.6.0.18,可以降级覆盖安装。**
之后请登陆您的微信。**

3. 运行服务器监控微信消息。这里有两种方法可以实现,请 ***二选一***

- 打开名字为 `tools/DLLinjector_V1.0.3.exe` 的注入器,然后选择文件名为 `3.6.0.18-0.0.0.008.dll` 并注入。
- 打开名字为 `tools/DLLinjector_V1.0.3.exe` 的注入器,然后选择文件名为 `3.6.0.18-0.0.0.008.dll` 并注入。

![image-20230221044543472](assets/image-20230221044543472.png)
![image-20230221044543472](assets/image-20230221044543472.png)

- 运行 `funtool_3.6.0.18-1.0.0013.exe` ,后点击 `Start`
- 运行 `funtool_3.6.0.18-1.0.0013.exe` ,后点击 `Start`

![image-20230221044609319](assets/image-20230221044609319.png)
![image-20230221044609319](assets/image-20230221044609319.png)

4. 登录[steamship.com](https://www.steamship.com)注册账号, 使用ChatGPT-4会用到。

@@ -116,8 +115,7 @@
node index.js
```


**一切准备就绪,欢迎使用 Wechat_bot!**
**一切准备就绪,欢迎使用 Wechat_bot!**

没有限制、没有使用计数,也没有付费要求。

@@ -127,8 +125,6 @@

需要生成图片请自行安装webui并下载各种模型后启动,此处不进行讲解。



## 常见问题解答

1. 遇到问题了吗?随时来创建一个 issue 进行发布。
@@ -142,12 +138,13 @@

## 日志

- 2023年3月23日 增加配置文件,默认私聊关闭自动回复。可输入命令`启用/关闭/帮助` 群聊可输入`g启用/g关闭`进行控制
- 2023年3月22日 公布版本


- 2023年3月23日

1. 增加配置文件,默认私聊关闭自动回复。可输入命令`启用/关闭/帮助` 群聊可输入`g启用/g关闭`进行控制;
2. 增加私聊间隔时长避免封号;
3. 增加VIP功能,可输入关键词加添加wx_id 让用户无间隔限制;输入关键词加删除wx_id让用户受间隔限制;

- 2023年3月22日 公布版本

###### 参考

2 changes: 2 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"server_host": "127.0.0.1:5555",
"chat_interval": 120,

"groupChatKey": "g",
"groupChatKey4": "c",
"grpCitationMode": true,
2 changes: 1 addition & 1 deletion nodejs/dist/index.js
Original file line number Diff line number Diff line change
@@ -403,7 +403,7 @@ httpServer.createServer(function (req, res) {
body += chunk.toString();
});
req.on('end', async () => {
console.log("请求内容:" + decodeURIComponent(body));
// console.log("请求内容:" + decodeURIComponent(body));
let data = JSON.parse(body);
let chatBot;
if (users[data.wx_id]) {
2 changes: 1 addition & 1 deletion nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ httpServer.createServer(function (req, res) {
body += chunk.toString();
});
req.on('end', async () => {
console.log("请求内容:" + decodeURIComponent(body))
// console.log("请求内容:" + decodeURIComponent(body))
let data = JSON.parse(body);
let chatBot: ChatBot;
if (users[data.wx_id]) {
80 changes: 63 additions & 17 deletions python/client/wxclient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path
import re
import time

import websocket

@@ -15,7 +16,7 @@
# 公共线程
global_thread = []
# 屏蔽id集合,重启失效
disable_ids = {}
user_configs = {}

welcome_group = "调用GPT对话请在文字前增加召唤字母\n" \
"可用功能为c/g/t\n" \
@@ -112,42 +113,86 @@ def handle_recv_txt_msg(j):
# ----------基础信息end----------
# 输出所有消息
print(get_now() + nick + ":" + content)
# 添加VIP用户
if wx_id in group_admin:
if content.startswith(groupChatKey + "添加"):
add_wx_id = re.sub("^" + groupChatKey + "添加", "", content, 1)
if user_configs.get(add_wx_id) is not None:
user_configs[add_wx_id]['vip'] = True
ws.send(send_txt_msg(text_string="添加成功,该用户无限制", wx_id=wx_id))
save_config()
else:
ws.send(send_txt_msg(text_string="此用户不存在", wx_id=wx_id))
return
elif content.startswith(groupChatKey + "删除"):
add_wx_id = re.sub("^" + groupChatKey + "删除", "", content, 1)
if user_configs.get(add_wx_id) is not None:
user_configs[add_wx_id]['vip'] = False
ws.send(send_txt_msg(text_string="删除成功,该用户受限制", wx_id=wx_id))
save_config()
else:
ws.send(send_txt_msg(text_string="此用户不存在", wx_id=wx_id))
return
if is_room: # 群内消息
if user_configs.get(room_id) is None:
print(get_now() + nick + "配置文件没有存储该群聊信息,默认关闭。保存至文件")
user_configs[room_id] = {
"disable": True,
"last_time": time.time(),
"vip": False
}
save_config()
if wx_id in group_admin:
if content.startswith(groupChatKey + "关闭"):
disable_ids[room_id] = "close"
print(get_now() + "当前状态" + str(disable_ids.get(room_id)))
user_configs[room_id]["disable"] = True
ws.send(send_txt_msg(text_string="已经关闭该群的回复,大家再见!", wx_id=room_id))
save_config()
return
elif content.startswith(groupChatKey + "启用"):
disable_ids[room_id] = "open"
user_configs[room_id]["disable"] = False
ws.send(send_txt_msg(text_string="大家好," + welcome_group, wx_id=room_id))
save_config()
return
else: # 个人消息
if disable_ids.get(wx_id) is None:
if user_configs.get(wx_id) is None:
print(get_now() + nick + "配置文件没有存储该用户信息,默认关闭。保存至文件")
disable_ids[wx_id] = 'close'
user_configs[wx_id] = {
"disable": True,
"last_time": time.time(),
"vip": False
}
save_config()
ws.send(send_txt_msg(text_string=welcome_private, wx_id=wx_id))
return
if content == "关闭":
disable_ids[wx_id] = "close"
print(get_now() + "当前状态" + str(disable_ids.get(wx_id)))
user_configs[wx_id]["disable"] = True
ws.send(send_txt_msg(text_string="已经关闭自动回复,如需恢复请输入:启用", wx_id=wx_id))
save_config()
return
elif content == "启用":
disable_ids[wx_id] = "open"
user_configs[wx_id]["disable"] = False
ws.send(send_txt_msg(text_string="已经开启自动回复,如需停用请输入:关闭", wx_id=wx_id))
save_config()
return
elif content == "你好" or content.startswith("在吗") or content.startswith("在么"):
ws.send(send_txt_msg(text_string=welcome_private, wx_id=wx_id))
return
# 已关闭群聊或关闭自动回复的,直接返回
if disable_ids.get(room_id) == 'close' or disable_ids.get(wx_id) == 'close':
if (is_room and user_configs[room_id]["disable"]) or \
user_configs.get(wx_id) is None or \
user_configs[wx_id]["disable"]:
return

# 计算聊天间隔,不判断VIP用户以及管理员
last_time = user_configs[wx_id]["last_time"]
interval = int(time.time() - last_time)
if interval < chat_interval and wx_id not in group_admin and user_configs[wx_id]["vip"] is not True:
if not is_room:
if interval > chat_interval / 2:
ws.send(send_txt_msg(
text_string=("小于设定提问间隔时间%d秒,还需等待%d秒" % (chat_interval, (chat_interval - interval))),
wx_id=wx_id))
return
user_configs[wx_id]["last_time"] = time.time()
# 启用了生成图片并且起始关键字一致
if stableDiffRly and (
(content.startswith(privateImgKey) and not is_room) or (content.startswith(groupImgKey) and is_room)):
@@ -270,27 +315,28 @@ def on_close(ws):

def save_config():
print("保存已关闭聊天id配置到文件")
data = json.dumps(disable_ids)
data = json.dumps(user_configs)
with open("./data.json", "wb") as file_object:
file_object.write(data.encode('utf-8'))
file_object.close()
print("保存已关闭聊天id配置到文件完成")


def load_config():
global disable_ids
print("读取已关闭消息配置到文件")
global user_configs
print("读取用户配置到文件")
if os.path.exists("./data.json"):
with open("./data.json", encoding="utf-8") as file_object:
disable_ids = json.load(file_object)
user_configs = json.load(file_object)
file_object.close()
print("读取已关闭消息配置到文件完成")
print("读取用户配置到文件完成")
else:
print("未找到已关闭消息配置文件")
print("未找用户消息配置文件")


server = "ws://" + server_host
# 是否调试模式
websocket.enableTrace(False)
# websocket.enableTrace(True)

ws = websocket.WebSocketApp(server, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close)
1 change: 1 addition & 0 deletions python/shared/shared.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
f.close()

server_host = config["server_host"]
chat_interval = config["chat_interval"]

groupChatKey = config["groupChatKey"]
groupChatKey4 = config["groupChatKey4"]

0 comments on commit 7097548

Please sign in to comment.