-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
150 lines (123 loc) · 3.92 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
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
import os
from dotenv import load_dotenv
from weather import get_weather
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
load_dotenv()
Bot = Client(
"Weather-Bot",
bot_token = os.environ["BOT_TOKEN"],
api_id = int(os.environ["API_ID"]),
api_hash = os.environ["API_HASH"]
)
START_TEXT = """Hello {},
I am a weather information finding bot. \
Give me a country/city/place name, \
I will send the weather informations about the place."""
HELP_TEXT = """**More Help**
- Just send me a country/city/place name
- Then I will check and send you the informations
**Informations :-**
Location details, current weather conditions \
(includes air quality details)"""
ABOUT_TEXT = """**About Me**
- **Bot :** `Weather Bot`
- **Creator :**
- [Telegram](https://telegram.me/FayasNoushad)
- [GitHub](https://github.com/FayasNoushad)
- **Source :** [Click here](https://github.com/FayasNoushad/Weather-Bot/tree/main)
- **Language :** [Python3](https://python.org)
- **Framework :** [Pyrogram](https://pyrogram.org)"""
START_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Send Feedback', url='https://telegram.me/FayasNoushad')
],
[
InlineKeyboardButton('Help', callback_data='help'),
InlineKeyboardButton('About', callback_data='about'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
HELP_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Home', callback_data='home'),
InlineKeyboardButton('About', callback_data='about'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
ABOUT_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Home', callback_data='home'),
InlineKeyboardButton('Help', callback_data='help'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
ERROR_BUTTON = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Help', callback_data='help'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
@Bot.on_callback_query()
async def cb_data(bot, update):
if update.data == "home":
await update.message.edit_text(
text=START_TEXT.format(update.from_user.mention),
reply_markup=START_BUTTONS,
disable_web_page_preview=True
)
elif update.data == "help":
await update.message.edit_text(
text=HELP_TEXT,
reply_markup=HELP_BUTTONS,
disable_web_page_preview=True
)
elif update.data == "about":
await update.message.edit_text(
text=ABOUT_TEXT,
reply_markup=ABOUT_BUTTONS,
disable_web_page_preview=True
)
else:
await update.message.delete()
@Bot.on_message(filters.private & filters.command(["start"]))
async def start(bot, update):
await update.reply_text(
text=START_TEXT.format(update.from_user.mention),
disable_web_page_preview=True,
reply_markup=START_BUTTONS
)
@Bot.on_message(filters.private & filters.text)
async def weatherinfo(bot, update):
try:
details = get_weather(update.text)
except KeyError:
await update.reply_text(
text="Key error.\nCan you check the name again."
)
return
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton('Send Feedback', url='https://telegram.me/FayasNoushad')]
])
try:
for i in details:
await update.reply_text(
text=i,
disable_web_page_preview=True
)
await update.reply_text(
text="Thanks for using me.",
reply_markup=reply_markup,
disable_web_page_preview=True
)
except Exception as error:
print(error)
Bot.run()