Skip to content

Commit

Permalink
Speedtest & Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkhatri137 committed Oct 5, 2021
1 parent a43aa72 commit 126a17d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ This project is heavily inspired from @out386 's telegram bot which is written i
- Shortener support
- No Duplicate mirrors
- Extract password protected files (It's not hack, you have to enter password for extracting. LOL)
- Speedtest
- Heroku dyno usage

- For extracting password protected files, using custom filename and download from password protected index links see these examples :-
> https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20
Expand All @@ -91,6 +93,7 @@ stats - Bot Usage Stats
help - Get Detailed Help
speedtest - Check Speed of the host (Not working currently!)
log - Bot Log [owner only]
usage - check heroku dyno usage [owner only]
```

<details>
Expand Down
10 changes: 10 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def getConfig(name: str):
MAX_TORRENT_SIZE = int(getConfig("MAX_TORRENT_SIZE"))
except KeyError:
MAX_TORRENT_SIZE = None
try:
HEROKU_API_KEY = getConfig('HEROKU_API_KEY')
except KeyError:
logging.warning('HEROKU API KEY not provided!')
HEROKU_API_KEY = None
try:
HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME')
except KeyError:
logging.warning('HEROKU APP NAME not provided!')
HEROKU_APP_NAME = None
try:
ENABLE_FILESIZE_LIMIT = getConfig('ENABLE_FILESIZE_LIMIT')
if ENABLE_FILESIZE_LIMIT.lower() == 'true':
Expand Down
3 changes: 2 additions & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from bot.helper.telegram_helper.message_utils import LOGGER, editMessage, sendLogFile, sendMessage
from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time
from .helper.telegram_helper.filters import CustomFilters
from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, delete # noqa
from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, delete, speedtest, usage # noqa

from pyrogram import idle
from bot import app
Expand Down Expand Up @@ -100,6 +100,7 @@ def bot_help(update, context):
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports
/{BotCommands.SpeedCommand}: Check Internet Speed of the Host
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only).
'''
sendMessage(help_string, context.bot, update)

Expand Down
2 changes: 2 additions & 0 deletions bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ def __init__(self):
self.WatchCommand = 'watch'
self.TarWatchCommand = 'tarwatch'
self.deleteCommand = 'del'
self.UsageCommand = 'usage'
self.SpeedCommand = 'speedtest'

BotCommands = _BotCommands()
16 changes: 8 additions & 8 deletions bot/modules/speedtest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from speedtest import Speedtest
from bot.helper.telegram_helper.filters import CustomFilters
from bot import dispatcher, AUTHORIZED_CHATS
from bot import dispatcher
from bot.helper.telegram_helper.bot_commands import BotCommands
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ParseMode
from telegram.ext import CallbackContext, Filters, run_async, CommandHandler
from telegram import ParseMode
from bot.helper.telegram_helper.message_utils import *
from telegram.ext import CommandHandler

run_async
def speedtest(update, context):
message = update.effective_message
ed_msg = message.reply_text("๐“ก๐“พ๐“ท๐“ท๐“ฒ๐“ท๐“ฐ ๐“ข๐“น๐“ฎ๐“ฎ๐“ญ ๐“ฃ๐“ฎ๐“ผ๐“ฝ . . . ")
speed = sendMessage("๐“ก๐“พ๐“ท๐“ท๐“ฒ๐“ท๐“ฐ ๐“ข๐“น๐“ฎ๐“ฎ๐“ญ ๐“ฃ๐“ฎ๐“ผ๐“ฝ . . . ", context.bot, update)
test = Speedtest()
test.get_best_server()
test.download()
Expand All @@ -26,7 +26,7 @@ def speedtest(update, context):
<b>๐Ÿ“ถ Ping:</b> <code>{result['ping']} ms</code>
<b>๐Ÿฌ ISP:</b> <code>{result['client']['isp']}</code>
'''
ed_msg.delete()
speed.delete()
try:
update.effective_message.reply_photo(path, string_speed, parse_mode=ParseMode.HTML)
except:
Expand All @@ -44,6 +44,6 @@ def speed_convert(size):


SPEED_HANDLER = CommandHandler(BotCommands.SpeedCommand, speedtest,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
filters=CustomFilters.owner_filter | CustomFilters.authorized_user, run_async=True)

dispatcher.add_handler(SPEED_HANDLER)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ js2py
lxml
megasdkrestclient
psutil
heroku3
Pyrogram
python-dotenv
python-magic
python-telegram-bot
requests
speedtest-cli
telegraph
tenacity
TgCrypto
Expand Down

0 comments on commit 126a17d

Please sign in to comment.