Skip to content

Commit

Permalink
Add Simplified Chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
pininkara committed Apr 27, 2023
1 parent ead1a75 commit 668531b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Language : English [简体中文](README.zh-cn.md)
# Description

Bing chat Telegram bot implemented in Python that utilizes unofficial [EdgeChat](https://github.com/acheong08/EdgeGPT) API
Expand Down
85 changes: 85 additions & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
语言:[English](README.MD) 简体中文
# 介绍

使用非官方 [EdgeChat](https://github.com/acheong08/EdgeGPT) API 的 Python 实现的 Bing 聊天 Telegram 机器人

## 已知问题

- ~~不同用户会使用同一个对话~~(已修复)

## 截图

![](assets/screenshot.zh-cn.png)

## 命令列表

```
help - 帮助信息
reset - 重置对话
switch - 切换对话风格 ( creative , balanced , precise )
```

# 安装

## 需求

- python 3.8+
- 一个能访问 http://bing.com/chat的微软账号 (必须!)

## 检查访问权限

- 安装最新版本的 Microsoft Edge
- 访问 http://bing.com/chat
- 如果你能看到聊天界面,说明你有访问权限

## 获取cookie

- 安装cookie插件:Chrome](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm)[Firefox](https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/)
- 访问 http://bing.com/chat
- 打开插件
- 点击底部的Export按钮 (cookie将会复制到你的剪贴板)
- 粘贴你的cookie到 `cookies.json`. json的格式参见 `cookie.exaple.json`(中间部分省略)

## 安装依赖

```shell
pip install -r requirements.txt
```

## 设置环境变量

### 必须变量

```shell
export BOT_TOKEN='REPLACE YOUR BOT TOKEN'
export ALLOWED_USER_IDS='XXXXXXXXX,XXXXXXXX,XXXXXXXX'
```

### 可选变量

```shell
#默认值为 './cookie.json'
export COOKIE_PATH='xxxxxx'

#默认值为 False , 如果你设置为True,任何人都可以使用bot
export PUBLIC_MODE=True


#如果你想将bot添加至群聊,请设置这些环境变量,并授予bot管理员权限
export BOT_ID='@YOURBOTID' #别忘了@
export GROUP_MODE=True #默认值为 False
```
如果 GROUP_MODE 为True ,bot将会回复群组里所有消息 , 否则bot只会回复@它的消息
私聊消息一直会回复

## 运行

```shell
python bing.py
```






Binary file added assets/screenshot.zh-cn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def switch_style(message):
bot.reply_to(
message, "Parameter error , please choose one of (creative,balanced,precise)\n(e.g./switch balanced")
else:
bot.reply_to(message, not_allow_info)
bot.reply_to(
message, '⚠️You are not authorized to switch conversation style ⚠️')


@bot.message_handler(func=lambda msg: True)
Expand Down Expand Up @@ -109,7 +110,8 @@ def callback_all(callback_query):
if len(response_list[0]) > 4095:
for x in range(0, len(response_list[0]), 4095):
bot.reply_to(
callback_query.message, response_list[0][x:x + 4095], parse_mode='Markdown',
callback_query.message, response_list[0][x:x +
4095], parse_mode='Markdown',
reply_markup=response_list[1])

else:
Expand Down Expand Up @@ -153,7 +155,8 @@ async def bing_chat(message_text, message):
response_dict['item']['throttling']:
max_num_user_messages_in_conversation = response_dict['item'][
'throttling']['maxNumUserMessagesInConversation']
num_user_messages_in_conversation = response_dict['item']['throttling']['numUserMessagesInConversation']
num_user_messages_in_conversation = response_dict[
'item']['throttling']['numUserMessagesInConversation']
response = response + "\n----------\n"
response = response + "Messages In Conversation : %d / %d" % (
num_user_messages_in_conversation, max_num_user_messages_in_conversation)
Expand All @@ -177,11 +180,11 @@ async def bing_chat(message_text, message):
r'\[\^\d\^]', '', response_dict['item']['messages'][1]['sourceAttributions'][2]['seeMoreUrl'])
response = response + "\n----------\nReference:\n"
response = response + \
"1.[%s](%s)\n" % (provider_display_name0, see_more_url0)
"1.[%s](%s)\n" % (provider_display_name0, see_more_url0)
response = response + \
"2.[%s](%s)\n" % (provider_display_name1, see_more_url1)
"2.[%s](%s)\n" % (provider_display_name1, see_more_url1)
response = response + \
"3.[%s](%s)\n" % (provider_display_name2, see_more_url2)
"3.[%s](%s)\n" % (provider_display_name2, see_more_url2)

markup = quick_markup({
suggested_responses0: {'callback_data': suggested_responses0[0:21]},
Expand Down

0 comments on commit 668531b

Please sign in to comment.