diff --git a/Scripts/Bots/runPython_bot/.gitignore b/Scripts/Bots/runPython_bot/.gitignore index ee5423d95..eefbeb9db 100644 --- a/Scripts/Bots/runPython_bot/.gitignore +++ b/Scripts/Bots/runPython_bot/.gitignore @@ -1,3 +1,132 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + token.txt -__pycache__ -*.pyc \ No newline at end of file +venv diff --git a/Scripts/Bots/runPython_bot/LICENSE b/Scripts/Bots/runPython_bot/LICENSE new file mode 100644 index 000000000..6f1f92c87 --- /dev/null +++ b/Scripts/Bots/runPython_bot/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Aahnik Daw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Scripts/Bots/runPython_bot/Makefile b/Scripts/Bots/runPython_bot/Makefile deleted file mode 100644 index 997554015..000000000 --- a/Scripts/Bots/runPython_bot/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -hi: - @echo hi - -requirements: - rm -rf venv - python3.8 -m venv venv - . venv/bin/activate && python3.8 -m pip install -r requirements.txt -U - clear - -start: - . venv/bin/activate && python3.8 start.py \ No newline at end of file diff --git a/Scripts/Bots/runPython_bot/README.md b/Scripts/Bots/runPython_bot/README.md index e6e1c365c..54978e290 100644 --- a/Scripts/Bots/runPython_bot/README.md +++ b/Scripts/Bots/runPython_bot/README.md @@ -1,31 +1,31 @@ -# runPython_bot +# run-py-bot -Run python code from your telegram chat ! +Run python code from your telegram chat! -[![GitHub license](https://img.shields.io/github/license/aahnik/lovely-telegram)](https://github.com/aahnik/lovely-telegram/blob/main/LICENSE) +[![GitHub license](https://img.shields.io/github/license/aahnik/lovely-telegram)](https://github.com/aahnik/run-py-bot/blob/main/LICENSE) [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![Maintenance Yes](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://gitHub.com/aahnik/REPO/graphs/commit-activity) -![RunPythonBot](https://user-images.githubusercontent.com/66209958/97750350-9d773d80-1b16-11eb-89a5-7626f5547a10.png) +![RunPythonBot](https://github.com/aahnik/run-py-bot/blob/main/docs/images/runPython_bot.png?raw=true) -## Find on Telegram +## πŸ•΅οΈ Find on Telegram -You can find this bot on Telegram: click on this [link](https://t.me/@runPython_bot) or search `@runPython_bot` on telegram. The spelling is case sensitive. +You can find this bot on Telegram as [@runPython_bot](https://telegram.me/runPython_bot). This bot is deployed on [Python Anywhere](https://www.pythonanywhere.com/) free Beginner Account. You may check whether the bot is alive or not, by clicking on the start command. If the bot responds, it is alive. -## Example Use +## πŸ’¬ Example Use You may use pythonic expressions to easily calculate any complex problem. Or you may test your algorithms on the go. > If you are viewing from a smartphone, click on the gif to view full screen ... -![runPython_bot](https://user-images.githubusercontent.com/66209958/97753037-1e383880-1b1b-11eb-863e-bcf82006820b.gif) +![runPython_bot](https://github.com/aahnik/run-py-bot/blob/main/docs/images/runPython_bot_gif.gif?raw=true) -## Deploy +## ⚑ Deploy You can easily *deploy this bot* on [Python Anywhere](https://www.pythonanywhere.com/) or your **local machine** by following the below steps: @@ -33,39 +33,32 @@ You can easily *deploy this bot* on [Python Anywhere](https://www.pythonanywhere Create a free Python Anywhere account and open a Bash Console, which has everything pre-loaded. -If you are planning to deploy on your **own machine**, make sure to have `Python3+`, `pip`, and `make`. +If you are planning to deploy on your **own machine**, make sure to have `Python3+`, `pip`. The following instructions will work smoothly on *Linux* and *Mac*. If you are on Windows, you may have to make slight modifications. Google is your best friend here. -- Create a `projects` directory and move into it +- Clone this repository and move into it. - mkdir projects && cd projects - -- Clone this repository containing the collection of bots - - git clone https://github.com/aahnik/lovely-telegram.git - -- Delete all other folders except the folder containing this bot - - find ./lovely-telegram -mindepth 1 ! -regex '^./lovely-telegram/runPython_bot\(/.*\)?' -delete - -- Now move into the directory which contains this README file, you are reading now. - - cd lovely-telegram/runPython_bot + git clone https://github.com/aahnik/run-py-bot.git && cd run-py-bot - Now add the token in the first line of `token.txt`.Run `cat> token.txt` -> Paste the token -> Press `Ctrl+D` -- To install all dependencies. Simply run `make requirements` +- Create a virtual environment and install dependencies. + + python3.8 -m venv venv && source venv/bin/activate + python3.8 -m pip install -r requirements.txt -- Activate the bot by running `make start` +- Activate the bot by running `python3.8 start.py` - You may now close the Python Anywhere bash console window from your browser, but the bot will continue running. Your bot is now up and running, Enjoy ! 😊 -To stop the bot, Press `Ctrl+C`. To restart the bot run `make start` +All the logs will have the timestamp in the time-zone specified in the `start.py` file. + +To stop the bot, press `Ctrl+C`. You may update the code running in your server by `git fetch && git pull`. -## Limitations +## πŸ˜‘ Limitations Currently, the bot is deployed on a Free Tier account of Python Anywhere. @@ -74,11 +67,11 @@ For security and performance reasons, you **cannot** do the following with the b - import any package - run the `input()` function - run the `open()` function -- Execute a piece of code which takes longer than 30 seconds to execute. +- Execute a piece of code which takes longer than *6 seconds* to execute. -You may overcome these limitations by tweaking the code a little bit and running the bot on your own server. +You may overcome these limitations by changing the `config.py` file in the `bot` subdirectory and running the bot on your own server. -## The Shameless Plug +## πŸ€— The Shameless Plug Authored by **Aahnik Daw**. diff --git a/Scripts/Bots/runPython_bot/bot/config.py b/Scripts/Bots/runPython_bot/bot/config.py new file mode 100644 index 000000000..6dfb2c1e6 --- /dev/null +++ b/Scripts/Bots/runPython_bot/bot/config.py @@ -0,0 +1,15 @@ +''' +Configs for the bot +''' + +# expressions which are banned +banned = ['quit', 'input', 'open', 'import', 'exit'] + +# timeout in seconds +TIMEOUT = 6 + +timeout_message = f'''😒 Timeout of {TIMEOUT} reached. +I have limited resources. +You may increase the timeout and run this bot on your own server if required.''' + +restricted_message = f'☹️ SECURITY ISSUE:\nYou have used a restricted word \n{banned}' diff --git a/Scripts/Bots/runPython_bot/bot/execute_code.py b/Scripts/Bots/runPython_bot/bot/execute_code.py index bca4ae96e..dab9391bf 100644 --- a/Scripts/Bots/runPython_bot/bot/execute_code.py +++ b/Scripts/Bots/runPython_bot/bot/execute_code.py @@ -1,59 +1,110 @@ ''' This module is responsible for handling the execution of python code given by the telegram user. ''' +import logging +from subprocess import TimeoutExpired +import subprocess +import multiprocessing +from .config import banned, TIMEOUT, timeout_message, restricted_message -import subprocess -from subprocess import TimeoutExpired +def contains_restricted(input_text): + '''returns true if any restricted word is found''' + if any(word in input_text for word in banned): + # block usage of this words for security and performance issues + return True + return False -def run(update): +def run(update) -> str: ''' - This function takes an Telegram `update` object, passed by the `reply` function in runPython_bot module, and returns the result after executing update.message.text. + This function takes an Telegram `update` object, + passed by the `reply` function in the runPython_bot module, + and returns the result after executing update.message.text. ''' def execute_py(code): ''' - This function takes a string of python code and executes it in a subprocess of timeout 30s, and returns the standard out and standard error. + This function takes a string of python code + and executes code in a subprocess of timeout 30s, + Returns the standard out and standard error. - Learn more about subprocesses from the official docs of Python + Learn more about subprocesses from the official docs of Python https://docs.python.org/3/library/subprocess.html - For a shorter intro read this stack overflow answer + For a shorter intro read this stack overflow answer https://stackoverflow.com/questions/64606880/how-to-get-the-python-interactive-shell-output-of-a-python-code-in-a-variable ''' proc = subprocess.Popen(['/usr/bin/python3.8', '-c', code], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) try: - stdout, stderr = proc.communicate(timeout=30) + stdout, stderr = proc.communicate(timeout=TIMEOUT) + return stdout.decode('utf-8'), stderr.decode('utf-8') except TimeoutExpired: - return '', '😒 Timeout is 30s. I have limited resources. You may increase the timeout and run this bot on your own server if required.' - return stdout.decode('utf-8'), stderr.decode('utf-8') + return '', timeout_message + except Exception as error: + return '', f'Problem occured \n{error}' + finally: + proc.kill() - def func(input_text): + def func(input_text: str): ''' - This function is a helper function which does some validation job before passing the code to execute_py. + This function is a helper function which does some validation job before passing + the code to execute_py. ''' - restricted_words = ['quit', 'input', 'open', 'import'] - if any(word in input_text for word in restricted_words): - # block usage of this words for security and performance issues - out = f'☹️ SECURITY ISSUE: You have used a restricted word \n {restricted_words}' - return out + if contains_restricted(input_text): + return restricted_message stdout, stderr = execute_py(input_text) if str(stdout) or str(stderr): out = f'{stdout} \n{stderr}' return out return None + try: + if update.message.text: + input_text = update.message.text + + out = func(input_text) + return out + return 'update.message.text was None' + except Exception as error: + msg = 'Error in handling update.message.text' + logging.log(level=40, msg=error) + return msg - input_text = update.message.text - out = func(input_text) - if not out: + +def eval_py(input_text: str): + ''' Runs eval() on the input text on a seperate process and returns output or error. + How to timout on a function call ? https://stackoverflow.com/a/14924210/13523305 + Return a value from multiprocess ? https://stackoverflow.com/a/10415215/13523305 + ''' + + def evaluate(input_text, return_val): + '''wrapper for eval''' try: - out = str(eval(input_text)) - # if there is no output, it may be due to the fact that the code does not have print and is a python expression. - # so the bot evaluates it using eval() - except Exception as e: - out = f'''πŸ˜” If you are planning to write lines after this line then try writing them in a single message. \n**To print something, try using print function**\n Executing your code gave no stdout or stderr. \nSo I tried to evaluate it by using eval(). That raised the following error \n {e}''' - return out + return_val[input_text] = str(eval(input_text)) + except Exception as error: + return_val[ + input_text] = f'''πŸ˜” /e feeds your expression to python's eval function. + The following error occured: \n\n{error}''' + + if contains_restricted(input_text): + return restricted_message + + # using multiprocessing and getting value returned by target function + manger = multiprocessing.Manager() + return_val = manger.dict() # enable target function to return a value + + process = multiprocessing.Process( + target=evaluate, args=(input_text, return_val)) + process.start() + process.join(6) # allow the process to run for 6 seconds + if process.is_alive(): + # kill the process if it is still alive + process.kill() + return timeout_message + output = return_val[input_text] + return output diff --git a/Scripts/Bots/runPython_bot/bot/runPython_bot.py b/Scripts/Bots/runPython_bot/bot/runPython_bot.py deleted file mode 100644 index 0756de3d2..000000000 --- a/Scripts/Bots/runPython_bot/bot/runPython_bot.py +++ /dev/null @@ -1,75 +0,0 @@ -''' -I'm the *Python Runner* bot πŸ˜€ - -I have been created by Aahnik Daw and you may see my [source code](http://bit.ly/runPython) on GitHub. - -I am currently *alive and kicking* on a free tier server of Python Anywhere. - -😁 Sometimes I behave quite differently from a regular python interactive shell. -Certain things are not allowed to prevent horrible consequences. - -_Start using me to figure out more about me_. - -Every message is executed freshly. Suppose you define a variable in one message, you wont be able to access it in the next message. - -But you can write _multiline code in one message_ -->Tab is 4 spaces --> Newline is a newline in the same message body - -If I am being used by too many people, there may be delay in response as I am deployed on a free tier server. -''' - -# the module docstring will be sent to the user if the bot is alive - -from telegram.ext import CommandHandler, MessageHandler, Filters, Updater -# python-telegram-bot is a Pythonic Wrapper to the core Telegram API -# it helps us to be DRY by giving us convinient wrapper functions to deal with Telegram API -# you can install it by pip install python-telegram-bot --upgrade -# learn more about it here https://github.com/python-telegram-bot/python-telegram-bot - - -from .execute_code import run - -# read the token for authenticating our bot -with open('token.txt') as f: - tok = f.readline().strip() - - -def bot(): - ''' - Running this function runs the bot - You may learn more from this tutorial - https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot - ''' - - updater = Updater(token=tok) - - dispatcher = updater.dispatcher - - def start(update, context): - ''' - This fuction replies to the start command - ''' - - context.bot.send_message( - chat_id=update.effective_chat.id, text=f'{__doc__}\n', parse_mode='Markdown') - # for more info on parse modes see https://python-telegram-bot.readthedocs.io/en/stable/telegram.parsemode.html - - def reply(update, context): - ''' - This function replies to any non-command messages - ''' - returned_val = run(update) - context.bot.send_message( - chat_id=update.effective_chat.id, text=returned_val) - - start_handler = CommandHandler('start', start) - message_handler = MessageHandler(Filters.text & (~Filters.command), reply) - - dispatcher.add_handler(start_handler) - dispatcher.add_handler(message_handler) - - updater.start_polling() - # Search google to know what is polling... - # i came to know while building this project - # this can be stopped by interrupting the terminal by `Ctrl+C` diff --git a/Scripts/Bots/runPython_bot/bot/run_python_bot.py b/Scripts/Bots/runPython_bot/bot/run_python_bot.py new file mode 100644 index 000000000..39f068f08 --- /dev/null +++ b/Scripts/Bots/runPython_bot/bot/run_python_bot.py @@ -0,0 +1,128 @@ +''' +This module makes the bot actually run +''' + +from telegram.ext import CommandHandler, MessageHandler, Filters, Updater +# python-telegram-bot is a Pythonic Wrapper to the core Telegram API +# it helps us to be DRY by giving us convinient wrapper functions to deal with Telegram API +# you can install it by pip install python-telegram-bot --upgrade +# learn more about it here https://github.com/python-telegram-bot/python-telegram-bot + + +from .execute_code import eval_py, run + +# read the token for authenticating our bot +with open('token.txt') as f: + tok = f.readline().strip() + +with open('docs/start.txt') as f: + start_text = f.read() + +with open('docs/help.txt') as f: + help_text = f.read() + +with open('docs/code.txt') as f: + code_text = f.read() + + +def handle_long_message(msg): + '''Telegram does not support messages over 4096 characters. + This handler handles all messages above 2000 characters + ''' + + if msg: + if len(msg)> 2000: + return msg[:2000]+'\n\n 😟 Output was too long, truncated to 2000 characters' + return msg + return 'handle_long_message recieved an empty message' + + +def bot(): + ''' + Running this function runs the bot + You may learn more from this tutorial + https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot + ''' + + updater = Updater(token=tok) + + dispatcher = updater.dispatcher + + def start(update, context): + '''This fuction replies to the start command''' + + context.bot.send_message( + chat_id=update.effective_chat.id, text=start_text, parse_mode='Markdown') + # for more info on parse modes + # see https://python-telegram-bot.readthedocs.io/en/stable/telegram.parsemode.html + + def bot_help(update, context): + '''This function replies to the help command''' + context.bot.send_message( + chat_id=update.effective_chat.id, text=help_text, parse_mode='Markdown') + + def code_info(update, context): + '''This function replies to the code command.''' + context.bot.send_message( + chat_id=update.effective_chat.id, text=code_text, parse_mode='Markdown') + + def reply_execute(update, context): + ''' + This function replies to any non-command messages. + ''' + input_text = str(update.message.text) + # allowing usage of /e at the end of expressions + + if input_text == 'hi': + user = update.message.from_user + context.bot.send_message(chat_id=update.effective_chat.id, + text=f'Hi! {user["username"]} πŸ₯°') + + if input_text.endswith('/e'): + message = handle_long_message(eval_py(input_text.strip('/e'))) + update.message.reply_text(message, quote=True) + else: + returned_val = run(update) + if not returned_val: + update.message.reply_text( + '''*No output. No error.* + \n> Try using a `print` statement. + \n> To evaluate an expression use the /e command.''', + quote=True, parse_mode='Markdown') + else: + message = handle_long_message(returned_val) + update.message.reply_text(message, quote=True) + + def reply_eval(update, context): + ''' This function handles the /e command''' + if context.args: + input_text = '' + for string in context.args: + input_text += string + ' ' + out = eval_py(input_text) + message = handle_long_message(out) + update.message.reply_text(message, quote=True) + else: + update.message.reply_text( + '''*No expression provided to eval*. + \nUse command /e before or after your expression like + \n/e `4>= 5` \n \t or \n`4>= 5` /e ''', quote=True, parse_mode='Markdown') + + _handlers = {} + + _handlers['start_handler'] = CommandHandler('start', start) + _handlers['help_handler'] = CommandHandler('help', bot_help) + _handlers['code_info_handler'] = CommandHandler('code', code_info) + _handlers['message_handler'] = MessageHandler( + Filters.text & (~Filters.command), reply_execute) + _handlers['eval_handler'] = CommandHandler('e', reply_eval) + + for name, _handler in _handlers.items(): + print(f'Adding {name}') + dispatcher.add_handler(_handler) + + updater.start_polling() + updater.idle() + # Search google to know what is polling... + # i came to know while building this project + # this can be stopped by interrupting the terminal by `Ctrl+C` diff --git a/Scripts/Bots/runPython_bot/docs/code.txt b/Scripts/Bots/runPython_bot/docs/code.txt new file mode 100644 index 000000000..6177e628f --- /dev/null +++ b/Scripts/Bots/runPython_bot/docs/code.txt @@ -0,0 +1,8 @@ +This bot has been built by @AahnikDaw and you can find the source code on GitHub at. + +Language: Python +Uses: Telegram Bot API via python-telegram-bot wrapper +License: MIT +Link: https://github.com/aahnik/run-py-bot + +If you find a bug, or want to request a new feature you may create a new issue in the GitHub repo of this project. Code Contributions are most welcome. \ No newline at end of file diff --git a/Scripts/Bots/runPython_bot/docs/commands.txt b/Scripts/Bots/runPython_bot/docs/commands.txt new file mode 100644 index 000000000..79791fdf7 --- /dev/null +++ b/Scripts/Bots/runPython_bot/docs/commands.txt @@ -0,0 +1,4 @@ +start - know whether i am alive +help - learn how to use me +code - see my source code +e - pass any expression to eval \ No newline at end of file diff --git a/Scripts/Bots/runPython_bot/docs/help.txt b/Scripts/Bots/runPython_bot/docs/help.txt new file mode 100644 index 000000000..cf1d6cedf --- /dev/null +++ b/Scripts/Bots/runPython_bot/docs/help.txt @@ -0,0 +1,13 @@ +*Every message is executed as fresh python code*. Suppose you define a variable in one message, you won't be able to access it in the next message. + +But you can write _multiline code in one message_ 😊. +->Tab is 4 spaces +-> Newline is a newline in the same message body + +To evaluate a pythonic expression, use the /e command. + +⚠️ Certain things like _importing packages_ is not allowed to prevent any horrible consequence. + +To get source code send /code. + +*Play around with me to explore more* 😍 \ No newline at end of file diff --git a/Scripts/Bots/runPython_bot/docs/images/run-py-bot.png b/Scripts/Bots/runPython_bot/docs/images/run-py-bot.png new file mode 100644 index 000000000..df763efaa Binary files /dev/null and b/Scripts/Bots/runPython_bot/docs/images/run-py-bot.png differ diff --git a/Scripts/Bots/runPython_bot/docs/images/runPython_bot.png b/Scripts/Bots/runPython_bot/docs/images/runPython_bot.png new file mode 100644 index 000000000..0024a8656 Binary files /dev/null and b/Scripts/Bots/runPython_bot/docs/images/runPython_bot.png differ diff --git a/Scripts/Bots/runPython_bot/docs/images/runPython_bot_gif.gif b/Scripts/Bots/runPython_bot/docs/images/runPython_bot_gif.gif new file mode 100644 index 000000000..0f40ce311 Binary files /dev/null and b/Scripts/Bots/runPython_bot/docs/images/runPython_bot_gif.gif differ diff --git a/Scripts/Bots/runPython_bot/docs/start.txt b/Scripts/Bots/runPython_bot/docs/start.txt new file mode 100644 index 000000000..86cb30ca1 --- /dev/null +++ b/Scripts/Bots/runPython_bot/docs/start.txt @@ -0,0 +1,5 @@ +Hi! I'm the *Python Runner* bot πŸ˜€ + +You can run python code, right from your chat. _Start using me to figure out more about me_. + +To learn usage send /help. diff --git a/Scripts/Bots/runPython_bot/requirements.txt b/Scripts/Bots/runPython_bot/requirements.txt index 06f6e7729..d95e4a5fe 100644 --- a/Scripts/Bots/runPython_bot/requirements.txt +++ b/Scripts/Bots/runPython_bot/requirements.txt @@ -1,15 +1,11 @@ APScheduler==3.6.3 -autopep8==1.5.4 certifi==2020εΉ΄6月20ζ—₯ cffi==1.14.3 cryptography==3.2.1 decorator==4.4.2 -pycodestyle==2.6.0 pycparser==2.20 python-telegram-bot==13.0 -pytz==2020.1 -PyYAML==5.3.1 +pytz==2020.4 six==1.15.0 -toml==0.10.1 -tornado==6.0.4 +tornado==6.1 tzlocal==2.1 diff --git a/Scripts/Bots/runPython_bot/start.py b/Scripts/Bots/runPython_bot/start.py index f7381411a..57d408852 100644 --- a/Scripts/Bots/runPython_bot/start.py +++ b/Scripts/Bots/runPython_bot/start.py @@ -1,6 +1,17 @@ -from bot import runPython_bot +from bot import run_python_bot import logging +from pytz import timezone +from datetime import datetime + +TIMEZONE = 'Asia/Kolkata' + +logging.Formatter.converter = lambda *args: datetime.now( + tz=timezone(TIMEZONE)).timetuple() logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) -runPython_bot.bot() + level=logging.INFO, datefmt='%d/%m/%Y %I:%M:%S %p') + +logger = logging.getLogger() +logger.setLevel(20) + +run_python_bot.bot()

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /