Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ECHO bot centos 8
- dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget
- cd /usr/src
- wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
- tar xzf Python-3.9.5.tgz
- cd Python-3.9.5
- ./configure --enable-optimizations
- make altinstall
- python3.9 -m pip install --upgrade pip
- /////////////////////////////////////////////////////////////////////
- Виртуальное окружение python
- встать над каталогом
- python3.9 -m venv python3.9-venv
- source python3.9-venv/bin/activate
- pip3 install pyTelegramBotAPI
- deactivate
- /////////////////////////////////////////////////////////////////////
- python3.9 -m pip install aiogram
- python3.9 -V
- mkdir /home/bot
- mcedit /home/bot/config.py
- TOKEN = '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'
- mcedit /home/bot/bot.py
- from aiogram import Bot, types
- from aiogram.dispatcher import Dispatcher
- from aiogram.utils import executor
- from config import TOKEN
- bot = Bot(token=TOKEN)
- dp = Dispatcher(bot)
- @dp.message_handler(commands=['start'])
- async def process_start_command(message: types.Message):
- await message.reply("Привет!\nНапиши мне что-нибудь!")
- @dp.message_handler(commands=['help'])
- async def process_help_command(message: types.Message):
- await message.reply("Напиши мне что-нибудь, и я отпрпавлю этот текст тебе в ответ!")
- @dp.message_handler()
- async def echo_message(msg: types.Message):
- await bot.send_message(msg.from_user.id, msg.text)
- if __name__ == '__main__':
- executor.start_polling(dp)
- ###############################################################################################################
- #Этот bot lininux
- ##### Выполните команду
- touch /etc/systemd/system/telegram-bot.service
- chmod 664 /etc/systemd/system/telegram-bot.service
- dnf instal mc
- ############## Эти команды на перезапуск сервиса #############
- systemctl start telegram-bot.service
- systemctl enable telegram-bot.service
- systemctl status telegram-bot.service
- systemctl куыефке telegram-bot.service
- ############# Выполните это
- mcedit etc/systemd/system/telegram-bot.service
- ############ И вставьте текст
- [Unit]
- Description=Telegram bot
- After=network.target
- [Service]
- Type=simple
- User= root
- ExecStart=/home/load/bot.sh (в этом файле тогда надо прописать полный путь до bot.py)
- [Install]
- WantedBy=multi-user.target
- #####################################################################
- #Этот файл config.py
- TOKEN = '1791281450:AAHcMZ4SqzchSKgI4iAyDrVOPJhFdb2vCLA'
- ##############################################################
- #Этот файл bot.sh
- #!/bin/bash
- python3.9 /home/bot/bot.py
- #############################################################
- #Этот файл bot.py
- ### Работает на python3.9
- import os
- import subprocess
- import sys
- import shlex
- import datetime
- from subprocess import Popen, PIPE
- from aiogram import Bot, types
- from aiogram.dispatcher import Dispatcher
- from aiogram.utils import executor
- import subprocess
- from config import TOKEN
- bot = Bot(token=TOKEN)
- dp = Dispatcher(bot)
- def run_command(command):
- process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
- global textoutput
- textoutput = ''
- while True:
- global output
- output = process.stdout.readline()
- output = output.decode('utf8')
- if output == '' and process.poll() is not None:
- break
- if output:
- print (output.strip())
- textoutput = textoutput + '\n' + output.strip()
- rc = process.poll()
- return rc
- @dp.message_handler(commands=['start'])
- async def process_start_command(message: types.Message):
- await message.reply("Привет!\nМой список команд ограничен твоей фантазией\n/help\n/ifconfig\n/ip\n/df\n/ping!")
- @dp.message_handler(commands=['ifconfig'])
- async def ifconfig(message: types.Message):
- answer_message = run_command("ifconfig")
- await message.answer(textoutput)
- @dp.message_handler(commands=['ip'])
- async def ip(message: types.Message):
- answer_message = run_command("ip addr show")
- await message.answer(textoutput)
- @dp.message_handler(commands=['df'])
- async def df(message: types.Message):
- answer_message = run_command ("df -h" )
- await message.answer(textoutput)
- @dp.message_handler(commands=['ping'])
- async def ping(message: types.Message):
- answer_message = run_command ("ping 8.8.8.8 -c 4" )
- await message.answer(textoutput)
- if __name__ == '__main__':
- executor.start_polling(dp)
Add Comment
Please, Sign In to add comment