Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 3e93250

Browse files
authored
Create lydia.py
1 parent a0b85f5 commit 3e93250

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

userbot/modules/lydia.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2019 - 2020 AviPatilPro
2+
3+
4+
from coffeehouse.lydia import LydiaAI
5+
from coffeehouse.api import API
6+
import asyncio
7+
from telethon import events
8+
9+
# Non-SQL Mode
10+
ACC_LYDIA = {}
11+
12+
if Var.LYDIA_API_KEY:
13+
api_key = Var.LYDIA_API_KEY
14+
api_client = API(api_key)
15+
lydia = LydiaAI(api_client)
16+
17+
@command(pattern="^.repcf", outgoing=True)
18+
async def repcf(event):
19+
if event.fwd_from:
20+
return
21+
await event.edit("Processing...")
22+
try:
23+
session = lydia.create_session()
24+
session_id = session.id
25+
reply = await event.get_reply_message()
26+
msg = reply.text
27+
text_rep = session.think_thought(msg)
28+
await event.edit("💫 {0}".format(text_rep))
29+
except Exception as e:
30+
await event.edit(str(e))
31+
32+
@command(pattern="^.addcf", outgoing=True)
33+
async def addcf(event):
34+
if event.fwd_from:
35+
return
36+
await event.edit("Running on Non-SQL mode for now...")
37+
await asyncio.sleep(3)
38+
await event.edit("Processing...")
39+
reply_msg = await event.get_reply_message()
40+
if reply_msg:
41+
session = lydia.create_session()
42+
session_id = session.id
43+
if reply_msg.from_id is None:
44+
return await event.edit("Invalid user type.")
45+
ACC_LYDIA.update({(event.chat_id & reply_msg.from_id): session})
46+
await event.edit("Lydia successfully (re)enabled for user: {} in chat: {}".format(str(reply_msg.from_id), str(event.chat_id)))
47+
else:
48+
await event.edit("Reply to a user to activate Lydia AI on them")
49+
50+
@command(pattern="^.remcf", outgoing=True)
51+
async def remcf(event):
52+
if event.fwd_from:
53+
return
54+
await event.edit("Running on Non-SQL mode for now...")
55+
await asyncio.sleep(3)
56+
await event.edit("Processing...")
57+
reply_msg = await event.get_reply_message()
58+
try:
59+
del ACC_LYDIA[event.chat_id & reply_msg.from_id]
60+
await event.edit("Lydia successfully disabled for user: {} in chat: {}".format(str(reply_msg.from_id), str(event.chat_id)))
61+
except Exception:
62+
await event.edit("This person does not have Lydia activated on him/her.")
63+
64+
65+
@bot.on(events.NewMessage(incoming=True))
66+
async def user(event):
67+
user_text = event.text
68+
try:
69+
session = ACC_LYDIA[event.chat_id & event.from_id]
70+
msg = event.text
71+
async with event.client.action(event.chat_id, "typing"):
72+
text_rep = session.think_thought(msg)
73+
wait_time = 0
74+
for i in range(len(text_rep)):
75+
wait_time = wait_time + 0.1
76+
await asyncio.sleep(wait_time)
77+
await event.reply(text_rep)
78+
except (KeyError, TypeError):
79+
return

0 commit comments

Comments
 (0)