Skip to content

Commit

Permalink
将指定范围内的API字符替换为星号
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed Nov 9, 2023
1 parent a6168de commit 0d62962
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ async def delete_message(update, context, messageid, delay=10):
if os.environ.get('GOOGLE_API_KEY', None) == None and os.environ.get('GOOGLE_CSE_ID', None) == None:
first_buttons[1][1] = InlineKeyboardButton("google已关闭", callback_data="google")

def replace_with_asterisk(string, start=10, end=45):
return string[:start] + '*' * (end - start) + string[end:]

banner = "👇下面可以随时更改默认 gpt 模型:"
async def button_press(update, context):
Expand All @@ -269,7 +271,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
callback_query = update.callback_query
Expand All @@ -286,7 +288,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await callback_query.edit_message_text(
Expand Down Expand Up @@ -320,7 +322,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await callback_query.edit_message_text(
Expand All @@ -340,7 +342,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)

Expand All @@ -363,7 +365,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await callback_query.edit_message_text(
Expand All @@ -383,7 +385,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await callback_query.edit_message_text(
Expand All @@ -403,7 +405,7 @@ async def button_press(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await callback_query.edit_message_text(
Expand All @@ -419,7 +421,7 @@ async def info(update, context):
f"**Default engine:** `{config.GPT_ENGINE}`\n"
f"**temperature:** `{config.temperature}`\n"
f"**API_URL:** `{config.API_URL}`\n\n"
f"**API:** `{config.API}`\n\n"
f"**API:** `{replace_with_asterisk(config.API)}`\n\n"
f"**WEB_HOOK:** `{config.WEB_HOOK}`\n\n"
)
message = await context.bot.send_message(chat_id=update.message.chat_id, text=escape(info_message), reply_markup=InlineKeyboardMarkup(first_buttons), parse_mode='MarkdownV2', disable_web_page_preview=True)
Expand Down
6 changes: 6 additions & 0 deletions test/test_API.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def replace_with_asterisk(string, start=15, end=40):
return string[:start] + '*' * (end - start) + string[end:]

original_string = "sk-zIuWeeuWY8vNCVhhHCXLroNmA6QhBxnv0ARMFcODVQwwqGRg"
result = replace_with_asterisk(original_string)
print(result)

0 comments on commit 0d62962

Please sign in to comment.