Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored ibrother/chatgpt-telegram-bot #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions bot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):

# Define the async function to call the ChatGPT API
async def call_openai_chatgpt(message):
resp = await client.chat.completions.create(
model=MODEL,
messages=message
)
return resp
return await client.chat.completions.create(model=MODEL, messages=message)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function call_openai_chatgpt refactored with the following changes:



# Define the handler for incoming messages
async def message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
# Check if the message is sent in a private chat or in a group chat with the bot
chat_id = update.message.chat.id
if (update.message.chat.type == 'private' and chat_id in authorized_user_ids) or (
update.message.chat.type == 'supergroup' and chat_id in authorized_group_ids and '@{}'.format(
context.bot.username) in update.message.text):
if (
(
update.message.chat.type == 'private'
and chat_id in authorized_user_ids
)
or update.message.chat.type == 'supergroup'
and chat_id in authorized_group_ids
and f'@{context.bot.username}' in update.message.text
):
Comment on lines -104 to +108
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function message_handler refactored with the following changes:

# Get the user ID
user_id = update.message.from_user.id

Expand Down