-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxiaomi.py
213 lines (180 loc) · 7.18 KB
/
xiaomi.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# XiaomiGeeks Plugin for Moon Userbot
# Provides various Xiaomi device information through @XiaomiGeeksBot
import asyncio
from pyrogram import Client, filters
from pyrogram.errors import YouBlockedUser
from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.scripts import format_exc
from utils.conv import Conversation
async def forward_xiaomi_bot_reply(
client: Client, cmd_text: str, message: Message, loading_text: str
):
"""Helper function to handle XiaomiGeeksBot interactions"""
try:
status_msg = await message.edit(loading_text)
bot_username = "@XiaomiGeeksBot"
async with Conversation(client, bot_username, timeout=15) as conv:
await conv.send_message(cmd_text)
response = await conv.get_response(timeout=10)
await client.forward_messages(
chat_id=message.chat.id,
from_chat_id=bot_username,
message_ids=response.id,
)
await status_msg.delete()
except YouBlockedUser:
await message.edit("<i>Please unblock @XiaomiGeeksBot first.</i>")
except TimeoutError:
await message.edit("<i>No response from bot within the timeout period.</i>")
except Exception as e:
await message.edit(f"<i>Error: {format_exc(e)}</i>")
@Client.on_message(filters.command("firmware", prefix) & filters.me)
async def firmware_cmd(client: Client, message: Message):
"""Get latest firmware for Xiaomi devices"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}firmware [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/firmware {message.command[1]}",
message,
"<i>Fetching firmware info...</i>",
)
@Client.on_message(filters.command("vendor", prefix) & filters.me)
async def vendor_cmd(client: Client, message: Message):
"""Get latest vendor for Xiaomi devices"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}vendor [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/vendor {message.command[1]}",
message,
"<i>Fetching vendor info...</i>",
)
@Client.on_message(filters.command("specs", prefix) & filters.me)
async def specs_cmd(client: Client, message: Message):
"""Get device specifications"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}specs [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/specs {message.command[1]}",
message,
"<i>Fetching device specs...</i>",
)
@Client.on_message(filters.command("fastboot", prefix) & filters.me)
async def fastboot_cmd(client: Client, message: Message):
"""Get fastboot ROM"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}fastboot [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/fastboot {message.command[1]}",
message,
"<i>Fetching fastboot ROM...</i>",
)
@Client.on_message(filters.command("recovery", prefix) & filters.me)
async def recovery_cmd(client: Client, message: Message):
"""Get recovery ROM"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}recovery [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/recovery {message.command[1]}",
message,
"<i>Fetching recovery ROM...</i>",
)
@Client.on_message(filters.command("of", prefix) & filters.me)
async def of_cmd(client: Client, message: Message):
"""Get OrangeFox Recovery"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}of [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/of {message.command[1]}",
message,
"<i>Fetching OrangeFox Recovery...</i>",
)
@Client.on_message(filters.command("latest", prefix) & filters.me)
async def latest_cmd(client: Client, message: Message):
"""Get latest OS versions info"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}latest [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/latest {message.command[1]}",
message,
"<i>Fetching latest OS info...</i>",
)
@Client.on_message(filters.command("archive", prefix) & filters.me)
async def archive_cmd(client: Client, message: Message):
"""Get official ROM archive links"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}archive [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/archive {message.command[1]}",
message,
"<i>Fetching archive links...</i>",
)
@Client.on_message(filters.command("eu", prefix) & filters.me)
async def eu_cmd(client: Client, message: Message):
"""Get Xiaomi.eu ROMs"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}eu [codename]</code>")
return
await forward_xiaomi_bot_reply(
client,
f"/eu {message.command[1]}",
message,
"<i>Fetching Xiaomi.eu ROMs...</i>",
)
@Client.on_message(filters.command("twrp", prefix) & filters.me)
async def twrp_cmd(client: Client, message: Message):
"""Get TWRP download link"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}twrp [codename]</code>")
return
await forward_xiaomi_bot_reply(
client, f"/twrp {message.command[1]}", message, "<i>Fetching TWRP...</i>"
)
@Client.on_message(filters.command("models", prefix) & filters.me)
async def models_cmd(client: Client, message: Message):
"""Get available device models"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}models [codename]</code>")
return
await forward_xiaomi_bot_reply(
client, f"/models {message.command[1]}", message, "<i>Fetching models...</i>"
)
@Client.on_message(filters.command("whatis", prefix) & filters.me)
async def whatis_cmd(client: Client, message: Message):
"""Get device name from codename"""
if len(message.command) < 2:
await message.edit(f"<b>Usage:</b> <code>{prefix}whatis [codename]</code>")
return
await forward_xiaomi_bot_reply(
client, f"/whatis {message.command[1]}", message, "<i>Identifying device...</i>"
)
modules_help["xiaomi"] = {
"archive [codename]": "Get official ROM archive links",
"eu [codename]": "Get Xiaomi.eu ROMs",
"fastboot [codename]": "Get fastboot ROM",
"firmware [codename]": "Get latest firmware for Xiaomi device",
"latest [codename]": "Get latest OS versions info",
"models [codename]": "Get available device models",
"of [codename]": "Get OrangeFox Recovery",
"recovery [codename]": "Get recovery ROM",
"specs [codename]": "Get device specifications",
"twrp [codename]": "Get TWRP download link",
"vendor [codename]": "Get latest vendor for Xiaomi device",
"whatis [codename]": "Get device name from codename",
}