-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminBot.py
174 lines (162 loc) · 5.75 KB
/
AdminBot.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
from telegram import *
from telegram.ext import *
import MainBot
import random
import AIBot
import json
APIKey = "<--- bot key --->"
MyBot = Bot(APIKey)
UpdateMyBot = Updater(APIKey,use_context=True)
DispatchUpToBot = UpdateMyBot.dispatcher
VerifyPassword = range(1)
def AdminAccis(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Ok, Enter Password"
)
return VerifyPassword
def AdminOwnership(update:Update,context:CallbackContext):
password = update.message.text
passwdFile = open("botData.json",'r')
dataFetched = json.load(passwdFile)
seepasswd = dataFetched['password']
passwdFile.close()
if(password.lower()==seepasswd):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Hello Sir/Mam,\nGreat to see you here.. to see gides click on\n[ /Admingide ]"
)
CAccessPass = open("botData.json",'r')
CeditAccessdata = json.load(CAccessPass)
CAccessPass.close()
if(int(update.effective_chat.id) not in CeditAccessdata["admin"]):
AccessPass = open("botData.json",'w')
CeditAccessdata["admin"].append(int(update.effective_chat.id))
json.dump(CeditAccessdata,AccessPass,indent=4)
AccessPass.close()
else:
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Access Denide! Sorry"
)
return ConversationHandler.END
def userIDlist():
ID = open("botData.json",'r')
dataFetchedID = json.load(ID)
IDList = dataFetchedID["users"]
ID.close()
return IDList
def isAllow(id):
AccessPassAllow = open("botData.json",'r')
idpass = json.load(AccessPassAllow)
status = 0
adminList = idpass["admin"]
if(id in adminList):
status = 1
else:
status = 0
AccessPassAllow.close()
if(status == 1):
return True
else:
return False
def control(update:Update,context:CallbackContext):
commandGiven = update.message.text
if(commandGiven in ["bye","bubye","byeeeee","Bye","ttyl"]):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Bye bye dear... it was great to spend time with you."
)
elif(commandGiven.lower()=="server name"):
if(isAllow(update.effective_chat.id)):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "VAIO Sony Laptop"
)
else:
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "This access are only given to Admin.So, Sorry!"
)
elif(commandGiven.lower()=="total users"):
if(isAllow(update.effective_chat.id)):
see_noOfusers = open("botData.json",'r')
totalUsers = json.load(see_noOfusers)
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Total {} users are using this bot now.".format(len(totalUsers["users"]))
)
see_noOfusers.close()
else:
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "This access are only given to Admin.So, Sorry!"
)
else:
reply = AIBot.commandsGiven(commandGiven.lower())
if(reply != None):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = reply
)
else:
ai_reply = AIBot.aiReply(commandGiven.lower())
MyBot.send_message(
chat_id = update.effective_chat.id,
text = ai_reply
)
def adminGide(update:Update,context:CallbackContext):
if(isAllow(update.effective_chat.id)):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = MainBot.datatoRead("AdminGide.txt")
)
else:
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "This access are only given to Admin.So, Sorry!"
)
sendnoticetousers = range(1)
def notice(update:Update,context:CallbackContext):
if(isAllow(update.effective_chat.id)):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "So, what is the message that you want to sent to all users..."
)
return sendnoticetousers
else:
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "This access are only given to Admin.So, Sorry!"
)
return ConversationHandler.END
def sendnotice(update:Update,context:CallbackContext):
noticeis = update.message.text
for i in userIDlist():
if(i!=""):
MyBot.send_message(
chat_id = int(i),
text = noticeis
)
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "noticed has been send to everyone.."
)
return ConversationHandler.END
seeLocation = range(1)
def askingWeather(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "So, send your location :"
)
return seeLocation
def weatherReport(update:Update,context:CallbackContext):
userslocation = update.message.location
lon = userslocation["longitude"]
lat = userslocation["latitude"]
forecast = AIBot.weather(lon,lat)
MyBot.send_message(
chat_id = update.effective_chat.id,
text = forecast
)
return ConversationHandler.END