Files
aaPanel/class/panel_telegram_bot.py
T
Jack ed55fa708d Update to 7.7.0
Since version 7.7.0, we recommend yours update python to 3.12.

[+] Using nginx technology to load static files improves access speed
[+] Refactor homepage, website, FTP, and database using vue3
[+] Table loading changed to skeleton screen
[+] Add Website statistics-v2 professional plug-in
[+] Add Home page - top 5 resource occupancy
[+] Add protection for Files management (requires Tamper-proof for Enterprise 3.7)
[+] Website, FTP, Databases page add program status
[+] Add FTP log analysis (only supports Centos)
[+] Add password-free login to phpMyAdmin
[+] Add Proxy Project in Website (Supported when web service uses Nginx)
[+] Add WP Toolkit (Pro version only)
[+] Redesigned Docker module
[+] Add WP Toolkit Protection
[+] Add WP Toolkit Backup and Restore
[+] Add WP Toolkit Migrated
[+] Add WP Toolkit Clone site (supports new domain and subdomain)
[+] Add WP Toolkit Create site from backup of other panel
[+] Add WP Toolkit support for Cron automatic backup (only save Local disk)
[+] Add WP Toolkit operation log
[+] Add Integrity check for WP Toolkit
[+] Add WP Toolkit plug-in management and themes management

[*] Optimize phpMyAdmin formula access method
[*] Optimize Home page PHP display problem
[*] Optimize jump to the login interface after the login expires
[*] Optimize automatic renewal of SSL at some times
[*] Optimize Let's Encrypt to increase application success rate

[-] Fix Logs Audit cannot be opened
[-] Fix apache URL rewrite issue
[-] Fix phpmyadmin installation problem
[-] Fix the problem that some servers cannot install software
[-] Fix upload file error
[-] Fix left menu hiding problem
[-] Fix aaPanel Mobile QR code display problem
[-] Fix problem that third-party plug-ins are not displayed in the App Store
[-] Fix issue where the menu bar is blank when opening new tabs
[-] Fixed panel not being accessible in some cases
[-] Fix the issue where Curl warning caused the inability to apply for SSL
[-] Fix Quota issues for Website, FTP, Databases
[-] Fix file interface display problem on mobile terminal
2024-07-19 11:25:10 +08:00

101 lines
3.2 KiB
Python

# coding: utf-8
# +-------------------------------------------------------------------
# | aaPanel x3
# +-------------------------------------------------------------------
# | Copyright (c) 2015-2017 aaPanel(www.aapanel.com) All rights reserved.
# +-------------------------------------------------------------------
# | Author: zhw <zhw@aapanel.com>
# +-------------------------------------------------------------------
import public
import json
import os
py_bin = public.get_python_bin()
pip = public.get_pip_bin()
try:
import telegram
except:
public.ExecShell('{} install python-telegram-bot'.format(pip))
import telegram
class panel_telegram_bot:
panel_path = public.get_panel_path()
__tg_conf_file = '{}/data/tg_bot.json'.format(panel_path)
# 设置tg机器人
def set_tg_bot(self,get):
"""
bot_token:12345677:CCCCCCCC-a0VUo2jjrCCfffaaaaCCDDD
my_id:1234567890
"""
data = {"setup":True,"bot_token":get.bot_token,"my_id":get.my_id}
public.writeFile(self.__tg_conf_file,json.dumps(data))
return public.returnMsg(True,"Setup successfully")
# 删除tg机器人
def del_tg_bot(self,get):
if os.path.exists(self.__tg_conf_file):
os.remove(self.__tg_conf_file)
return public.returnMsg(True, "Remove successfully")
# 获取tg机器人信息
def get_tg_conf(self,get=None):
conf = public.readFile(self.__tg_conf_file)
if not conf:
return {"setup":False,"bot_token":"","my_id":""}
try:
return json.loads(conf)
except:
return {"setup":False,"bot_token":"","my_id":""}
def process_character(self,content):
character = ['\\', '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']
for c in character:
content = content.replace(c, '\\' + c)
return content
# 使用tg机器人发送消息
def send_by_tg_bot(self,content,parse_mode=None):
"""
@author hezhihong
"""
"parse_mode 消息格式 html/markdown/markdownv2"
# content = self.process_character(content)
conf = self.get_tg_conf()
try:
result= self.send_message(conf['bot_token'],conf['my_id'],content)
if not result['status']:
return False
return True
except:
return False
def send_message(self, bot_token, chat_id, msg):
"""
tg发送信息
@msg 消息正文
@author hezhihong
"""
msg = self.process_character(msg)
url = 'https://api.telegram.org/bot{}/sendMessage'.format(bot_token)
data = {
'chat_id': chat_id,
'text': msg,
'parse_mode':'MarkdownV2',
}
try:
import requests
response = requests.post(url, json=data)
if response.status_code == 200:
return public.returnMsg(True,0,response.json())
else:
return public.returnMsg(False,json.loads(response.text))
except Exception as e:
return public.returnMsg(False,str(e))