-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-bot.py
183 lines (144 loc) · 6.93 KB
/
test-bot.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
################################################################
# Chanka Bot
# ----------------------------------------------------------------
# uses openwa library
from openwa import WhatsAPIDriver
import json
import time
from Mods.ReplyMods import replymods as RM #NOTE:all the mods are saved in this module you can ad new modules there
from PIL import Image
import qrcode
#NOTE: this is used get UserConfig data from UserConfig.json
with open("UserConfig.json","r") as f:
d = f.read()
config_data = json.loads(d)
help_msg = config_data.get("HELP_MSG")
prefix = config_data.get("PREFIX")
owner = config_data.get("OWNER")
groups = config_data.get("GROUPS")
flag = 0
#NOTE:This inisitaes the driver from whatsapp web app and authenictes by scaning
# driver = WhatsAPIDriver(client="chrome",executable_path="chromedriver.exe",headless=False,chrome_options=['--disable-gpu'])
driver = WhatsAPIDriver(client="chrome",executable_path="chromedriver.exe",headless=True)
def qrprinter(barcode_url):
qr = qrcode.QRCode()
qr.add_data(barcode_url)
#invert=True Black block on white, some apps don't recognize black and white blocks.
qr.print_ascii(invert=True)
#NOTE:this class is used for receving and handling message
class NewMessageObserver:
def on_message_received(self, new_messages):
for message in new_messages:
print(f"New message {message} received from number {message.sender.id}")
if message.content.startswith(prefix):
if message.content == f"{prefix}quote":
RM.replyQuote(message)
elif message.content == f"{prefix}help":
RM.replyHelp(message)
elif message.content == f"{prefix}noods":
RM.replyNoods(message)
elif message.content == f"{prefix}menu":
RM.replyMenu(message)
elif message.content == f"{prefix}namo":
RM.replyNamo(message, driver=driver)
elif f"{prefix}namo " in message.content:
count = int(message.content.split(" ")[1])
RM.replyNamo(message, driver=driver, count=count)
elif message.content == f"{prefix}ping":
RM.replyPing(message)
elif message.content == f"{prefix}sticker":
RM.replySticker(message, driver=driver)
elif message.content == f"{prefix}gif":
RM.replyVideoToGif(message, driver=driver)
elif message.content.startswith(f"{prefix}memes"):
content_list = message.content.split(" ")
if len(content_list) == 2:
RM.replySr(message, driver=driver, count=int(content_list[-1]))
else:
RM.replySr(message, driver=driver)
elif message.content.startswith(f"{prefix}sr"):
content_list = message.content.split(" ")
if len(content_list) == 2:
RM.replySr(message, driver=driver,query=content_list[-1])
elif len(content_list) == 3:
RM.replySr(message, driver=driver,query=content_list[-2],count=int(content_list[-1]))
else:
message.reply_message("First lean how to use this command, Biyath.")
elif message.content.startswith(f"{prefix}say:"):
content_list = message.content.split(':')
if len(content_list) == 2:
text = content_list[-1]
RM.replySay(message,text,driver=driver)
elif len(content_list) == 3:
text = content_list[-2]
lang = content_list[-1]
RM.replySay(message,text,driver=driver,lang=lang)
else:
text=""
RM.replySay(message,text,driver=driver)
elif message.content.startswith(f"{prefix}r6p"):
content_list = message.content.split(" ")
text = content_list[-1]
RM.replyRsixP(message,text,driver=driver)
elif message.content.startswith(f"{prefix}r6t"):
content_list = message.content.split(" ")
text = content_list[-1]
RM.replyRsixT(message,text,driver=driver)
elif message.content.startswith(f"{prefix}r6s"):
content_list = message.content.split(" ")
if len(content_list) == 2:
p = content_list[-1]
RM.replyRsixS(message,p,driver=driver)
elif content_list == 3:
p = content_list[2]
pl = content_list[1]
RM.replyRsixS(message,p,pl,driver=driver)
else:
message.reply_message("Command use krna sikh bhosad.")
else:
RM.replyModError(message)
else:
pass
print("Waiting for QR")
qrprinter(driver.get_qr_plain())
while not driver.wait_for_login():
time.sleep(3)
print("Saving session")
# driver.save_firefox_profile(remove_old=False)
print("Bot started")
#NOTE:this is used to subscribe message handling class to the driver
driver.subscribe_new_messages(NewMessageObserver())
#NOTE: loop is infinite coz of continues listning of messages
while(True):
time.sleep(60)
# while True:
# if driver.wait_for_login():
# #starting bot
# print("*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# driver.chat_send_message(owner,"*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# groups = driver.get_all_groups()
# # for group in groups:
# # group.send_message("*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# break
# else:
# pass
# while not driver.wait_for_login():
# pass
#starting bot
# print("*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# driver.chat_send_message(owner,"*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# groups = driver.get_all_groups()
# for group in groups:
# group.send_message("*Lord is Back* 👑 ⚒ 🙋 🎁 ")
# def replyMission(message):
# if message.sender.id == owner:
# #bot stopped
# print("*Lord is going on mission* 👨🚒 💂 🔫 ⚠ \n*he will be back*\n\n*WISH HIM LUCK 👍*")
# driver.chat_send_message(owner,"*Lord is going on mission* 👨🚒 💂 🔫 ⚠ \n*he will be back*\n\n*WISH HIM LUCK 👍*")
# # groups = driver.get_all_groups()
# # for group in groups:
# # group.send_message("*Lord is going on mission* 👨🚒 💂 🔫 ⚠ \n*he will be back*\n\n*WISH HIM LUCK 👍*")
# return 1
# else:
# message.reply_message("*You are not my boss.*\n\n _Only chevi sensei can send to me to the mission._")
# return 0