-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 私聊 * fix: 只有命令行登陆才修改配置文件 * fix: 判断是否从cli登陆 * #68 私信窗口 * feat: #118 python客户端在线状态记录 fix: 修复私聊通道重复建立的问题 * #103 通知系统 * fix: 正则修改 chore: 支持macos * chore version => 2.1.0
- Loading branch information
Showing
19 changed files
with
379 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
|
||
import requests | ||
|
||
from src.utils import UA | ||
|
||
from .base import Base | ||
from .config import GLOBAL_CONFIG | ||
|
||
|
||
class ChatAPI(Base): | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def unread(self) -> None | dict: | ||
if self.api_key == '': | ||
return None | ||
resp = requests.get(f"{GLOBAL_CONFIG.host}/chat/has-unread?apiKey={self.api_key}", | ||
headers={'User-Agent': UA}) | ||
return json.loads(resp.text) | ||
|
||
def get_list(self) -> list[dict]: | ||
if self.api_key == '': | ||
return None | ||
resp = requests.get(f"{GLOBAL_CONFIG.host}/chat/get-list?apiKey={self.api_key}", | ||
headers={'User-Agent': UA}) | ||
ret = json.loads(resp.text) | ||
if ret['result'] == 0: | ||
return ret['data'] | ||
else: | ||
return [] | ||
|
||
def render_recent_chat_users(self) -> None: | ||
[print(f"{user['receiverUserName']} {self.__render_online_flag(user['receiverOnlineFlag'])} : {user['preview']}") | ||
for user in self.get_list()] | ||
|
||
def __render_online_flag(self, is_online: bool) -> str: | ||
return '[在线]' if is_online else '[离线]' | ||
|
||
def get_msg(self, user: str, page: int = 1) -> list[dict]: | ||
if self.api_key == '': | ||
return None | ||
resp = requests.get(f"{GLOBAL_CONFIG.host}/chat/get-message?apiKey={self.api_key}&toUser={user}&page={page}&pageSize=20", | ||
headers={'User-Agent': UA}) | ||
ret = json.loads(resp.text) | ||
if ret['result'] == 0: | ||
return ret['data'] | ||
else: | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
import enum | ||
NTYPE = enum.Enum('Notification_type', [ | ||
'FROM_CHATROOM', 'FROM_CHAT', 'FROM_KEYWORD']) | ||
CODE = enum.Enum('REDPACKET_CODE', ['SUCCESS', 'LOSED', 'NOT_ME', "ZERO"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from src.api import API | ||
from src.api.ws import WS | ||
|
||
|
||
class Chat(WS): | ||
WS_URL = 'fishpi.cn/chat-channel' | ||
|
||
def __init__(self, to: str) -> None: | ||
self.params = {'toUser': to} | ||
super().__init__(Chat.WS_URL, [render]) | ||
|
||
def on_open(self, ws): | ||
print(f"正在与{self.params['toUser']}私聊!") | ||
[render(API, item) | ||
for item in reversed(API.chat.get_msg(self.params['toUser']))] | ||
|
||
def on_error(self, ws, error): | ||
print(f"私聊通道初始化失败, {self.params['toUser']}不存在!") | ||
self.stop() | ||
|
||
def on_close(self, ws, close_status_code, close_msg): | ||
print('私聊结束') | ||
|
||
def sender(self, msg: str): | ||
self.instance.send(msg) | ||
|
||
|
||
def render(api, message: dict): | ||
time = message["time"] | ||
sender_name = message["senderUserName"] | ||
if sender_name == api.current_user: | ||
print(f"\t\t\t\t\t\t[{time}]") | ||
print(f'\t\t\t\t\t\t你说: {message["markdown"]}') | ||
else: | ||
print(f"[{time}]") | ||
print(f"{sender_name}说:") | ||
print(message['markdown']) | ||
print("\r\n") |
Oops, something went wrong.