File size: 2,944 Bytes
9f99fe2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import logging
import os
import sys
import threading

sys.path.insert(0, "src")
os.environ['TRANSFORMERS_CACHE'] = '/tmp'

from telegram.ext import (
    CommandHandler,
    CallbackContext,
    Application,
    ContextTypes,
)
from api import GirlfriendGPT
from functools import partial  
from typing import List
from telegram import Update
from termcolor import colored

SELECT_COMMAND, GET_TEXT = range(2)

# Enable logging
logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)

# def show_results(response_messages):
#     print(colored("\nResults: ", "blue", attrs=["bold"]))
#     for message in response_messages:
#         if message.mime_type:
#             print(message.url, end="\n\n")
#         else:
#             print(message.text, end="\n\n")


def shutdown(updater: Update):
    updater.stop()
    updater.is_idle = False

def stop(update):
    threading.Thread(target=shutdown(updater=update)).start()

async def hello(update: Update, context: CallbackContext) -> None:
    intro_text = f"🤖 Greetings human!🤗\nI'm a bot built by Rexthecoder\n🦾 I can do a lot of things"
    await update.message.reply_text(intro_text)


# async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
#     """Echo the user message."""
#     await update.message.reply_text("Enter your text")
#     return GET_TEXT


class LoggingDisabled:
    """Context manager that turns off logging within context."""

    def __enter__(self):
        logging.disable(logging.CRITICAL)

    def __exit__(self, exit_type, exit_value, exit_traceback):
        logging.disable(logging.NOTSET)


def main():
    app = Application.builder().token(
        '6207542226:AAEoNVXw766dq8fYqVvBQW9Hve2Rovq0ERI',).build()
    # application = Application.builder().token('6207542226:AAGXBVVxNNUKLUz17-5_sGJnhFDaVWUXTc8').build()
    # application.add_handler(CommandHandler('start', hello))

    # # Run the bot until the user presses Ctrl-C
    # application.run_polling()
    run_agent(
        agent=GirlfriendGPT(
            token="hello",
            application=app
        )
    )
    print(f"Starting Agent...")


def run_agent(agent: GirlfriendGPT, as_api: bool = False) -> None:
    # For Debugging
    summary_handler = agent.conversation_summary_handler()
    agent.application.add_handler(summary_handler)
    agent.application.add_handler(CommandHandler('stop', stop))
    agent.application.add_handler(CommandHandler('start', hello))
    # agent.application.add_handler(CommandHandler('summary', agent.conversation_summary))
    # agent.application.add_handler(MessageHandler(
    #     filters.TEXT & ~filters.COMMAND, agent.create_response))
    agent.application.run_polling()
    # agent.application.add_handler(MessageHandler(
    #     filters.TEXT & ~filters.COMMAND, agent.create_response))


if __name__ == "__main__":
    main()