diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..baab029 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/.venv/bin/python", + "args": [ + "-m", + "webot" + ], + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 0d698c8..e88ffd8 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,14 @@

这是一个基于web微信协议的简易微信机器人,目前功能比较简陋且不堪🙈。

- +

## 现有功能 +- AI机器人(ollama) - 简单文字消息回复 - 消息过滤 - 实时信息展示(带斗图表情(Iterm2)) @@ -58,7 +59,7 @@ ## 环境安装 -首先保证您已经安装了```python3.7.4```及以上版本,然后依次运行如下命令。 +首先保证您已经安装了```python3.10```及以上版本,然后依次运行如下命令。 ```sh git clone https://github.com/aoii103/Webot.git diff --git a/examples/ai_chat_with_self.py b/examples/ai_chat_with_self.py new file mode 100644 index 0000000..87cde6f --- /dev/null +++ b/examples/ai_chat_with_self.py @@ -0,0 +1,26 @@ +import sys +sys.path.append('..') + +from webot.core import Webot +from webot.util import Device +import ollama + +ollama.pull('llama3') + +class bot(Webot): + @Device.filters(["text"], is_me=True) + def send_back(self, msg): + response = ollama.chat( + model="llama3", + messages=[ + { + "role": "user", + "content": msg["content"], + }, + ], + ) + self.send_text(msg["from"], response["message"]["content"]) + + + +bot().run(hot_reload=True) diff --git a/requirements.txt b/requirements.txt index 3b152b2..e971cad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,65 @@ -requests==2.24.0 -termcolor==1.1.0 -pandas==1.1.4 -filetype==1.0.7 -requests_html==0.10.0 -PyExecJS==1.5.1 +anyio==4.4.0 +appdirs==1.4.4 +beautifulsoup4==4.12.3 +black==24.4.2 +bs4==0.0.2 +certifi==2024.6.2 +charset-normalizer==3.3.2 +click==8.1.7 +cssselect==1.2.0 +decorator==5.1.1 +et-xmlfile==1.1.0 +exceptiongroup==1.2.1 +fake-useragent==1.5.1 +filelock==3.15.4 +filetype==1.2.0 +h11==0.14.0 +httpcore==1.0.5 +httpx==0.27.0 +idna==3.7 imgcat==0.5.0 -openpyxl==3.0.7 -Pillow==8.2.0 +importlib_metadata==8.0.0 +Jinja2==3.1.4 +lxml==5.2.2 +lxml_html_clean==0.1.1 +MarkupSafe==2.1.5 +mypy-extensions==1.0.0 +numpy==2.0.0 +ollama==0.2.1 +openpyxl==3.1.5 +packaging==24.1 +pandas==2.2.2 +parse==1.20.2 +pathspec==0.12.1 +pillow==10.4.0 +platformdirs==4.2.2 +prettytable==3.10.0 progressbar33==2.4 -pyecharts==1.9.0 -pygame==2.0.1 +py==1.11.0 +pyecharts==2.0.6 +pyee==11.1.0 +PyExecJS==1.5.1 +pygame==2.6.0 +pyppeteer==2.0.0 +pyquery==2.0.0 +python-dateutil==2.9.0.post0 +pytz==2024.1 +requests==2.32.3 +requests-html==0.10.0 retry==0.9.2 -urlextract==1.3.0 +simplejson==3.19.2 +six==1.16.0 +sniffio==1.3.1 +soupsieve==2.5 +termcolor==2.4.0 +tomli==2.0.1 +tqdm==4.66.4 +typing_extensions==4.12.2 +tzdata==2024.1 +uritools==4.0.3 +urlextract==1.9.0 +urllib3==1.26.19 +w3lib==2.2.1 +wcwidth==0.2.13 +websockets==10.4 +zipp==3.19.2 diff --git a/test.py b/test.py deleted file mode 100644 index a99fe4f..0000000 --- a/test.py +++ /dev/null @@ -1,14 +0,0 @@ -from webot.core import Webot -from webot.util import Device - - -class bot(Webot): - @Device.filters(["text"], is_me=True) - def send_back(self, msg): - ... - # if msg["type"] == "text": - # if "你好" == msg["content"]: - # self.send_text(msg["from"], "你好呀!") - - -bot().run(hot_reload=True) diff --git a/webot/core.py b/webot/core.py index 78c35fc..298c187 100644 --- a/webot/core.py +++ b/webot/core.py @@ -197,6 +197,9 @@ def get_ticket(self): self.__get_ticket_url, params={"fun": "new", "lang": "zh_CN", "_": Device.get_timestamp()}, ) + resp.encoding = 'GB2312' + if '暂不支持使用网页版微信' in resp.text : + exit('您的账号不支持网页版微信') info( f"Get Ticket:{requests_html.requests.utils.dict_from_cookiejar(resp.cookies)}" )