mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2026-01-05 14:05:38 +01:00
2
Pipfile
2
Pipfile
@@ -6,7 +6,7 @@ name = "pypi"
|
||||
[packages]
|
||||
requests = "*"
|
||||
python-telegram-bot = "==20.0a6"
|
||||
revchatgpt = "==0.0.35"
|
||||
revchatgpt = "==0.0.36.1"
|
||||
python-dotenv = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
8
Pipfile.lock
generated
8
Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "2eb67492c65c2f60d234a34e63b9ce5c50167fe5b8b71e4213f4450f384119b3"
|
||||
"sha256": "f97c365de56e56676a39f258153e749176f1a8cc37646b50f62ea9dbb52ee9fc"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@@ -330,11 +330,11 @@
|
||||
},
|
||||
"revchatgpt": {
|
||||
"hashes": [
|
||||
"sha256:5040bd20a948dec0414ac1eca625717815007c6e91dd61a74e64bd8c1b71df28",
|
||||
"sha256:cf297063301132b95ff6037520997b7ac71780b13e8c33ab76a676b05adde847"
|
||||
"sha256:5c8473ca22f7e35f12a30e985084e19949b62aef2c98bc6559d7a93edc1c6f58",
|
||||
"sha256:c1f737e31d044e26cc7fea94488a739e75ee702dc7937e1c0de2fa90b754c29f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.0.35"
|
||||
"version": "==0.0.36.1"
|
||||
},
|
||||
"rfc3986": {
|
||||
"extras": [
|
||||
|
||||
@@ -2,7 +2,7 @@ import asyncio
|
||||
import logging
|
||||
|
||||
import telegram.constants as constants
|
||||
from asyncChatGPT.asyncChatGPT import Chatbot as ChatGPT3Bot
|
||||
from revChatGPT.revChatGPT import asyncChatBot as ChatGPT3Bot
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters
|
||||
|
||||
@@ -11,6 +11,7 @@ class ChatGPT3TelegramBot:
|
||||
"""
|
||||
Class representing a Chat-GPT3 Telegram Bot.
|
||||
"""
|
||||
|
||||
def __init__(self, config: dict, gpt3_bot: ChatGPT3Bot):
|
||||
"""
|
||||
Initializes the bot with the given configuration and GPT-3 bot object.
|
||||
@@ -37,7 +38,8 @@ class ChatGPT3TelegramBot:
|
||||
Handles the /start command.
|
||||
"""
|
||||
if not self.is_allowed(update):
|
||||
logging.info(f'User {update.message.from_user.name} is not allowed to start the bot')
|
||||
logging.info(
|
||||
f'User {update.message.from_user.name} is not allowed to start the bot')
|
||||
await self.send_disallowed_message(update, context)
|
||||
return
|
||||
|
||||
@@ -49,7 +51,8 @@ class ChatGPT3TelegramBot:
|
||||
Resets the conversation.
|
||||
"""
|
||||
if not self.is_allowed(update):
|
||||
logging.info(f'User {update.message.from_user.name} is not allowed to reset the bot')
|
||||
logging.info(
|
||||
f'User {update.message.from_user.name} is not allowed to reset the bot')
|
||||
await self.send_disallowed_message(update, context)
|
||||
return
|
||||
|
||||
@@ -70,11 +73,13 @@ class ChatGPT3TelegramBot:
|
||||
React to incoming messages and respond accordingly.
|
||||
"""
|
||||
if not self.is_allowed(update):
|
||||
logging.info(f'User {update.message.from_user.name} is not allowed to use the bot')
|
||||
logging.info(
|
||||
f'User {update.message.from_user.name} is not allowed to use the bot')
|
||||
await self.send_disallowed_message(update, context)
|
||||
return
|
||||
|
||||
logging.info(f'New message received from user {update.message.from_user.name}')
|
||||
logging.info(
|
||||
f'New message received from user {update.message.from_user.name}')
|
||||
|
||||
# Send "Typing..." action periodically every 4 seconds until the response is received
|
||||
typing_task = asyncio.get_event_loop().create_task(
|
||||
@@ -134,7 +139,8 @@ class ChatGPT3TelegramBot:
|
||||
application.add_handler(CommandHandler('start', self.start))
|
||||
application.add_handler(CommandHandler('reset', self.reset))
|
||||
application.add_handler(CommandHandler('help', self.help))
|
||||
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), self.prompt))
|
||||
application.add_handler(MessageHandler(
|
||||
filters.TEXT & (~filters.COMMAND), self.prompt))
|
||||
|
||||
application.add_error_handler(self.error_handler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user