-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Author: @yshalsager Signed-off-by: isaacchen <isaacchen@isaacchen.cn>
- Loading branch information
0 parents
commit f96ff0d
Showing
9 changed files
with
1,201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*log* | ||
*tmp* | ||
*__pycache__* | ||
config.json | ||
admin/ | ||
private/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Uranus Telegam Bot | ||
#### By [yshalsager](https://t.me/yshalsager) & [XiaomiGeeks](https://t.me/XiaomiGeeks) | ||
|
||
Uranus is an all-in-one bot that provide useful services for Xiaomi users on Telegram. | ||
|
||
You can start using it or adding it to your group [here](https://t.me/XiaomiGeeksBot). | ||
|
||
### About the code: | ||
This project is a modular telegram bot, made using Python 3 and python-telegram-bot library. | ||
|
||
The whole bot functions in this repo, which are licensed under GPL3, are based on [XiaomiFirmwareUpdater](https://github.com/XiaomiFirmwareUpdater/) other projects and files, including and not limited to: | ||
|
||
- [mi-firmware-updater](https://github.com/XiaomiFirmwareUpdater/mi-firmware-updater) | ||
- [miui-updates-tracker](https://github.com/XiaomiFirmwareUpdater/miui-updates-tracker) | ||
- [xiaomifirmwareupdater.github.io](https://github.com/XiaomiFirmwareUpdater/xiaomifirmwareupdater.github.io) | ||
|
||
However, [the telegram bot](https://t.me/XiaomiGeeksBot) may contian some other features that are not available in this code, like Admin module. | ||
|
||
### Running this bot on your own: | ||
|
||
- Make sure you have python3.6+ installed. | ||
- Install required libs. | ||
``` | ||
pip3 install -r requirements.txt | ||
``` | ||
- Copy the bot config file and rename it to config.json, place your bot API TOKEN at placeholder. | ||
- Run the bot using `python3 xfu_bot.py` | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tg_bot_token": "TOKEN HERE" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
#!/usr/bin/env python3.7 | ||
"""Xiaomi Helper Bot general commands""" | ||
|
||
import json | ||
from requests import get | ||
|
||
codenames = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/xiaomi_devices/" + | ||
"master/devices.json").content) | ||
|
||
|
||
def check_codename(codename): | ||
"""check if codename is correct""" | ||
if not [i for i in codenames['data'] if codename == i.split('_')[0]]: | ||
return False | ||
|
||
|
||
def load_fastboot_data(device): | ||
""" | ||
load latest fasboot ROMs data form MIUI tracker json files | ||
:argument device - Xiaomi device codename | ||
:returns data - a list with merged stable, weekly, current, and EOL data | ||
""" | ||
stable_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" + | ||
"stable_fastboot/stable_fastboot.json").content) | ||
weekly_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" + | ||
"weekly_fastboot/weekly_fastboot.json").content) | ||
eol_stable_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/EOL/" + | ||
"stable_fastboot/stable_fastboot.json").content) | ||
eol_weekly_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/EOL/" + | ||
"weekly_fastboot/weekly_fastboot.json").content) | ||
latest_stable = [i for i in stable_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
latest_weekly = [i for i in weekly_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
eol_stable = [i for i in eol_stable_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
eol_weekly = [i for i in eol_weekly_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
data = latest_stable + latest_weekly + eol_stable + eol_weekly | ||
return data | ||
|
||
|
||
def fetch_recovery(device): | ||
""" | ||
fetch latest recovery ROMs for a device from MIUI updates tracker json files | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
stable_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" + | ||
"stable_recovery/stable_recovery.json").content) | ||
weekly_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/" + | ||
"weekly_recovery/weekly_recovery.json").content) | ||
eol_stable_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/EOL/" + | ||
"stable_recovery/stable_recovery.json").content) | ||
eol_weekly_roms = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/miui-updates-tracker/master/EOL/" + | ||
"weekly_recovery/weekly_recovery.json").content) | ||
latest_stable = [i for i in stable_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
latest_weekly = [i for i in weekly_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
eol_stable = [i for i in eol_stable_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
eol_weekly = [i for i in eol_weekly_roms | ||
if device == i['codename'].split('_')[0] and i['version']] | ||
data = latest_stable + latest_weekly + eol_stable + eol_weekly | ||
message = '' | ||
status = None | ||
if not data: | ||
message = "No such device!" | ||
status = False | ||
return message, status | ||
for i in data: | ||
name = i['device'] | ||
version = i['version'] | ||
android = i['android'] | ||
download = i['download'] | ||
if 'V' in version: | ||
rom_type = 'Stable' | ||
else: | ||
rom_type = 'Weekly' | ||
message += "Latest {} {} ROM:\n" \ | ||
"*Version:* `{}` \n" \ | ||
"*Android:* {} \n" \ | ||
"*Download*: [Here]({}) \n\n" \ | ||
.format(name, rom_type, version, android, download) | ||
return message, status | ||
|
||
|
||
def fetch_fastboot(device): | ||
""" | ||
fetch latest fastboot ROMs for a device from MIUI updates tracker json files | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
message = '' | ||
status = None | ||
data = load_fastboot_data(device) | ||
if not data: | ||
message = "No such device!" | ||
status = False | ||
return message, status | ||
for i in data: | ||
name = i['device'] | ||
version = i['version'] | ||
android = i['android'] | ||
download = i['download'] | ||
if 'V' in version: | ||
rom_type = 'Stable' | ||
else: | ||
rom_type = 'Weekly' | ||
message += "Latest {} {} ROM:\n" \ | ||
"*Version:* `{}` \n" \ | ||
"*Android:* {} \n".format(name, rom_type, version, android) | ||
message += "*Download*: [Here]({}) \n\n".format(download) | ||
return message, status | ||
|
||
|
||
def gen_fw_link(device): | ||
""" | ||
generate latest firmware links for a device | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
devices = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/" + | ||
"xiaomifirmwareupdater.github.io/master/data/devices.json").content) | ||
status = None | ||
if not [i for i in devices if device == i['codename'].split('_')[0]]: | ||
message = "Wrong codename!" | ||
status = False | ||
return message, status | ||
site = 'https://xiaomifirmwareupdater.com/#' | ||
stable = site + 'stable/#' | ||
weekly = site + 'weekly/#' | ||
message = "*Stable Firmware*: [Here]({})\n" \ | ||
"*Weekly Firmware*: [Here]({})\n".format(stable + device, weekly + device) | ||
return message, status | ||
|
||
|
||
def check_latest(device): | ||
""" | ||
check latest version of ROMs for a device from MIUI updates tracker json files | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
message = '' | ||
status = None | ||
data = load_fastboot_data(device) | ||
if not data: | ||
message = "No such device!" | ||
status = False | ||
return message, status | ||
for i in data: | ||
version = i['version'] | ||
if 'V' in version: | ||
branch = 'Stable' | ||
else: | ||
branch = 'Weekly' | ||
file = i['filename'] | ||
if 'eea_global' in file: | ||
region = 'EEA Global' | ||
elif 'in_global' in file: | ||
region = 'India' | ||
elif 'ru_global' in file: | ||
region = 'Russia' | ||
elif 'global' in file: | ||
region = 'Global' | ||
else: | ||
region = 'China' | ||
message += "Latest {} {}: `{}`\n".format(region, branch, version) | ||
return message, status | ||
|
||
|
||
def oss(device): | ||
""" | ||
get latest oss kernel for a device from MIUI Mi Code repo | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
info = list(get( | ||
"https://raw.githubusercontent.com/MiCode/Xiaomi_Kernel_OpenSource/" + | ||
"README/README.md").text.splitlines()) | ||
data = [i.split('|')[-2] for i in info if device in i] | ||
message = '' | ||
status = None | ||
if not data: | ||
message = "No such device!" | ||
status = False | ||
return message, status | ||
for item in data: | ||
message += "{}\n".format(item.strip()) | ||
return message, status | ||
|
||
|
||
def history(device): | ||
""" | ||
get all released MIUI rom for device | ||
:argument device - Xiaomi device codename | ||
:returns message - telegram message string | ||
:returns status - Boolean for device status whether found or not | ||
""" | ||
devices = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/" + | ||
"xiaomifirmwareupdater.github.io/master/data/devices.json").content) | ||
status = None | ||
if not [i for i in devices if device == i['codename'].split('_')[0]]: | ||
message = "Wrong codename!" | ||
return message, status | ||
all_data = json.loads(get( | ||
"https://raw.githubusercontent.com/XiaomiFirmwareUpdater/" + | ||
"xiaomifirmwareupdater.github.io/master/data/devices/full/" + | ||
"{}.json".format(device)).content) | ||
stable = [i for i in all_data if i['branch'] == 'stable'] | ||
weekly = [i for i in all_data if i['branch'] == 'weekly'] | ||
stable.reverse() | ||
weekly.reverse() | ||
message = '*Available Stable ROMs:*\n' | ||
for i in stable: | ||
version = i['versions']['miui'] | ||
file = '_'.join(i['filename'].split('_')[2:]) | ||
link = 'http://bigota.d.miui.com/{}/{}'.format(version, file) | ||
message += "[{}]({}) ".format(version, link) | ||
message += '\n*Available Weekly ROMs:*\n' | ||
for i in weekly: | ||
version = i['versions']['miui'] | ||
file = '_'.join(i['filename'].split('_')[2:]) | ||
link = 'http://bigota.d.miui.com/{}/{}'.format(version, file) | ||
message += "[{}]({}) ".format(version, link) | ||
return message, status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
python-telegram-bot==12.0.0b1 |
Oops, something went wrong.