-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignmentBot.py
166 lines (147 loc) · 7.81 KB
/
assignmentBot.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
import os
import random
import telebot
from khayyam import JalaliDatetime
from gtts import gTTS
import qrcode
TOKEN = os.environ['TOKEN']
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['Start', 'start'])
def wellcome(message):
first_name = message.from_user.first_name
bot.reply_to(message, f'Hey {first_name}, Welcome 😃')
@bot.message_handler(commands=['Game', 'game'])
def play_game(message):
bot.reply_to(message, 'Guess the number 🎯')
msg = bot.send_message(message.chat.id, 'Tell me a number between 0 and 1000 ...')
bot.register_next_step_handler(msg, game)
def game(msg):
ANSWER_NUMBER = random.randint(0, 1000)
def game_works(message):
markUp = telebot.types.ReplyKeyboardMarkup(row_width=1)
button_1 = telebot.types.KeyboardButton('New Game ? 🤔')
markUp.add(button_1)
try:
if int(message.text) > ANSWER_NUMBER:
msg = bot.send_message(message.chat.id, 'Come DOWN :D', reply_markup=markUp)
bot.register_next_step_handler(msg, game_works)
elif int(message.text) < ANSWER_NUMBER:
msg = bot.send_message(message.chat.id, 'Go UP :D', reply_markup=markUp)
bot.register_next_step_handler(msg, game_works)
elif int(message.text) == ANSWER_NUMBER:
msg = bot.send_message(message.chat.id, "That's Right 😍\nGood job buddy 👊", reply_markup=telebot.types.ReplyKeyboardRemove(selective=True))
elif message.text == 'New Game ? 🤔':
print('1')
bot.send_message(message.chat.id, 'Guess the number 🎯 \nTell me a number between 0 and 1000 ...', reply_markup=telebot.types.ReplyKeyboardRemove(selective=True))
bot.register_next_step_handler_by_chat_id(message.chat.id, game)
except:
bot.reply_to(message, 'Did something happen? 😟\nLeave the game to check the rest of your needs.', reply_markup=telebot.types.ReplyKeyboardRemove(selective=True))
game_works(msg)
@bot.message_handler(commands=['Age', 'age'])
def calculate_age(message):
msg = bot.send_message(message.chat.id, 'Please tell me your date of birth (Jalali-Shamsi)\n📌Example: 27/4/1379')
bot.register_next_step_handler(msg, age_works)
def age_works(message):
slash_counter = 0
for letter in message.text:
if letter == '/':
slash_counter += 1
if slash_counter == 2:
input_text = message.text
input_list = input_text.split('/')
try:
difference = JalaliDatetime.now() - JalaliDatetime(input_list[2], input_list[1], input_list[0])
if ',' not in str(difference):
y = 0
m = 0
d = 0
else:
difference = int(((str(difference)).split(' '))[0])
y = difference // 365
difference %= 365
m = difference // 30
difference %= 30
d = difference
if y < 0:
bot.send_message(message.chat.id, 'Wrong input!')
elif y != 0 and m == 0 and d == 0: # y
bot.send_message(message.chat.id, f'HAPPY BIRTHDAY 🎈🎂\nYou are {y} years old 😍')
elif y != 0 and m != 0 and d == 0: # y m
bot.send_message(message.chat.id, f'You are {y} years and {m} months old :)\nBe healthy ❤')
elif y != 0 and m == 0 and d != 0: # y d
bot.send_message(message.chat.id, f'You are {y} years and {d} days old :)\nBe healthy ❤')
elif y != 0 and m != 0 and d != 0: # y m d
bot.send_message(message.chat.id, f'You are {y} years, {m} months and {d} days old :)\nBe healthy ❤')
elif y == 0 and m != 0 and d == 0: # m
bot.send_message(message.chat.id, f'You are {m} months old :)\nBe healthy 🤍')
elif y == 0 and m != 0 and d != 0: # m d
bot.send_message(message.chat.id, f'You are {m} months and {d} days old :)\nBe healthy 🤍')
elif y == 0 and m == 0 and d != 0: # d
bot.send_message(message.chat.id, f'You are {d} days old :)\nBe healthy 🤍')
elif y == 0 and m == 0 and d == 0: #
bot.send_message(message.chat.id, 'Welcome to this world, my dear 🎊👶')
except:
bot.send_message(message.chat.id, 'Wrong input!')
else:
bot.send_message(message.chat.id, 'Wrong input!')
@bot.message_handler(commands=['Voice', 'voice'])
def voice_producer(message):
msg = bot.send_message(message.chat.id, 'Enter your message')
bot.register_next_step_handler(msg, voice_works)
def voice_works(message):
try:
message_text = message.text
language = 'en'
message_voice = gTTS(text=message_text, lang=language, slow=False)
message_voice.save('your_voice.ogg')
voice = open('your_voice.ogg', 'rb')
bot.send_voice(message.chat.id, voice)
except:
bot.send_message(message.chat.id, 'WARNING ⚠\nPlease try again')
@bot.message_handler(commands=['Qrcode', 'qrcode'])
def qrcode_producer(message):
msg = bot.send_message(message.chat.id, 'Enter text or web address or ...\n🔑 Example: www.google.com')
bot.register_next_step_handler(msg, qrcode_works)
def qrcode_works(message):
try:
message_text = message.text
qrcode_image = qrcode.make(message_text)
qrcode_image.save('your_qrcode.png')
qrCode = open('your_qrcode.png', 'rb')
bot.send_photo(message.chat.id, qrCode)
except:
bot.send_message(message.chat.id, 'WARNING ⚠\nPlease try again')
@bot.message_handler(commands=['max', 'Max', 'MAX'])
def maxx(message):
Description = "Write a list of your numbers (each separated by a ',')\nI will find the largest number and tell you 😎"
msg = bot.send_message(message.chat.id, Description)
bot.register_next_step_handler(msg, max_works)
def max_works(message):
try:
numbers_text = message.text
numbers_list = numbers_text.split(',')
numbers_list = list(map(int, numbers_list))
answer = str(max(numbers_list))
bot.send_message(message.chat.id, f'The largest number is {answer}')
except:
bot.send_message(message.chat.id, "WARNING ⚠\nDo you just enter numbers and ','? 🤔\nPlease try again")
@bot.message_handler(commands=['argmax', 'Argmax'])
def argmaxx(message):
Description = "Write a list of your numbers (each separated by a ',')\nI will find the largest number and tell you its index 🧠\nList index starts from 0 ☺"
msg = bot.send_message(message.chat.id, Description)
bot.register_next_step_handler(msg, arg_works)
def arg_works(message):
try:
numbers_text = message.text
numbers_list = numbers_text.split(',')
numbers_list = list(map(int, numbers_list))
answer_1 = str(max(numbers_list))
answer_2 = str(numbers_list.index(max(numbers_list)))
bot.send_message(message.chat.id, f'The largest number: {answer_1}\nIts index: {answer_2}')
except:
bot.send_message(message.chat.id, "WARNING ⚠\nDo you just enter numbers and ','? 🤔\nPlease try again")
@bot.message_handler(commands=['help', 'Help', 'HELP'])
def help(message):
Description = '1️⃣ /start : start and welcome\n2️⃣ /game : Play game\n3️⃣ /age : Your age\n4️⃣ /voice : text to voice\n5️⃣ /max : maximum in list\n6️⃣ /argmax : highest number argument in list\n7️⃣ /qrcode : product QR code\n\nAli Yaghoubian 👨💻\nSupport: @Alijackoub'
bot.send_message(message.chat.id, Description)
bot.polling()