-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
94 lines (73 loc) · 3.66 KB
/
main.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
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery, constants, error
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, ContextTypes
import tempmail
import config
import logging
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(f"""
Hello {update.effective_user.first_name}
Welcome to @FakeMaiilRobot.
""", reply_markup=buttons)
async def query_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
query: CallbackQuery = update.callback_query.data
chat_id = update.callback_query.from_user.id
try:
# if email not exist
if not context.user_data:
if query == "generate":
email = tempmail.generate()
context.user_data["email"] = email
await update.callback_query.edit_message_text(text=f"__**Your Temporary E-mail**__ : `{email}`", reply_markup=buttons, parse_mode=constants.ParseMode.MARKDOWN)
else:
await update.callback_query.edit_message_text(text="You Need to Generate an email", reply_markup=buttons)
# elif user have an email
elif context.user_data:
email = context.user_data["email"]
username, domain = email.split("@")
if query == "refresh":
try:
email_id, email_from, email_subject, email_date, email_text, files = tempmail.refresh(
username, domain)
files_text = "\n".join(files) if files else ""
text = f"""
➖➖➖➖➖➖➖➖➖
From: <{email_from}>
To: <{email}>
Date: {email_date}
Attachments: {files_text}
➖➖➖➖➖➖➖➖➖
Subject: {email_subject}
➖➖➖➖➖➖➖➖➖
{email_text}
"""
await context.bot.send_message(chat_id, text, disable_web_page_preview=True)
except ValueError:
await update.callback_query.edit_message_text(text="No Messages Were Received..", parse_mode=constants.ParseMode.MARKDOWN, reply_markup=buttons)
elif query == "my_email":
await update.callback_query.edit_message_text(text=f"__**Your Temporary E-mail**__ : `{email}`", parse_mode=constants.ParseMode.MARKDOWN, reply_markup=buttons)
elif query == "close":
context.user_data.clear()
await update.callback_query.edit_message_text(text="Session Closed✅\n/start")
else:
await update.callback_query.edit_message_text(text="To Change The Email, You Must Close The Session First", reply_markup=buttons, parse_mode=constants.ParseMode.MARKDOWN)
except error.BadRequest:
pass
except:
await update.callback_query.edit_message_text(text="Service Unavailable,Please Try Again Later", reply_markup=buttons)
if __name__ == "__main__":
try:
logging.basicConfig(filename='errors.log', level=logging.ERROR,
format='%(asctime)s %(levelname)s: %(message)s')
buttons = InlineKeyboardMarkup([
[InlineKeyboardButton('Generate📥', callback_data='generate')],
[InlineKeyboardButton('Refresh🔄', callback_data='refresh'),
InlineKeyboardButton('My Email📬', callback_data='my_email')],
[InlineKeyboardButton('Close🚫', callback_data='close')]
])
app = ApplicationBuilder().token(config.token).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CallbackQueryHandler(query_handler))
print("Bot is Alive")
app.run_polling()
except Exception as e:
logging.error(str(e))