forked from TheHamkerCat/LunaChatBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluna.py
164 lines (142 loc) · 4.87 KB
/
luna.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import aiohttp
import asyncio
import re
from sample_config import bot_token, owner_id, bot_id
from pyrogram import Client, filters
luna = Client(
":memory:",
bot_token=bot_token,
api_id=6,
api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e",
)
blacklisted = []
mode = None
async def getresp(query):
url = f"https://lunabot.tech/?query={query}"
async with aiohttp.ClientSession() as session:
async with session.get(url) as res:
res = await res.json()
text = res["response"]
return text
@luna.on_message(filters.command("repo") & ~filters.edited)
async def repo(_, message):
await message.reply_text(
"[Github](https://github.com/thehamkercat/LunaChatBot)"
+ " | [Group](t.me/PatheticProgrammers)", disable_web_page_preview=True)
@luna.on_message(filters.command("help") & ~filters.edited)
async def start(_, message):
user_id = message.from_user.id
if user_id in blacklisted:
return
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text(
"**Only For Owners**\n/shutdown - `Shutdown Luna.`\n/blacklist - `Blacklist A User.`\n/whitelist - `Whitelist A User.`"
)
@luna.on_message(filters.command("shutdown") & filters.user(owner_id) & ~filters.edited)
async def shutdown(_, message):
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("**Shutted Down!**")
print("Exited!")
exit()
@luna.on_message(filters.command("blacklist") & filters.user(owner_id) & ~filters.edited)
async def blacklist(_, message):
global blacklisted
if not message.reply_to_message:
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Reply To A User's Message To Blacklist.")
return
victim = message.reply_to_message.from_user.id
if victim in blacklisted:
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Already Blacklisted Lol.")
return
blacklisted.append(victim)
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Blacklisted.")
@luna.on_message(filters.command("whitelist") & filters.user(owner_id) & ~filters.edited)
async def whitelist(_, message):
global blacklisted
if not message.reply_to_message:
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Reply To A User's Message To Whitelist.")
return
victim = message.reply_to_message.from_user.id
if victim not in blacklisted:
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Already Whitelisted Lol.")
return
blacklisted.remove(victim)
await luna.send_chat_action(message.chat.id, "typing")
await message.reply_text("Whitelisted.")
@luna.on_message(
~filters.private &
~filters.command("blacklist")
& ~filters.command("shutdown")
& ~filters.command("help")
& ~filters.edited
)
async def chat(_, message):
if message.from_user.id in blacklisted:
return
if message.reply_to_message:
if not message.reply_to_message.from_user.id == bot_id:
return
await luna.send_chat_action(message.chat.id, "typing")
if not message.text:
query = "Hello"
else:
query = message.text
if len(query) > 50:
return
try:
res = await getresp(query)
await asyncio.sleep(1)
except Exception as e:
res = str(e)
await message.reply_text(res)
await luna.send_chat_action(message.chat.id, "cancel")
else:
if message.text:
query = message.text
if len(query) > 50:
return
if re.search("[.|\n]{0,}[l|L][u|U][n|N][a|A][.|\n]{0,}", query):
await luna.send_chat_action(message.chat.id, "typing")
try:
res = await getresp(query)
await asyncio.sleep(1)
except Exception as e:
res = str(e)
await message.reply_text(res)
await luna.send_chat_action(message.chat.id, "cancel")
@luna.on_message(
filters.private
& ~filters.command("blacklist")
& ~filters.command("shutdown")
& ~filters.command("help")
& ~filters.edited
)
async def chatpm(_, message):
if message.from_user.id in blacklisted:
return
if not message.text:
return
await luna.send_chat_action(message.chat.id, "typing")
query = message.text
if len(query) > 50:
return
try:
res = await getresp(query)
await asyncio.sleep(1)
except Exception as e:
res = str(e)
await message.reply_text(res)
await luna.send_chat_action(message.chat.id, "cancel")
print(
"""
-----------------
| Luna Started! |
-----------------
"""
)
luna.run()