Skip to content

Commit

Permalink
Merge pull request #37 from flynnoct/36-fix-a-bug-in-acm
Browse files Browse the repository at this point in the history
36 fix a bug in acm
  • Loading branch information
flynnoct authored Mar 7, 2023
2 parents 7531636 + 5d440ac commit e7a735d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

![](/docs/dialog.png)

## URGENT

We located a bug in v1.2.0 which may lead to an error when start the bot. Please make sure you update to the v1.2.1 version.

## News

- **DALL·E, the OpenAI Image Generation Model**, is now supported! Send a short prompt to the Bot and get your own painting!
- **Whisper, the OpenAI Intelligent Speech Recognizer**, is now supported! Now chat with the Bot with audio messages!
- **Telegram Inline Mode (Beta)** is now supported! You can ask @BotFather to enable **both** inline mode & *inline feedback to 100%** for your Bot and use it in any private chat with a contact and group chat (even without inviting the bot as a member).
- **Telegram Inline Mode (Beta)** is now supported! You can ask @BotFather to enable **both** inline mode & \*inline feedback to 100%\*\* for your Bot and use it in any private chat with a contact and group chat (even without inviting the bot as a member).
- **Important privacy protection strategy** is deployed! The Bot is unable (and of course we won't) to collect any message in group chat except user prompts.
- **Better config.json.template** is now provided.
- **Better config.json.template** is now provided.

## Introduction

Expand Down
4 changes: 4 additions & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Version history

## v1.2.1

- A critical bug is fixed.

## v1.2.0

- Privacy protection improvement. The Bot now is unable to acquire messages in the group chat except user prompts.
Expand Down
18 changes: 7 additions & 11 deletions src/access_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ def __init__(self) -> None:

if not os.path.exists("./usage"):
os.makedirs("./usage")
# load usage info

# load usage info
(filename, _) = self.__get_usage_filename_and_key("chat")
if os.path.exists("./usage/" + filename):
with open("./usage/" + filename) as f:
self.user_chat_usage_dict = json.load(f)

(filename, _) = self.__get_usage_filename_and_key("image")
if os.path.exists("./usage/" + filename):
with open("./usage/" + filename) as f:
self.user_image_generation_usage_dict = json.load(f)


# generate filename & dict key (based on datetime)

def __get_usage_filename_and_key(self, chatORimage):
if chatORimage == "chat":
filename = "_chat_usage.json"
Expand All @@ -43,14 +43,10 @@ def __update_dict(self, chatORimage):
(filename, now) = self.__get_usage_filename_and_key(chatORimage)
# new month
if not os.path.exists("./usage/" + filename):
# necessary?
with open("./usage/" + filename, 'w') as f:
json.dump({}, f)
if chatORimage == "image":
self.user_image_generation_usage_dict = {}
elif chatORimage == "chat":
self.user_chat_usage_dict = {}
return

# new day
if chatORimage == "image" and now not in self.user_image_generation_usage_dict:
Expand All @@ -63,7 +59,7 @@ def __get_image_generation_usage(self, userid):
# always check date
if now not in self.user_image_generation_usage_dict:
self.__update_dict("image")

if userid not in self.user_image_generation_usage_dict[now]:
used_num = 0
self.user_image_generation_usage_dict[now][userid] = 0
Expand All @@ -77,14 +73,14 @@ def update_usage_info(self, user, num, chatORimage):
# always check date
if now not in self.user_image_generation_usage_dict:
self.__update_dict(chatORimage)

if chatORimage == "image":
if user not in self.user_image_generation_usage_dict[now]:
self.user_image_generation_usage_dict[now][user] = 0
self.user_image_generation_usage_dict[now][user] += num
with open("./usage/" + filename, "w") as f:
json.dump(self.user_image_generation_usage_dict, f)

elif chatORimage == "chat":
if user not in self.user_chat_usage_dict[now]:
self.user_chat_usage_dict[now][user] = 0
Expand Down

0 comments on commit e7a735d

Please sign in to comment.