-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainBot.py
161 lines (146 loc) · 5.6 KB
/
MainBot.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
from telegram import *
from telegram.ext import *
import random
import json
import AdminBot
APIKey = "<--- bot key --->"
MyBot = Bot(APIKey)
UpdateMyBot = Updater(APIKey,use_context=True)
DispatchUpToBot = UpdateMyBot.dispatcher
def datatoRead(filename):
filename = open(filename,'r')
see = filename.readlines()
data = ""
for i in see:
data = data + i
return data
def SayingThought(update:Update,context:CallbackContext):
thoughtsfile = open("thoughts.txt",'r')
takethoughts = thoughtsfile.readlines()
pickAnyOne = random.randint(0,len(takethoughts))
MyBot.send_message(
chat_id = update.effective_chat.id,
text = takethoughts[pickAnyOne]
)
def StartChatting(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = datatoRead("startgide.txt")
)
if(update.effective_chat.id not in AdminBot.userIDlist()):
userIDdetails = open("botData.json",'r')
dataLoadofusers = json.load(userIDdetails)
userIDdetails.close()
adduserID = open("botData.json",'w')
dataLoadofusers["users"].append(update.effective_chat.id)
json.dump(dataLoadofusers,adduserID,indent=4)
adduserID.close()
def TheNewthings(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = datatoRead("whatsnew.txt")
)
sendingfeed = range(1)
def UserFeedBack(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "That's great your feedback is really have a huge value for us.. So, Start typing your feedback :"
)
return sendingfeed
def TQforfeeds(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "FeedBack Page Close"
)
return ConversationHandler.END
def feedbacktyper(update:Update,context:CallbackContext):
thefeedback = update.message.text
FeedBackfile = open('FeedBackPage.txt','a')
data = '\nUserID{}: Feedback is :- {}'.format(update.effective_chat.id,thefeedback)
FeedBackfile.write(data)
FeedBackfile.close()
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "ThankYou for your feedback..."
)
return ConversationHandler.END
EchoChat,EchoSticker = range(2)
def startingEcho(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Starting the Echo.\n[For stoping echo: /stopecho]"
)
return EchoChat,EchoSticker
def echoTheText(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = update.message.text
)
def echoTheSticker(update:Update,context:CallbackContext):
MyBot.send_sticker(
chat_id = update.effective_chat.id,
sticker = update.message.sticker.file_id
)
def stopingEcho(update:Update,context:CallbackContext):
MyBot.send_message(
chat_id = update.effective_chat.id,
text = "Echo is stoped now"
)
return ConversationHandler.END
def mainControl():
StartChat = CommandHandler("start",StartChatting)
WhatsNew = CommandHandler(["whatsnew","help"],TheNewthings)
AdminGide = CommandHandler("admingide",AdminBot.adminGide)
FeedBack = ConversationHandler(
entry_points=[CommandHandler("feedback",UserFeedBack)],
states={sendingfeed:[MessageHandler(Filters.text,feedbacktyper)]},
fallbacks=[CommandHandler("sendfeed",TQforfeeds),MessageHandler(Filters.text,feedbacktyper)]
)
Thought = CommandHandler(["saythought","quote"],SayingThought)
EchoState = ConversationHandler(
entry_points=[CommandHandler(["startecho"],startingEcho)],
states={
EchoChat:[MessageHandler(Filters.text,echoTheText)],
EchoSticker:[MessageHandler(Filters.sticker,echoTheSticker)]
},
fallbacks=[
CommandHandler(["stopecho"],stopingEcho),
MessageHandler(Filters.text,echoTheText),
MessageHandler(Filters.sticker,echoTheSticker)
]
)
AdminPass = ConversationHandler(
entry_points=[CommandHandler(["admin"],AdminBot.AdminAccis)],
states={
AdminBot.VerifyPassword:[MessageHandler(Filters.text,AdminBot.AdminOwnership)]
},
fallbacks=[MessageHandler(Filters.text,AdminBot.AdminOwnership)]
)
NoticeSender = ConversationHandler(
entry_points=[CommandHandler(["notice"],AdminBot.notice)],
states={
AdminBot.sendnoticetousers:[MessageHandler(Filters.text,AdminBot.sendnotice)]
},
fallbacks=[MessageHandler(Filters.text,AdminBot.sendnotice)]
)
UsersLocation = ConversationHandler(
entry_points=[CommandHandler(["weather"],AdminBot.askingWeather)],
states={
AdminBot.seeLocation:[MessageHandler(Filters.location,AdminBot.weatherReport)]
},
fallbacks=[MessageHandler(Filters.location,AdminBot.weatherReport)]
)
Admincontrol = MessageHandler(Filters.text,AdminBot.control)
DispatchUpToBot.add_handler(AdminPass)
DispatchUpToBot.add_handler(NoticeSender)
DispatchUpToBot.add_handler(StartChat)
DispatchUpToBot.add_handler(AdminGide)
DispatchUpToBot.add_handler(UsersLocation)
DispatchUpToBot.add_handler(WhatsNew)
DispatchUpToBot.add_handler(FeedBack)
DispatchUpToBot.add_handler(Thought)
DispatchUpToBot.add_handler(EchoState)
DispatchUpToBot.add_handler(Admincontrol)
UpdateMyBot.start_polling()
if __name__ == "__main__":
mainControl()