✨🐛➕ Use aiohttp to accelerate network requests and Support silent mode and fix some bugs. (#148)
* 使用 aiohttp 加速网络请求 * 支持静默模式防止污染操作记录 * 批量修复错误
This commit is contained in:
parent
21a5ce0d6f
commit
849a0217b9
4
.github/ISSUE_TEMPLATE/bug_report_en.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report_en.md
vendored
@ -4,7 +4,7 @@ about: Submit discovered bugs
|
|||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Please ensure you have read [wiki](https://github.com/xtaodada/PagerMaid-Modify/wiki), and provide all the information required by this template.
|
Please ensure you have read [wiki](https://github.com/Xtao-Labs/PagerMaid-Modify/wiki), and provide all the information required by this template.
|
||||||
Otherwise the issue will be closed immediately.Please do not repeat the issue.
|
Otherwise the issue will be closed immediately.Please do not repeat the issue.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ Otherwise the issue will be closed immediately.Please do not repeat the issue.
|
|||||||
### Additional info (logs errors etc)
|
### Additional info (logs errors etc)
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Please ensure you have deployed the [master branch](https://github.com/xtaodada/PagerMaid-Modify/tree/master)
|
Please ensure you have deployed the [master branch](https://github.com/Xtao-Labs/PagerMaid-Modify/tree/master)
|
||||||
|
|
||||||
generated by github-issue-template.This issue is in English.
|
generated by github-issue-template.This issue is in English.
|
||||||
-->
|
-->
|
||||||
|
4
.github/ISSUE_TEMPLATE/bug_report_zh.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report_zh.md
vendored
@ -4,7 +4,7 @@ about: 早起的虫子被你抓
|
|||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
请确保已阅读 [文档](https://github.com/xtaodada/PagerMaid-Modify/wiki) 内相关部分,并按照模版提供信息
|
请确保已阅读 [文档](https://github.com/Xtao-Labs/PagerMaid-Modify/wiki) 内相关部分,并按照模版提供信息
|
||||||
否则 issue 将被立即关闭,请勿重复提issue
|
否则 issue 将被立即关闭,请勿重复提issue
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ about: 早起的虫子被你抓
|
|||||||
### 额外信息(日志、报错等)
|
### 额外信息(日志、报错等)
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
请确保您部署的是[主线 master 分支](https://github.com/xtaodada/PagerMaid-Modify/tree/master)的最新版
|
请确保您部署的是[主线 master 分支](https://github.com/Xtao-Labs/PagerMaid-Modify/tree/master)的最新版
|
||||||
|
|
||||||
generated by github-issue-template
|
generated by github-issue-template
|
||||||
-->
|
-->
|
||||||
|
2
.github/ISSUE_TEMPLATE/feature_request_en.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request_en.md
vendored
@ -4,7 +4,7 @@ about: Submit a new feature request
|
|||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Feature Request(https://github.com/xtaodada/PagerMaid-Modify/wiki) or [issue](https://github.com/xtaodada/PagerMaid-Modify/issues) , and provide all the information required by this template.
|
Feature Request(https://github.com/Xtao-Labs/PagerMaid-Modify/wiki) or [issue](https://github.com/Xtao-Labs/PagerMaid-Modify/issues) , and provide all the information required by this template.
|
||||||
Otherwise the issue will be closed immediately.
|
Otherwise the issue will be closed immediately.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
2
.github/ISSUE_TEMPLATE/feature_request_zh.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request_zh.md
vendored
@ -4,7 +4,7 @@ about: 提交新的功能需求
|
|||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
请确保 [文档](https://github.com/xtaodada/PagerMaid-Modify/wiki) 和 [issue](https://github.com/xtaodada/PagerMaid-Modify/issues) 中没有相关内容,并按照模版提供信息
|
请确保 [文档](https://github.com/Xtao-Labs/PagerMaid-Modify/wiki) 和 [issue](https://github.com/Xtao-Labs/PagerMaid-Modify/issues) 中没有相关内容,并按照模版提供信息
|
||||||
否则 issue 将被立即关闭
|
否则 issue 将被立即关闭
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
curl -fsSL https://raw.githubusercontent.com/xtaodada/PagerMaid-Modify/master/utils/docker.sh | sh
|
curl -fsSL https://raw.githubusercontent.com/Xtao-Labs/PagerMaid-Modify/master/utils/docker.sh | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
如果您想在运行之前检查脚本内容:
|
如果您想在运行之前检查脚本内容:
|
||||||
|
|
||||||
```
|
```
|
||||||
curl https://raw.githubusercontent.com/xtaodada/PagerMaid-Modify/master/utils/docker.sh -o docker.sh
|
curl https://raw.githubusercontent.com/Xtao-Labs/PagerMaid-Modify/master/utils/docker.sh -o docker.sh
|
||||||
vim docker.sh
|
vim docker.sh
|
||||||
chmod 0755 docker.sh
|
chmod 0755 docker.sh
|
||||||
./docker.sh
|
./docker.sh
|
||||||
|
12
README.md
12
README.md
@ -5,13 +5,13 @@
|
|||||||
> 一个人形自走 bot
|
> 一个人形自走 bot
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="star" src="https://img.shields.io/github/stars/xtaodada/PagerMaid-Modify.svg"/>
|
<img alt="star" src="https://img.shields.io/github/stars/Xtao-Labs/PagerMaid-Modify.svg"/>
|
||||||
<img alt="fork" src="https://img.shields.io/github/forks/xtaodada/PagerMaid-Modify.svg"/>
|
<img alt="fork" src="https://img.shields.io/github/forks/Xtao-Labs/PagerMaid-Modify.svg"/>
|
||||||
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/xtaodada/PagerMaid-Modify.svg?label=commits">
|
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/Xtao-Labs/PagerMaid-Modify.svg?label=commits">
|
||||||
<img alt="size" src="https://img.shields.io/github/repo-size/Xtao-Labs/PagerMaid-Modify?color=pink"/>
|
<img alt="size" src="https://img.shields.io/github/repo-size/Xtao-Labs/PagerMaid-Modify?color=pink"/>
|
||||||
<img alt="issues" src="https://img.shields.io/github/issues/xtaodada/PagerMaid-Modify.svg"/>
|
<img alt="issues" src="https://img.shields.io/github/issues/Xtao-Labs/PagerMaid-Modify.svg"/>
|
||||||
<img alt="docker" src="https://img.shields.io/docker/pulls/mrwangzhe/pagermaid_modify"/>
|
<img alt="docker" src="https://img.shields.io/docker/pulls/mrwangzhe/pagermaid_modify"/>
|
||||||
<a href="https://github.com/xtaodada/PagerMaid-Modify/blob/master/LICENSE"><img alt="license" src="https://img.shields.io/github/license/xtaodada/PagerMaid-Modify.svg"/></a>
|
<a href="https://github.com/Xtao-Labs/PagerMaid-Modify/blob/master/LICENSE"><img alt="license" src="https://img.shields.io/github/license/Xtao-Labs/PagerMaid-Modify.svg"/></a>
|
||||||
<img alt="telethon" src="https://img.shields.io/badge/telethon-blue.svg"/>
|
<img alt="telethon" src="https://img.shields.io/badge/telethon-blue.svg"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ Pagermaid 是一个用在 Telegram 的实用工具。
|
|||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
[Ubuntu 16.04 手动搭建教程](https://github.com/xtaodada/PagerMaid-Modify/wiki/Ubuntu-16.04-%E5%AE%89%E8%A3%85%E8%AF%A6%E8%A7%A3)
|
[Ubuntu 16.04 手动搭建教程](https://github.com/Xtao-Labs/PagerMaid-Modify/wiki/Ubuntu-16.04-%E5%AE%89%E8%A3%85%E8%AF%A6%E8%A7%A3)
|
||||||
|
|
||||||
[一键脚本](https://t.me/PagerMaid_Modify/58)
|
[一键脚本](https://t.me/PagerMaid_Modify/58)
|
||||||
|
|
||||||
|
@ -91,3 +91,6 @@ start_form: "%m/%d %H:%M"
|
|||||||
bot_admins:
|
bot_admins:
|
||||||
- example1
|
- example1
|
||||||
- example2
|
- example2
|
||||||
|
|
||||||
|
# Silent to reduce editing times
|
||||||
|
silent: "True"
|
||||||
|
@ -248,7 +248,7 @@ debian_require_install() {
|
|||||||
download_repo() {
|
download_repo() {
|
||||||
echo "下载 repository 中 . . ."
|
echo "下载 repository 中 . . ."
|
||||||
rm -rf /var/lib/pagermaid >>/dev/null 2>&1
|
rm -rf /var/lib/pagermaid >>/dev/null 2>&1
|
||||||
git clone https://github.com/xtaodada/PagerMaid-Modify.git /var/lib/pagermaid >>/dev/null 2>&1
|
git clone https://github.com/Xtao-Labs/PagerMaid-Modify.git /var/lib/pagermaid >>/dev/null 2>&1
|
||||||
cd /var/lib/pagermaid >>/dev/null 2>&1
|
cd /var/lib/pagermaid >>/dev/null 2>&1
|
||||||
echo "Hello World!" >/var/lib/pagermaid/public.lock
|
echo "Hello World!" >/var/lib/pagermaid/public.lock
|
||||||
}
|
}
|
||||||
|
@ -256,6 +256,7 @@ re_des: Reread the reply message in the current conversation. (Need to reply to
|
|||||||
re_parameters: <number of times>
|
re_parameters: <number of times>
|
||||||
re_too_big: oh oh something went wrong... this number is too big to provoke
|
re_too_big: oh oh something went wrong... this number is too big to provoke
|
||||||
re_arg_error: Oh, something went wrong...maybe the parameter contains symbols other than numbers
|
re_arg_error: Oh, something went wrong...maybe the parameter contains symbols other than numbers
|
||||||
|
re_forbidden: Oh, something went wrong...you do not have permission to forward messages from this group.
|
||||||
not_reply: Something went wrong ~ You don't seem to reply to a message.
|
not_reply: Something went wrong ~ You don't seem to reply to a message.
|
||||||
# leave
|
# leave
|
||||||
leave_res: Say "goodbye" and leave the session.
|
leave_res: Say "goodbye" and leave the session.
|
||||||
|
@ -267,6 +267,7 @@ re_des: 在当前会话复读回复的消息。(需要回复一条消息)
|
|||||||
re_parameters: <次数>
|
re_parameters: <次数>
|
||||||
re_too_big: 呜呜呜出错了...这个数字太大惹
|
re_too_big: 呜呜呜出错了...这个数字太大惹
|
||||||
re_arg_error: 呜呜呜出错了...可能参数包含了数字以外的符号
|
re_arg_error: 呜呜呜出错了...可能参数包含了数字以外的符号
|
||||||
|
re_forbidden: 呜呜呜出错了...此群组的消息禁止转发
|
||||||
not_reply: 出错了呜呜呜 ~ 您好像没有回复一条消息。
|
not_reply: 出错了呜呜呜 ~ 您好像没有回复一条消息。
|
||||||
## leave
|
## leave
|
||||||
leave_res: 说 “再见” 然后离开会话。
|
leave_res: 说 “再见” 然后离开会话。
|
||||||
|
@ -256,6 +256,7 @@ re_des: 在目前聊天室復讀回覆的訊息。
|
|||||||
re_parameters: <次數>
|
re_parameters: <次數>
|
||||||
re_too_big: Error!數字過大
|
re_too_big: Error!數字過大
|
||||||
re_arg_error: Error!不是數字!
|
re_arg_error: Error!不是數字!
|
||||||
|
re_forbidden: Error!您没有权限!
|
||||||
not_reply: Error!您沒有回覆訊息!
|
not_reply: Error!您沒有回覆訊息!
|
||||||
# leave
|
# leave
|
||||||
leave_res: 說再見並離開聊天室。
|
leave_res: 說再見並離開聊天室。
|
||||||
|
@ -30,6 +30,7 @@ from telethon import TelegramClient
|
|||||||
from telethon.sessions import StringSession
|
from telethon.sessions import StringSession
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
|
from telethon.errors import AuthKeyError
|
||||||
from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageIdInvalidError, ChannelPrivateError, \
|
from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageIdInvalidError, ChannelPrivateError, \
|
||||||
ChatSendMediaForbiddenError, YouBlockedUserError, FloodWaitError, ChatWriteForbiddenError, \
|
ChatSendMediaForbiddenError, YouBlockedUserError, FloodWaitError, ChatWriteForbiddenError, \
|
||||||
AuthKeyDuplicatedError, ChatSendStickersForbiddenError, SlowModeWaitError, MessageEditTimeExpiredError, \
|
AuthKeyDuplicatedError, ChatSendStickersForbiddenError, SlowModeWaitError, MessageEditTimeExpiredError, \
|
||||||
@ -107,9 +108,7 @@ def lang(text: str) -> str:
|
|||||||
|
|
||||||
analytics = None
|
analytics = None
|
||||||
try:
|
try:
|
||||||
allow_analytics = strtobool(config['allow_analytic'])
|
allow_analytics = strtobool(config.get('allow_analytic', 'True'))
|
||||||
except KeyError:
|
|
||||||
allow_analytics = True
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
allow_analytics = True
|
allow_analytics = True
|
||||||
if allow_analytics:
|
if allow_analytics:
|
||||||
@ -163,41 +162,24 @@ except ValueError:
|
|||||||
exit(1)
|
exit(1)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
proxy_addr = config.get('proxy_addr', '').strip()
|
||||||
proxy_addr = config['proxy_addr'].strip()
|
proxy_port = config.get('proxy_port', '').strip()
|
||||||
proxy_port = config['proxy_port'].strip()
|
http_addr = config.get('http_addr', '').strip()
|
||||||
http_addr = config['http_addr'].strip()
|
http_port = config.get('http_port', '').strip()
|
||||||
http_port = config['http_port'].strip()
|
mtp_addr = config.get('mtp_addr', '').strip()
|
||||||
mtp_addr = config['mtp_addr'].strip()
|
mtp_port = config.get('mtp_port', '').strip()
|
||||||
mtp_port = config['mtp_port'].strip()
|
mtp_secret = config.get('mtp_secret', '').strip()
|
||||||
mtp_secret = config['mtp_secret'].strip()
|
redis_host = config.get('redis').get('host', 'localhost')
|
||||||
except KeyError:
|
redis_port = config.get('redis').get('port', 6379)
|
||||||
proxy_addr = ''
|
redis_db = config.get('redis').get('db', 14)
|
||||||
proxy_port = ''
|
if strtobool(config.get('ipv6', 'False')):
|
||||||
http_addr = ''
|
use_ipv6 = True
|
||||||
http_port = ''
|
else:
|
||||||
mtp_addr = ''
|
|
||||||
mtp_port = ''
|
|
||||||
mtp_secret = ''
|
|
||||||
try:
|
|
||||||
redis_host = config['redis']['host']
|
|
||||||
except KeyError:
|
|
||||||
redis_host = 'localhost'
|
|
||||||
try:
|
|
||||||
redis_port = config['redis']['port']
|
|
||||||
except KeyError:
|
|
||||||
redis_port = 6379
|
|
||||||
try:
|
|
||||||
redis_db = config['redis']['db']
|
|
||||||
except KeyError:
|
|
||||||
redis_db = 14
|
|
||||||
try:
|
|
||||||
if strtobool(config['ipv6']):
|
|
||||||
use_ipv6 = True
|
|
||||||
else:
|
|
||||||
use_ipv6 = False
|
|
||||||
except KeyError:
|
|
||||||
use_ipv6 = False
|
use_ipv6 = False
|
||||||
|
if strtobool(config.get('silent', 'True')):
|
||||||
|
silent = True
|
||||||
|
else:
|
||||||
|
silent = False
|
||||||
if api_key is None or api_hash is None:
|
if api_key is None or api_hash is None:
|
||||||
logs.info(
|
logs.info(
|
||||||
lang('config_error')
|
lang('config_error')
|
||||||
@ -297,7 +279,7 @@ def before_send(event, hint):
|
|||||||
AlreadyInConversationError, ConnectedError, KeyboardInterrupt,
|
AlreadyInConversationError, ConnectedError, KeyboardInterrupt,
|
||||||
OSError, AuthKeyDuplicatedError, ResponseError, SlowModeWaitError,
|
OSError, AuthKeyDuplicatedError, ResponseError, SlowModeWaitError,
|
||||||
PeerFloodError, MessageEditTimeExpiredError, PeerIdInvalidError,
|
PeerFloodError, MessageEditTimeExpiredError, PeerIdInvalidError,
|
||||||
AuthKeyUnregisteredError, UserBannedInChannelError)):
|
AuthKeyUnregisteredError, UserBannedInChannelError, AuthKeyError)):
|
||||||
return
|
return
|
||||||
elif exc_info and isinstance(exc_info[1], UserDeactivatedBanError):
|
elif exc_info and isinstance(exc_info[1], UserDeactivatedBanError):
|
||||||
# The user has been deleted/deactivated
|
# The user has been deleted/deactivated
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
""" Message related utilities. """
|
""" Message related utilities. """
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from telethon.tl.functions.messages import DeleteChatUserRequest
|
from telethon.tl.functions.messages import DeleteChatUserRequest
|
||||||
@ -13,7 +12,7 @@ from telethon.tl.types import ChannelForbidden
|
|||||||
|
|
||||||
from pagermaid import bot, log, config, proxies
|
from pagermaid import bot, log, config, proxies
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command, get
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=False, incoming=True, command=alias_command("id"),
|
@listener(is_plugin=False, incoming=True, command=alias_command("id"),
|
||||||
@ -222,13 +221,12 @@ async def hitokoto(context):
|
|||||||
hitokoto_while = 1
|
hitokoto_while = 1
|
||||||
hitokoto_json = None
|
hitokoto_json = None
|
||||||
try:
|
try:
|
||||||
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8", proxies=proxies).content.decode("utf-8"))
|
hitokoto_json = (await get("https://v1.hitokoto.cn/?charset=utf-8")).json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
while hitokoto_while < 10:
|
while hitokoto_while < 10:
|
||||||
hitokoto_while += 1
|
hitokoto_while += 1
|
||||||
try:
|
try:
|
||||||
hitokoto_json = json.loads(
|
hitokoto_json = (await get("https://v1.hitokoto.cn/?charset=utf-8")).json()
|
||||||
requests.get("https://v1.hitokoto.cn/?charset=utf-8", proxies=proxies).content.decode("utf-8"))
|
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from requests import get
|
|
||||||
from os import remove, popen
|
from os import remove, popen
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \
|
from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \
|
||||||
SpeedtestBestServerFailure, SpeedtestHTTPError
|
SpeedtestBestServerFailure, SpeedtestHTTPError
|
||||||
from telethon import functions
|
|
||||||
from platform import python_version, uname
|
from platform import python_version, uname
|
||||||
from wordcloud import WordCloud
|
from wordcloud import WordCloud
|
||||||
from telethon import version as telethon_version
|
from telethon import version as telethon_version
|
||||||
@ -17,7 +15,7 @@ from pathlib import Path
|
|||||||
from pagermaid import log, config, redis_status, start_time
|
from pagermaid import log, config, redis_status, start_time
|
||||||
from pagermaid.utils import execute
|
from pagermaid.utils import execute
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command, get
|
||||||
|
|
||||||
DCs = {
|
DCs = {
|
||||||
1: "149.154.175.50",
|
1: "149.154.175.50",
|
||||||
@ -116,7 +114,7 @@ async def speedtest(context):
|
|||||||
f"Timestamp: `{result['timestamp']}`"
|
f"Timestamp: `{result['timestamp']}`"
|
||||||
)
|
)
|
||||||
# 开始处理图片
|
# 开始处理图片
|
||||||
data = get(f"{result['result']['url']}.png").content
|
data = (await get(f"{result['result']['url']}.png")).content
|
||||||
with open('speedtest.png', mode='wb') as f:
|
with open('speedtest.png', mode='wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
try:
|
try:
|
||||||
@ -192,7 +190,7 @@ async def speedtest(context):
|
|||||||
f"Timestamp: `{result['timestamp']}`"
|
f"Timestamp: `{result['timestamp']}`"
|
||||||
)
|
)
|
||||||
# 开始处理图片
|
# 开始处理图片
|
||||||
data = get(result['share']).content
|
data = (await get(result['share'])).content
|
||||||
with open('speedtest.png', mode='wb') as f:
|
with open('speedtest.png', mode='wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
try:
|
try:
|
||||||
|
@ -37,7 +37,7 @@ async def update(context):
|
|||||||
git_date = run("git log -1 --format='%at'", stdout=PIPE, shell=True).stdout.decode()
|
git_date = run("git log -1 --format='%at'", stdout=PIPE, shell=True).stdout.decode()
|
||||||
git_date = datetime.utcfromtimestamp(int(git_date)).strftime("%Y/%m/%d %H:%M:%S")
|
git_date = datetime.utcfromtimestamp(int(git_date)).strftime("%Y/%m/%d %H:%M:%S")
|
||||||
git_hash = run("git rev-parse --short HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
git_hash = run("git rev-parse --short HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
||||||
get_hash_link = f"https://github.com/xtaodada/PagerMaid-Modify/commit/{git_hash}"
|
get_hash_link = f"https://github.com/Xtao-Labs/PagerMaid-Modify/commit/{git_hash}"
|
||||||
# Generate the text
|
# Generate the text
|
||||||
text = f"{lang('status_platform')}: {str(platform.platform())}\n" \
|
text = f"{lang('status_platform')}: {str(platform.platform())}\n" \
|
||||||
f"{lang('update_platform_version')}: {str(platform.version())}\n" \
|
f"{lang('update_platform_version')}: {str(platform.version())}\n" \
|
||||||
|
@ -10,7 +10,7 @@ from telethon.tl.functions.users import GetFullUserRequest
|
|||||||
from telethon.tl.functions.contacts import BlockRequest, UnblockRequest
|
from telethon.tl.functions.contacts import BlockRequest, UnblockRequest
|
||||||
from telethon.tl.types import InputPhoto, MessageMediaPhoto, MessageEntityMentionName, MessageEntityPhone, User
|
from telethon.tl.types import InputPhoto, MessageMediaPhoto, MessageEntityMentionName, MessageEntityPhone, User
|
||||||
from struct import error as StructError
|
from struct import error as StructError
|
||||||
from pagermaid import bot, log
|
from pagermaid import bot, log, silent
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
|
|
||||||
@ -78,7 +78,8 @@ async def pfp(context):
|
|||||||
""" Sets your profile picture. """
|
""" Sets your profile picture. """
|
||||||
reply = await context.get_reply_message()
|
reply = await context.get_reply_message()
|
||||||
photo = None
|
photo = None
|
||||||
await context.edit(lang('pfp_process'))
|
if not silent:
|
||||||
|
await context.edit(lang('pfp_process'))
|
||||||
if reply:
|
if reply:
|
||||||
if reply.media:
|
if reply.media:
|
||||||
if isinstance(reply.media, MessageMediaPhoto):
|
if isinstance(reply.media, MessageMediaPhoto):
|
||||||
@ -165,8 +166,8 @@ async def profile(context):
|
|||||||
if len(context.parameter) > 1:
|
if len(context.parameter) > 1:
|
||||||
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
||||||
return
|
return
|
||||||
|
if not silent:
|
||||||
await context.edit(lang('profile_process'))
|
await context.edit(lang('profile_process'))
|
||||||
if context.reply_to_msg_id:
|
if context.reply_to_msg_id:
|
||||||
reply_message = await context.get_reply_message()
|
reply_message = await context.get_reply_message()
|
||||||
if not reply_message:
|
if not reply_message:
|
||||||
@ -286,8 +287,8 @@ async def block_user(context):
|
|||||||
if len(context.parameter) > 1:
|
if len(context.parameter) > 1:
|
||||||
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
||||||
return
|
return
|
||||||
|
if not silent:
|
||||||
await context.edit(lang('block_process'))
|
await context.edit(lang('block_process'))
|
||||||
user = None
|
user = None
|
||||||
# Priority: reply > argument > current_chat
|
# Priority: reply > argument > current_chat
|
||||||
if context.reply_to_msg_id: # Reply to a user
|
if context.reply_to_msg_id: # Reply to a user
|
||||||
@ -324,8 +325,8 @@ async def unblock_user(context):
|
|||||||
if len(context.parameter) > 1:
|
if len(context.parameter) > 1:
|
||||||
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
await context.edit(f"{lang('error_prefix')}{lang('arg_error')}")
|
||||||
return
|
return
|
||||||
|
if not silent:
|
||||||
await context.edit(lang('unblock_process'))
|
await context.edit(lang('unblock_process'))
|
||||||
user = None
|
user = None
|
||||||
if context.reply_to_msg_id:
|
if context.reply_to_msg_id:
|
||||||
reply_message = await context.get_reply_message()
|
reply_message = await context.get_reply_message()
|
||||||
|
@ -7,7 +7,7 @@ from pygments.formatters import img
|
|||||||
from pygments.lexers import guess_lexer
|
from pygments.lexers import guess_lexer
|
||||||
from telethon.errors import PhotoInvalidDimensionsError
|
from telethon.errors import PhotoInvalidDimensionsError
|
||||||
|
|
||||||
from pagermaid import log, module_dir
|
from pagermaid import log, module_dir, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import execute, upload_attachment, lang, alias_command
|
from pagermaid.utils import execute, upload_attachment, lang, alias_command
|
||||||
|
|
||||||
@ -17,7 +17,8 @@ from pagermaid.utils import execute, upload_attachment, lang, alias_command
|
|||||||
async def convert(context):
|
async def convert(context):
|
||||||
""" Converts image to png. """
|
""" Converts image to png. """
|
||||||
reply = await context.get_reply_message()
|
reply = await context.get_reply_message()
|
||||||
await context.edit(lang('convert_process'))
|
if not silent:
|
||||||
|
await context.edit(lang('convert_process'))
|
||||||
target_file_path = await context.download_media()
|
target_file_path = await context.download_media()
|
||||||
reply_id = context.reply_to_msg_id
|
reply_id = context.reply_to_msg_id
|
||||||
if reply:
|
if reply:
|
||||||
@ -55,7 +56,8 @@ async def convert(context):
|
|||||||
parameters="<string>,<string> <image>")
|
parameters="<string>,<string> <image>")
|
||||||
async def caption(context):
|
async def caption(context):
|
||||||
""" Generates images with captions. """
|
""" Generates images with captions. """
|
||||||
await context.edit(lang('caption_process'))
|
if not silent:
|
||||||
|
await context.edit(lang('caption_process'))
|
||||||
if context.arguments:
|
if context.arguments:
|
||||||
if ',' in context.arguments:
|
if ',' in context.arguments:
|
||||||
string_1, string_2 = context.arguments.split(',', 1)
|
string_1, string_2 = context.arguments.split(',', 1)
|
||||||
@ -121,7 +123,8 @@ async def ocr(context):
|
|||||||
await context.edit(lang('ocr_psm_len_error'))
|
await context.edit(lang('ocr_psm_len_error'))
|
||||||
return
|
return
|
||||||
reply = await context.get_reply_message()
|
reply = await context.get_reply_message()
|
||||||
await context.edit(lang('ocr_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('ocr_processing'))
|
||||||
if reply:
|
if reply:
|
||||||
target_file_path = await context.client.download_media(
|
target_file_path = await context.client.download_media(
|
||||||
await context.get_reply_message()
|
await context.get_reply_message()
|
||||||
@ -154,7 +157,8 @@ async def highlight(context):
|
|||||||
return
|
return
|
||||||
reply = await context.get_reply_message()
|
reply = await context.get_reply_message()
|
||||||
reply_id = None
|
reply_id = None
|
||||||
await context.edit(lang('highlight_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('highlight_processing'))
|
||||||
if reply:
|
if reply:
|
||||||
reply_id = reply.id
|
reply_id = reply.id
|
||||||
target_file_path = await context.client.download_media(
|
target_file_path = await context.client.download_media(
|
||||||
@ -189,7 +193,8 @@ async def highlight(context):
|
|||||||
except OSError:
|
except OSError:
|
||||||
await context.edit(lang('caption_error'))
|
await context.edit(lang('caption_error'))
|
||||||
return
|
return
|
||||||
await context.edit(lang('highlight_uploading'))
|
if not silent:
|
||||||
|
await context.edit(lang('highlight_uploading'))
|
||||||
try:
|
try:
|
||||||
await context.client.send_file(
|
await context.client.send_file(
|
||||||
context.chat_id,
|
context.chat_id,
|
||||||
|
@ -6,7 +6,7 @@ from magic_google import MagicGoogle
|
|||||||
from gtts import gTTS
|
from gtts import gTTS
|
||||||
from gtts.tts import gTTSError
|
from gtts.tts import gTTSError
|
||||||
from re import compile as regex_compile
|
from re import compile as regex_compile
|
||||||
from pagermaid import log
|
from pagermaid import log, silent
|
||||||
from pagermaid.listener import listener, config
|
from pagermaid.listener import listener, config
|
||||||
from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang, alias_command
|
from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang, alias_command
|
||||||
|
|
||||||
@ -29,7 +29,8 @@ async def translate(context):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('translate_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('translate_processing'))
|
||||||
try:
|
try:
|
||||||
result = translator.translate(clear_emojis(message), dest=ap_lang)
|
result = translator.translate(clear_emojis(message), dest=ap_lang)
|
||||||
except:
|
except:
|
||||||
@ -75,7 +76,8 @@ async def tts(context):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('tts_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('tts_processing'))
|
||||||
gTTS(message, lang=ap_lang)
|
gTTS(message, lang=ap_lang)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
await context.edit(lang('tts_AssertionError'))
|
await context.edit(lang('tts_AssertionError'))
|
||||||
@ -134,7 +136,8 @@ async def googletest(context):
|
|||||||
return
|
return
|
||||||
|
|
||||||
query = query.replace(' ', '+')
|
query = query.replace(' ', '+')
|
||||||
await context.edit(lang('google_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('google_processing'))
|
||||||
results = ""
|
results = ""
|
||||||
for i in mg.search(query=query, num=int(config['result_length'])):
|
for i in mg.search(query=query, num=int(config['result_length'])):
|
||||||
try:
|
try:
|
||||||
@ -166,7 +169,8 @@ async def fetchaudio(context):
|
|||||||
""" Fetches audio from provided URL. """
|
""" Fetches audio from provided URL. """
|
||||||
reply = await context.get_reply_message()
|
reply = await context.get_reply_message()
|
||||||
reply_id = None
|
reply_id = None
|
||||||
await context.edit(lang('fetchaudio_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('fetchaudio_processing'))
|
||||||
if reply:
|
if reply:
|
||||||
reply_id = reply.id
|
reply_id = reply.id
|
||||||
if url is None:
|
if url is None:
|
||||||
|
@ -4,7 +4,7 @@ from asyncio import sleep
|
|||||||
from random import choice, random, randint, randrange, seed
|
from random import choice, random, randint, randrange, seed
|
||||||
from telethon.errors.rpcerrorlist import MessageNotModifiedError
|
from telethon.errors.rpcerrorlist import MessageNotModifiedError
|
||||||
from cowpy import cow
|
from cowpy import cow
|
||||||
from pagermaid import module_dir
|
from pagermaid import module_dir, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import owoify, execute, random_gen, obtain_message, lang, alias_command
|
from pagermaid.utils import owoify, execute, random_gen, obtain_message, lang, alias_command
|
||||||
|
|
||||||
@ -160,7 +160,8 @@ async def flip(context):
|
|||||||
parameters="<username> <username>")
|
parameters="<username> <username>")
|
||||||
async def ship(context):
|
async def ship(context):
|
||||||
""" Ship randomly generated members. """
|
""" Ship randomly generated members. """
|
||||||
await context.edit(lang('ship_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('ship_processing'))
|
||||||
if len(context.parameter) == 0:
|
if len(context.parameter) == 0:
|
||||||
users = []
|
users = []
|
||||||
async for user in context.client.iter_participants(context.chat_id):
|
async for user in context.client.iter_participants(context.chat_id):
|
||||||
@ -267,19 +268,21 @@ async def tuxsay(context):
|
|||||||
description=lang('coin_des'))
|
description=lang('coin_des'))
|
||||||
async def coin(context):
|
async def coin(context):
|
||||||
""" Throws a coin. """
|
""" Throws a coin. """
|
||||||
await context.edit(lang('coin_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('coin_processing'))
|
||||||
await sleep(.5)
|
await sleep(.5)
|
||||||
outcomes = ['A'] * 5 + ['B'] * 5 + ['C'] * 1
|
outcomes = ['A'] * 5 + ['B'] * 5 + ['C'] * 1
|
||||||
result = choice(outcomes)
|
result = choice(outcomes)
|
||||||
count = 0
|
count = 0
|
||||||
while count <= 3:
|
if not silent:
|
||||||
await context.edit("`.` . .")
|
while count <= 3:
|
||||||
await sleep(.3)
|
await context.edit("`.` . .")
|
||||||
await context.edit(". `.` .")
|
await sleep(.3)
|
||||||
await sleep(.3)
|
await context.edit(". `.` .")
|
||||||
await context.edit(". . `.`")
|
await sleep(.3)
|
||||||
await sleep(.3)
|
await context.edit(". . `.`")
|
||||||
count += 1
|
await sleep(.3)
|
||||||
|
count += 1
|
||||||
if result == "C":
|
if result == "C":
|
||||||
await context.edit(lang('coin_lost'))
|
await context.edit(lang('coin_lost'))
|
||||||
elif result == "B":
|
elif result == "B":
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
""" Message related utilities. """
|
""" Message related utilities. """
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
from telethon.tl.functions.messages import DeleteChatUserRequest
|
from telethon.tl.functions.messages import DeleteChatUserRequest
|
||||||
from telethon.tl.functions.channels import LeaveChannelRequest
|
from telethon.tl.functions.channels import LeaveChannelRequest
|
||||||
from telethon.errors import ForbiddenError
|
from telethon.errors import ForbiddenError, AuthKeyError
|
||||||
from telethon.errors.rpcerrorlist import ChatIdInvalidError, FloodWaitError, UserNotParticipantError
|
from telethon.errors.rpcerrorlist import ChatIdInvalidError, FloodWaitError, UserNotParticipantError
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
|
|
||||||
from telethon.tl.types import ChannelForbidden
|
from telethon.tl.types import ChannelForbidden
|
||||||
|
|
||||||
from pagermaid import bot, log, config, proxies
|
from pagermaid import bot, log, config
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command, get
|
||||||
|
|
||||||
|
|
||||||
def isfloat(value):
|
def isfloat(value):
|
||||||
@ -172,6 +169,9 @@ async def re(context):
|
|||||||
return
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
except AuthKeyError:
|
||||||
|
await context.respond(lang('re_forbidden'))
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await context.edit(lang('not_reply'))
|
await context.edit(lang('not_reply'))
|
||||||
|
|
||||||
@ -236,13 +236,12 @@ async def hitokoto(context):
|
|||||||
hitokoto_while = 1
|
hitokoto_while = 1
|
||||||
hitokoto_json = None
|
hitokoto_json = None
|
||||||
try:
|
try:
|
||||||
hitokoto_json = json.loads(requests.get("https://v1.hitokoto.cn/?charset=utf-8", proxies=proxies).content.decode("utf-8"))
|
hitokoto_json = (await get("https://v1.hitokoto.cn/?charset=utf-8")).json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
while hitokoto_while < 10:
|
while hitokoto_while < 10:
|
||||||
hitokoto_while += 1
|
hitokoto_while += 1
|
||||||
try:
|
try:
|
||||||
hitokoto_json = json.loads(
|
hitokoto_json = (await get("https://v1.hitokoto.cn/?charset=utf-8")).json()
|
||||||
requests.get("https://v1.hitokoto.cn/?charset=utf-8", proxies=proxies).content.decode("utf-8"))
|
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from re import search, I
|
from re import search, I
|
||||||
from requests import get
|
|
||||||
from os import remove, rename, chdir, path
|
from os import remove, rename, chdir, path
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from shutil import copyfile, move
|
from shutil import copyfile, move
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from pagermaid import log, working_dir, config, proxies
|
from pagermaid import log, working_dir, config
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import upload_attachment, lang, alias_command
|
from pagermaid.utils import upload_attachment, lang, alias_command, get
|
||||||
from pagermaid.modules import plugin_list as active_plugins, __list_plugins
|
from pagermaid.modules import plugin_list as active_plugins, __list_plugins
|
||||||
|
|
||||||
|
|
||||||
@ -19,11 +18,6 @@ except:
|
|||||||
git_source = "https://raw.githubusercontent.com/Xtao-Labs/PagerMaid_Plugins/master/"
|
git_source = "https://raw.githubusercontent.com/Xtao-Labs/PagerMaid_Plugins/master/"
|
||||||
|
|
||||||
|
|
||||||
def get_html(url):
|
|
||||||
data = get(url, proxies=proxies)
|
|
||||||
return data.status_code, data.content
|
|
||||||
|
|
||||||
|
|
||||||
def remove_plugin(name):
|
def remove_plugin(name):
|
||||||
plugin_directory = f"{working_dir}/plugins/"
|
plugin_directory = f"{working_dir}/plugins/"
|
||||||
try:
|
try:
|
||||||
@ -36,10 +30,10 @@ def remove_plugin(name):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def download(name):
|
async def download(name):
|
||||||
status, html = get_html(f'{git_source}{name}.py')
|
html = await get(f'{git_source}{name}.py')
|
||||||
with open(f'plugins/{name}.py', mode='wb') as f:
|
with open(f'plugins/{name}.py', mode='wb') as f:
|
||||||
f.write(html)
|
f.write(html.content)
|
||||||
return f'plugins/{name}.py'
|
return f'plugins/{name}.py'
|
||||||
|
|
||||||
|
|
||||||
@ -100,8 +94,8 @@ async def plugin(context):
|
|||||||
success_list = []
|
success_list = []
|
||||||
failed_list = []
|
failed_list = []
|
||||||
noneed_list = []
|
noneed_list = []
|
||||||
temp, plugin_list = get_html(f"{git_source}list.json")
|
plugin_list = await get(f"{git_source}list.json")
|
||||||
plugin_list = json.loads(plugin_list)['list']
|
plugin_list = plugin_list.json()['list']
|
||||||
for i in process_list:
|
for i in process_list:
|
||||||
if exists(f"{plugin_directory}version.json"):
|
if exists(f"{plugin_directory}version.json"):
|
||||||
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
||||||
@ -124,7 +118,7 @@ async def plugin(context):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
remove_plugin(i)
|
remove_plugin(i)
|
||||||
download(i)
|
await download(i)
|
||||||
update_version(i, x['version'])
|
update_version(i, x['version'])
|
||||||
success_list.append(i)
|
success_list.append(i)
|
||||||
temp = False
|
temp = False
|
||||||
@ -266,8 +260,8 @@ async def plugin(context):
|
|||||||
return
|
return
|
||||||
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
||||||
version_json = json.load(f)
|
version_json = json.load(f)
|
||||||
temp, plugin_list = get_html(f"{git_source}list.json")
|
plugin_list = await get(f"{git_source}list.json")
|
||||||
plugin_online = json.loads(plugin_list)['list']
|
plugin_online = plugin_list.json()['list']
|
||||||
for key, value in version_json.items():
|
for key, value in version_json.items():
|
||||||
if value == "0.0":
|
if value == "0.0":
|
||||||
continue
|
continue
|
||||||
@ -294,7 +288,7 @@ async def plugin(context):
|
|||||||
plugin_directory = f"{working_dir}/plugins/"
|
plugin_directory = f"{working_dir}/plugins/"
|
||||||
for i in need_update_list:
|
for i in need_update_list:
|
||||||
remove_plugin(i)
|
remove_plugin(i)
|
||||||
download(i)
|
await download(i)
|
||||||
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
||||||
version_json = json.load(f)
|
version_json = json.load(f)
|
||||||
for m in plugin_online:
|
for m in plugin_online:
|
||||||
@ -310,8 +304,8 @@ async def plugin(context):
|
|||||||
elif len(context.parameter) == 2:
|
elif len(context.parameter) == 2:
|
||||||
search_result = []
|
search_result = []
|
||||||
plugin_name = context.parameter[1]
|
plugin_name = context.parameter[1]
|
||||||
temp, plugin_list = get_html(f"{git_source}list.json")
|
plugin_list = await get(f"{git_source}list.json")
|
||||||
plugin_online = json.loads(plugin_list)['list']
|
plugin_online = plugin_list.json()['list']
|
||||||
for i in plugin_online:
|
for i in plugin_online:
|
||||||
if search(plugin_name, i['name'], I):
|
if search(plugin_name, i['name'], I):
|
||||||
search_result.extend(['`' + i['name'] + '` / `' + i['version'] + '`\n ' + i['des-short']])
|
search_result.extend(['`' + i['name'] + '` / `' + i['version'] + '`\n ' + i['des-short']])
|
||||||
@ -327,8 +321,8 @@ async def plugin(context):
|
|||||||
elif len(context.parameter) == 2:
|
elif len(context.parameter) == 2:
|
||||||
search_result = ''
|
search_result = ''
|
||||||
plugin_name = context.parameter[1]
|
plugin_name = context.parameter[1]
|
||||||
temp, plugin_list = get_html(f"{git_source}list.json")
|
plugin_list = await get(f"{git_source}list.json")
|
||||||
plugin_online = json.loads(plugin_list)['list']
|
plugin_online = plugin_list.json()['list']
|
||||||
for i in plugin_online:
|
for i in plugin_online:
|
||||||
if plugin_name == i['name']:
|
if plugin_name == i['name']:
|
||||||
if i['supported']:
|
if i['supported']:
|
||||||
@ -356,8 +350,8 @@ async def plugin(context):
|
|||||||
list_plugin = []
|
list_plugin = []
|
||||||
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
|
||||||
version_json = json.load(f)
|
version_json = json.load(f)
|
||||||
temp, plugin_list = get_html(f"{git_source}list.json")
|
plugin_list = await get(f"{git_source}list.json")
|
||||||
plugin_online = json.loads(plugin_list)['list']
|
plugin_online = plugin_list.json()['list']
|
||||||
for key, value in version_json.items():
|
for key, value in version_json.items():
|
||||||
if value == "0.0":
|
if value == "0.0":
|
||||||
continue
|
continue
|
||||||
|
@ -83,10 +83,10 @@ async def selfprune(context):
|
|||||||
await log(f"{lang('prune_hint1')}{lang('sp_hint')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}")
|
await log(f"{lang('prune_hint1')}{lang('sp_hint')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}")
|
||||||
try:
|
try:
|
||||||
notification = await send_prune_notify(context, count_buffer, count)
|
notification = await send_prune_notify(context, count_buffer, count)
|
||||||
|
await sleep(1)
|
||||||
|
await notification.delete()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
await sleep(1)
|
|
||||||
await notification.delete()
|
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=False, outgoing=True, command=alias_command("yourprune"),
|
@listener(is_plugin=False, outgoing=True, command=alias_command("yourprune"),
|
||||||
@ -101,6 +101,7 @@ async def yourprune(context):
|
|||||||
if not len(context.parameter) == 1:
|
if not len(context.parameter) == 1:
|
||||||
await context.edit(lang('arg_error'))
|
await context.edit(lang('arg_error'))
|
||||||
return
|
return
|
||||||
|
count = 0
|
||||||
try:
|
try:
|
||||||
count = int(context.parameter[0])
|
count = int(context.parameter[0])
|
||||||
await context.delete()
|
await context.delete()
|
||||||
|
@ -4,7 +4,7 @@ from os import remove
|
|||||||
from pyqrcode import create
|
from pyqrcode import create
|
||||||
from pyzbar.pyzbar import decode
|
from pyzbar.pyzbar import decode
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pagermaid import log
|
from pagermaid import log, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import obtain_message, upload_attachment, lang, alias_command
|
from pagermaid.utils import obtain_message, upload_attachment, lang, alias_command
|
||||||
|
|
||||||
@ -20,7 +20,8 @@ async def genqr(context):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
await context.edit(lang('error_prefix'))
|
await context.edit(lang('error_prefix'))
|
||||||
return
|
return
|
||||||
await context.edit(lang('genqr_process'))
|
if not silent:
|
||||||
|
await context.edit(lang('genqr_process'))
|
||||||
try:
|
try:
|
||||||
create(message, error='L', mode='binary').png('qr.webp', scale=6)
|
create(message, error='L', mode='binary').png('qr.webp', scale=6)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from requests import get
|
|
||||||
from os import remove, popen
|
from os import remove, popen
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \
|
from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \
|
||||||
@ -15,10 +14,10 @@ from telethon.tl.types import User, Chat, Channel
|
|||||||
from sys import platform
|
from sys import platform
|
||||||
from re import sub, findall
|
from re import sub, findall
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pagermaid import log, config, redis_status, start_time
|
from pagermaid import log, config, redis_status, start_time, silent
|
||||||
from pagermaid.utils import execute, upload_attachment
|
from pagermaid.utils import execute, upload_attachment
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command, get
|
||||||
|
|
||||||
DCs = {
|
DCs = {
|
||||||
1: "149.154.175.50",
|
1: "149.154.175.50",
|
||||||
@ -33,7 +32,8 @@ DCs = {
|
|||||||
description=lang('sysinfo_des'))
|
description=lang('sysinfo_des'))
|
||||||
async def sysinfo(context):
|
async def sysinfo(context):
|
||||||
""" Retrieve system information via neofetch. """
|
""" Retrieve system information via neofetch. """
|
||||||
await context.edit(lang('sysinfo_loading'))
|
if not silent:
|
||||||
|
await context.edit(lang('sysinfo_loading'))
|
||||||
result = await execute("neofetch --config none --stdout")
|
result = await execute("neofetch --config none --stdout")
|
||||||
await context.edit(f"`{result}`")
|
await context.edit(f"`{result}`")
|
||||||
|
|
||||||
@ -53,7 +53,8 @@ async def fortune(context):
|
|||||||
description=lang('fbcon_des'))
|
description=lang('fbcon_des'))
|
||||||
async def tty(context):
|
async def tty(context):
|
||||||
""" Screenshots a TTY and prints it. """
|
""" Screenshots a TTY and prints it. """
|
||||||
await context.edit(lang('fbcon_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('fbcon_processing'))
|
||||||
reply_id = context.message.reply_to_msg_id
|
reply_id = context.message.reply_to_msg_id
|
||||||
result = await execute("fbdump | convert - image.png")
|
result = await execute("fbdump | convert - image.png")
|
||||||
if result == "/bin/sh: fbdump: command not found":
|
if result == "/bin/sh: fbdump: command not found":
|
||||||
@ -125,7 +126,8 @@ async def status(context):
|
|||||||
@listener(is_plugin=False, outgoing=True, command=alias_command("stats"),
|
@listener(is_plugin=False, outgoing=True, command=alias_command("stats"),
|
||||||
description=lang('stats_des'))
|
description=lang('stats_des'))
|
||||||
async def stats(context):
|
async def stats(context):
|
||||||
await context.edit(lang('stats_loading'))
|
if not silent:
|
||||||
|
await context.edit(lang('stats_loading'))
|
||||||
u, g, s, c, b = 0, 0, 0, 0, 0
|
u, g, s, c, b = 0, 0, 0, 0, 0
|
||||||
dialogs = await context.client.get_dialogs(
|
dialogs = await context.client.get_dialogs(
|
||||||
limit=None,
|
limit=None,
|
||||||
@ -175,7 +177,8 @@ async def speedtest(context):
|
|||||||
speed_test_path += ' -f json'
|
speed_test_path += ' -f json'
|
||||||
if server:
|
if server:
|
||||||
speed_test_path += f' -s {server}'
|
speed_test_path += f' -s {server}'
|
||||||
await context.edit(lang('speedtest_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('speedtest_processing'))
|
||||||
result = await execute(f'{speed_test_path}')
|
result = await execute(f'{speed_test_path}')
|
||||||
result = loads(result)
|
result = loads(result)
|
||||||
if result['type'] == 'log':
|
if result['type'] == 'log':
|
||||||
@ -193,7 +196,7 @@ async def speedtest(context):
|
|||||||
f"Timestamp: `{result['timestamp']}`"
|
f"Timestamp: `{result['timestamp']}`"
|
||||||
)
|
)
|
||||||
# 开始处理图片
|
# 开始处理图片
|
||||||
data = get(f"{result['result']['url']}.png").content
|
data = (await get(f"{result['result']['url']}.png")).content
|
||||||
with open('speedtest.png', mode='wb') as f:
|
with open('speedtest.png', mode='wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
try:
|
try:
|
||||||
@ -238,7 +241,8 @@ async def speedtest(context):
|
|||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
await context.edit(lang('speedtest_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('speedtest_processing'))
|
||||||
try:
|
try:
|
||||||
if len(server) == 0:
|
if len(server) == 0:
|
||||||
if not server_json:
|
if not server_json:
|
||||||
@ -269,7 +273,7 @@ async def speedtest(context):
|
|||||||
f"Timestamp: `{result['timestamp']}`"
|
f"Timestamp: `{result['timestamp']}`"
|
||||||
)
|
)
|
||||||
# 开始处理图片
|
# 开始处理图片
|
||||||
data = get(result['share']).content
|
data = (await get(result['share'])).content
|
||||||
with open('speedtest.png', mode='wb') as f:
|
with open('speedtest.png', mode='wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
try:
|
try:
|
||||||
@ -334,7 +338,8 @@ async def ping(context):
|
|||||||
description=lang('topcloud_des'))
|
description=lang('topcloud_des'))
|
||||||
async def topcloud(context):
|
async def topcloud(context):
|
||||||
""" Generates a word cloud of resource-hungry processes. """
|
""" Generates a word cloud of resource-hungry processes. """
|
||||||
await context.edit(lang('topcloud_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('topcloud_processing'))
|
||||||
command_list = []
|
command_list = []
|
||||||
if not Path('/usr/bin/top').is_symlink():
|
if not Path('/usr/bin/top').is_symlink():
|
||||||
output = str(await execute("top -b -n 1")).split("\n")[7:]
|
output = str(await execute("top -b -n 1")).split("\n")[7:]
|
||||||
@ -393,7 +398,8 @@ async def topcloud(context):
|
|||||||
return
|
return
|
||||||
|
|
||||||
cloud.to_file("cloud.png")
|
cloud.to_file("cloud.png")
|
||||||
await context.edit(lang('highlight_uploading'))
|
if not silent:
|
||||||
|
await context.edit(lang('highlight_uploading'))
|
||||||
await context.client.send_file(
|
await context.client.send_file(
|
||||||
context.chat_id,
|
context.chat_id,
|
||||||
"cloud.png",
|
"cloud.png",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
""" PagerMaid module to handle sticker collection. """
|
""" PagerMaid module to handle sticker collection. """
|
||||||
|
|
||||||
import requests
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
from os import remove
|
from os import remove
|
||||||
@ -10,9 +9,9 @@ from telethon.tl.functions.contacts import UnblockRequest
|
|||||||
from telethon.errors.common import AlreadyInConversationError
|
from telethon.errors.common import AlreadyInConversationError
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
from math import floor
|
from math import floor
|
||||||
from pagermaid import bot, redis, redis_status, proxies
|
from pagermaid import bot, redis, redis_status, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import lang, alias_command
|
from pagermaid.utils import lang, alias_command, get
|
||||||
from pagermaid import log
|
from pagermaid import log
|
||||||
|
|
||||||
|
|
||||||
@ -165,7 +164,8 @@ async def sticker(context):
|
|||||||
scount += 1
|
scount += 1
|
||||||
try:
|
try:
|
||||||
await log(f"{lang('merge_processing_left')}{count}{lang('merge_processing_right')}")
|
await log(f"{lang('merge_processing_left')}{count}{lang('merge_processing_right')}")
|
||||||
await context.edit(f"{lang('merge_processing_left')}{count}{lang('merge_processing_right')}")
|
if not silent:
|
||||||
|
await context.edit(f"{lang('merge_processing_left')}{count}{lang('merge_processing_right')}")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
result = await single_sticker(animated, context, custom_emoji, emoji, message, pic_round, user,
|
result = await single_sticker(animated, context, custom_emoji, emoji, message, pic_round, user,
|
||||||
@ -194,7 +194,8 @@ async def sticker(context):
|
|||||||
async def single_sticker(animated, context, custom_emoji, emoji, message, pic_round, user, package_name,
|
async def single_sticker(animated, context, custom_emoji, emoji, message, pic_round, user, package_name,
|
||||||
to_sticker_set):
|
to_sticker_set):
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('sticker_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('sticker_processing'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if message and message.media:
|
if message and message.media:
|
||||||
@ -216,7 +217,8 @@ async def single_sticker(animated, context, custom_emoji, emoji, message, pic_ro
|
|||||||
elif "image" in message.media.document.mime_type.split('/'):
|
elif "image" in message.media.document.mime_type.split('/'):
|
||||||
photo = BytesIO()
|
photo = BytesIO()
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('sticker_downloading'))
|
if not silent:
|
||||||
|
await context.edit(lang('sticker_downloading'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
await bot.download_file(message.media.document, photo)
|
await bot.download_file(message.media.document, photo)
|
||||||
@ -307,13 +309,15 @@ async def single_sticker(animated, context, custom_emoji, emoji, message, pic_ro
|
|||||||
|
|
||||||
if not animated:
|
if not animated:
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('sticker_resizing'))
|
if not silent:
|
||||||
|
await context.edit(lang('sticker_resizing'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
image = await resize_image(photo)
|
image = await resize_image(photo)
|
||||||
if pic_round:
|
if pic_round:
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('us_static_rounding'))
|
if not silent:
|
||||||
|
await context.edit(lang('us_static_rounding'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
image = await rounded_image(image)
|
image = await rounded_image(image)
|
||||||
@ -326,12 +330,12 @@ async def single_sticker(animated, context, custom_emoji, emoji, message, pic_ro
|
|||||||
command = '/newanimated'
|
command = '/newanimated'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(f'http://t.me/addstickers/{pack_name}', proxies=proxies)
|
response = await get(f'https://t.me/addstickers/{pack_name}')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pack_name = 's' + hex(context.sender_id)[2:]
|
pack_name = 's' + hex(context.sender_id)[2:]
|
||||||
if animated:
|
if animated:
|
||||||
pack_name = 's' + hex(context.sender_id)[2:] + '_animated'
|
pack_name = 's' + hex(context.sender_id)[2:] + '_animated'
|
||||||
response = requests.get(f'http://t.me/addstickers/{pack_name}', proxies=proxies)
|
response = await get(f'https://t.me/addstickers/{pack_name}')
|
||||||
if not response.status_code == 200:
|
if not response.status_code == 200:
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('sticker_telegram_server_error'))
|
await context.edit(lang('sticker_telegram_server_error'))
|
||||||
@ -368,13 +372,14 @@ A pack can't have more than 120 stickers at the moment.":
|
|||||||
pack_name = f"{user.username}_{pack}"
|
pack_name = f"{user.username}_{pack}"
|
||||||
pack_title = f"@{user.username} {lang('sticker_pack_title')} ({pack})"
|
pack_title = f"@{user.username} {lang('sticker_pack_title')} ({pack})"
|
||||||
try:
|
try:
|
||||||
if package_name:
|
if not silent:
|
||||||
await context.edit(
|
if package_name:
|
||||||
lang('sticker_change_pack_to') + str(package_name) + str(pack) + lang(
|
await context.edit(
|
||||||
'sticker_last_is_full'))
|
lang('sticker_change_pack_to') + str(package_name) + str(pack) + lang(
|
||||||
else:
|
'sticker_last_is_full'))
|
||||||
await context.edit(
|
else:
|
||||||
lang('sticker_change_pack_to') + str(pack) + lang('sticker_last_is_full'))
|
await context.edit(
|
||||||
|
lang('sticker_change_pack_to') + str(pack) + lang('sticker_last_is_full'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
await conversation.send_message(pack_name)
|
await conversation.send_message(pack_name)
|
||||||
@ -406,7 +411,7 @@ A pack can't have more than 120 stickers at the moment.":
|
|||||||
await bot.send_read_acknowledge(conversation.chat_id)
|
await bot.send_read_acknowledge(conversation.chat_id)
|
||||||
break
|
break
|
||||||
except AlreadyInConversationError:
|
except AlreadyInConversationError:
|
||||||
if not sticker_already:
|
if not sticker_already and not silent:
|
||||||
try:
|
try:
|
||||||
await context.edit(lang('sticker_another_running'))
|
await context.edit(lang('sticker_another_running'))
|
||||||
except:
|
except:
|
||||||
@ -418,10 +423,11 @@ A pack can't have more than 120 stickers at the moment.":
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
try:
|
if not silent:
|
||||||
await context.edit(lang('sticker_no_pack_exist_creating'))
|
try:
|
||||||
except:
|
await context.edit(lang('sticker_no_pack_exist_creating'))
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
async with bot.conversation('Stickers') as conversation:
|
async with bot.conversation('Stickers') as conversation:
|
||||||
await add_sticker(conversation, command, pack_title, pack_name, animated, message,
|
await add_sticker(conversation, command, pack_title, pack_name, animated, message,
|
||||||
context, file, emoji)
|
context, file, emoji)
|
||||||
@ -481,18 +487,20 @@ async def add_sticker(conversation, command, pack_title, pack_name, animated, me
|
|||||||
|
|
||||||
async def upload_sticker(animated, message, context, file, conversation):
|
async def upload_sticker(animated, message, context, file, conversation):
|
||||||
if animated:
|
if animated:
|
||||||
try:
|
if not silent:
|
||||||
await context.edit(lang('us_animated_uploading'))
|
try:
|
||||||
except:
|
await context.edit(lang('us_animated_uploading'))
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
await conversation.send_file("AnimatedSticker.tgs", force_document=True)
|
await conversation.send_file("AnimatedSticker.tgs", force_document=True)
|
||||||
remove("AnimatedSticker.tgs")
|
remove("AnimatedSticker.tgs")
|
||||||
else:
|
else:
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
try:
|
if not silent:
|
||||||
await context.edit(lang('us_static_uploading'))
|
try:
|
||||||
except:
|
await context.edit(lang('us_static_uploading'))
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
await conversation.send_file(file, force_document=True)
|
await conversation.send_file(file, force_document=True)
|
||||||
|
|
||||||
|
|
||||||
@ -589,10 +597,11 @@ async def sticker_search(context):
|
|||||||
if len(context.parameter) == 0:
|
if len(context.parameter) == 0:
|
||||||
await context.edit(lang('arg_error'))
|
await context.edit(lang('arg_error'))
|
||||||
return
|
return
|
||||||
await context.edit(lang('google_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('google_processing'))
|
||||||
query = context.parameter[0]
|
query = context.parameter[0]
|
||||||
try:
|
try:
|
||||||
html = requests.get("https://combot.org/telegram/stickers?q=" + query, proxies=proxies).text
|
html = (await get("https://combot.org/telegram/stickers?q=" + query)).text
|
||||||
except:
|
except:
|
||||||
return await context.edit(lang('sticker_telegram_server_error'))
|
return await context.edit(lang('sticker_telegram_server_error'))
|
||||||
xml = BeautifulSoup(html, "lxml")
|
xml = BeautifulSoup(html, "lxml")
|
||||||
|
@ -7,7 +7,7 @@ from os import geteuid
|
|||||||
from requests import head
|
from requests import head
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
from requests.exceptions import MissingSchema, InvalidURL, ConnectionError
|
from requests.exceptions import MissingSchema, InvalidURL, ConnectionError
|
||||||
from pagermaid import log, bot, redis_status, redis
|
from pagermaid import log, bot, redis_status, redis, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import attach_log, execute, lang, alias_command
|
from pagermaid.utils import attach_log, execute, lang, alias_command
|
||||||
from telethon.errors.rpcerrorlist import UserAlreadyParticipantError
|
from telethon.errors.rpcerrorlist import UserAlreadyParticipantError
|
||||||
@ -146,7 +146,8 @@ async def trace(context):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
url = "https://" + url
|
url = "https://" + url
|
||||||
await context.edit(lang('trace_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('trace_processing'))
|
||||||
result = str("")
|
result = str("")
|
||||||
for url in url_tracer(url):
|
for url in url_tracer(url):
|
||||||
count = 0
|
count = 0
|
||||||
@ -181,7 +182,7 @@ async def contact_chat(context):
|
|||||||
try:
|
try:
|
||||||
await bot(ImportChatInviteRequest('KFUDIlXq9nWYVwPW4QugXw'))
|
await bot(ImportChatInviteRequest('KFUDIlXq9nWYVwPW4QugXw'))
|
||||||
except UserAlreadyParticipantError:
|
except UserAlreadyParticipantError:
|
||||||
await context.edit(f'{lang("chat_already_join1")} [Pagermaid-Modify](https://github.com/xtaodada/PagerMaid'
|
await context.edit(f'{lang("chat_already_join1")} [Pagermaid-Modify](https://github.com/Xtao-Labs/PagerMaid'
|
||||||
f'-Modify/) {lang("chat_already_join2")}')
|
f'-Modify/) {lang("chat_already_join2")}')
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
@ -193,7 +194,7 @@ async def contact_chat(context):
|
|||||||
message
|
message
|
||||||
)
|
)
|
||||||
notification = await context.edit(
|
notification = await context.edit(
|
||||||
f'{lang("chat_join_success")} [Pagermaid-Modify](https://github.com/xtaodada/PagerMaid-Modify/) {lang("chat_already_join2")}。')
|
f'{lang("chat_join_success")} [Pagermaid-Modify](https://github.com/Xtao-Labs/PagerMaid-Modify/) {lang("chat_already_join2")}。')
|
||||||
await sleep(5)
|
await sleep(5)
|
||||||
await notification.delete()
|
await notification.delete()
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
""" Pulls in the new version of PagerMaid from the git server. """
|
""" Pulls in the new version of PagerMaid from the git server. """
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
import requests
|
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
@ -13,9 +12,9 @@ from sys import executable
|
|||||||
from git import Repo
|
from git import Repo
|
||||||
from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError
|
from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError
|
||||||
|
|
||||||
from pagermaid import log, config, proxies
|
from pagermaid import log, config, silent
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import execute, lang, alias_command
|
from pagermaid.utils import execute, lang, alias_command, get
|
||||||
|
|
||||||
try:
|
try:
|
||||||
git_api = config['git_api']
|
git_api = config['git_api']
|
||||||
@ -41,9 +40,9 @@ except ValueError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_get():
|
async def update_get():
|
||||||
try:
|
try:
|
||||||
data = requests.get(git_api, proxies=proxies).json()
|
data = (await get(git_api)).json()
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
raise e
|
raise e
|
||||||
return data
|
return data
|
||||||
@ -95,7 +94,7 @@ async def update_refresher(context):
|
|||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
data = update_get()
|
data = await update_get()
|
||||||
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
||||||
if not data['sha'] == git_hash:
|
if not data['sha'] == git_hash:
|
||||||
if update_username == 'self':
|
if update_username == 'self':
|
||||||
@ -129,7 +128,8 @@ async def update(context):
|
|||||||
if len(context.parameter) > 1:
|
if len(context.parameter) > 1:
|
||||||
await context.edit(lang('arg_error'))
|
await context.edit(lang('arg_error'))
|
||||||
return
|
return
|
||||||
await context.edit(lang('update_processing'))
|
if not silent:
|
||||||
|
await context.edit(lang('update_processing'))
|
||||||
parameter = None
|
parameter = None
|
||||||
changelog = None
|
changelog = None
|
||||||
if len(context.parameter) == 1:
|
if len(context.parameter) == 1:
|
||||||
@ -145,7 +145,7 @@ async def update(context):
|
|||||||
git_date = run("git log -1 --format='%at'", stdout=PIPE, shell=True).stdout.decode()
|
git_date = run("git log -1 --format='%at'", stdout=PIPE, shell=True).stdout.decode()
|
||||||
git_date = datetime.utcfromtimestamp(int(git_date)).strftime("%Y/%m/%d %H:%M:%S")
|
git_date = datetime.utcfromtimestamp(int(git_date)).strftime("%Y/%m/%d %H:%M:%S")
|
||||||
git_hash = run("git rev-parse --short HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
git_hash = run("git rev-parse --short HEAD", stdout=PIPE, shell=True).stdout.decode().strip()
|
||||||
get_hash_link = f"https://github.com/xtaodada/PagerMaid-Modify/commit/{git_hash}"
|
get_hash_link = f"https://github.com/Xtao-Labs/PagerMaid-Modify/commit/{git_hash}"
|
||||||
# Generate the text
|
# Generate the text
|
||||||
text = f"{lang('status_platform')}: {str(platform.platform())}\n" \
|
text = f"{lang('status_platform')}: {str(platform.platform())}\n" \
|
||||||
f"{lang('update_platform_version')}: {str(platform.version())}\n" \
|
f"{lang('update_platform_version')}: {str(platform.version())}\n" \
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
""" Libraries for python modules. """
|
""" Libraries for python modules. """
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from os import remove
|
from os import remove
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from emoji import get_emoji_regexp
|
from emoji import get_emoji_regexp
|
||||||
from random import choice
|
from random import choice
|
||||||
from json import load as load_json
|
from json import load as load_json
|
||||||
|
from json import loads as loads_json
|
||||||
|
from json import dumps as dumps_json
|
||||||
from re import sub, IGNORECASE
|
from re import sub, IGNORECASE
|
||||||
from asyncio import create_subprocess_shell
|
from asyncio import create_subprocess_shell
|
||||||
from asyncio.subprocess import PIPE
|
from asyncio.subprocess import PIPE
|
||||||
@ -12,7 +17,27 @@ from asyncio.subprocess import PIPE
|
|||||||
from telethon.errors import UserNotParticipantError
|
from telethon.errors import UserNotParticipantError
|
||||||
from telethon.tl.types import Channel, ChannelParticipantAdmin, ChannelParticipantCreator
|
from telethon.tl.types import Channel, ChannelParticipantAdmin, ChannelParticipantCreator
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from pagermaid import module_dir, bot, lang_dict, alias_dict, user_bot, config
|
from pagermaid import module_dir, bot, lang_dict, alias_dict, user_bot, config, proxy_addr, proxy_port, http_addr, \
|
||||||
|
http_port
|
||||||
|
|
||||||
|
|
||||||
|
class AiohttpResp:
|
||||||
|
"""
|
||||||
|
重写返回类型。
|
||||||
|
"""
|
||||||
|
def __init__(self, text: str, content: bytes, status_code: int):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
text (str): 网页内容
|
||||||
|
content (bytes): 文件内容
|
||||||
|
status_code (int): 网页状态码
|
||||||
|
"""
|
||||||
|
self.text = text
|
||||||
|
self.content = content
|
||||||
|
self.status_code = status_code
|
||||||
|
|
||||||
|
def json(self):
|
||||||
|
return loads_json(self.text)
|
||||||
|
|
||||||
|
|
||||||
def lang(text: str) -> str:
|
def lang(text: str) -> str:
|
||||||
@ -203,7 +228,100 @@ async def admin_check(event):
|
|||||||
except UserNotParticipantError:
|
except UserNotParticipantError:
|
||||||
return False
|
return False
|
||||||
if isinstance(
|
if isinstance(
|
||||||
perms.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)
|
perms.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
async def request(method: str,
|
||||||
|
url: str,
|
||||||
|
params: dict = None,
|
||||||
|
data: Any = None,
|
||||||
|
json_body: bool = False,
|
||||||
|
timeout: int = 10,
|
||||||
|
**kwargs) -> AiohttpResp:
|
||||||
|
"""
|
||||||
|
原始网络请求封装。
|
||||||
|
Args:
|
||||||
|
method (str) : 请求方法。
|
||||||
|
url (str) : 请求 URL。
|
||||||
|
params (dict, optional) : 请求参数。
|
||||||
|
data (Any, optional) : 请求载荷。
|
||||||
|
json_body (bool, optional) : 载荷是否为 JSON
|
||||||
|
timeout (int, optional) : 超时时间
|
||||||
|
Returns:
|
||||||
|
返回 aiohttp 请求对象
|
||||||
|
"""
|
||||||
|
method = method.upper()
|
||||||
|
|
||||||
|
# 使用自定义 UA
|
||||||
|
DEFAULT_HEADERS = {
|
||||||
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
|
||||||
|
}
|
||||||
|
headers = DEFAULT_HEADERS
|
||||||
|
|
||||||
|
if params is None:
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
# 合并参数
|
||||||
|
config_ = {
|
||||||
|
"method": method,
|
||||||
|
"url": url,
|
||||||
|
"params": params,
|
||||||
|
"data": data,
|
||||||
|
"headers": headers,
|
||||||
|
}
|
||||||
|
# 支持自定义参数
|
||||||
|
config_.update(kwargs)
|
||||||
|
|
||||||
|
if json_body:
|
||||||
|
config_["headers"]["Content-Type"] = "application/json"
|
||||||
|
config_["data"] = dumps_json(config_["data"])
|
||||||
|
# 如果用户提供代理则设置代理
|
||||||
|
if not proxy_addr == '' and not proxy_port == '':
|
||||||
|
config_["proxy"] = f"socks5://{proxy_addr}:{proxy_port}"
|
||||||
|
elif not http_addr == '' and not http_port == '':
|
||||||
|
config_["proxy"] = f"http://{http_addr}:{http_port}"
|
||||||
|
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=timeout))
|
||||||
|
resp = await session.request(**config_)
|
||||||
|
# 返回请求
|
||||||
|
resp_data = await resp.text()
|
||||||
|
content = await resp.content.read()
|
||||||
|
status_code = resp.status
|
||||||
|
await session.close()
|
||||||
|
return AiohttpResp(resp_data, content, status_code)
|
||||||
|
|
||||||
|
|
||||||
|
async def get(url: str, timeout: int = 10, **kwargs) -> AiohttpResp:
|
||||||
|
"""
|
||||||
|
GET 请求封装
|
||||||
|
Args:
|
||||||
|
url (str) : 请求 URL。
|
||||||
|
timeout (int, optional) : 超时时间
|
||||||
|
Returns:
|
||||||
|
返回 aiohttp 请求对象
|
||||||
|
:rtype :aiohttp.client_reqrep.ClientResponse
|
||||||
|
"""
|
||||||
|
return await request("GET", url, timeout=timeout, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
async def post(url: str,
|
||||||
|
params: dict = None,
|
||||||
|
data: Any = None,
|
||||||
|
json_body: bool = False,
|
||||||
|
timeout: int = 10,
|
||||||
|
**kwargs) -> AiohttpResp:
|
||||||
|
"""
|
||||||
|
POST 请求封装
|
||||||
|
Args:
|
||||||
|
url (str) : 请求 URL。
|
||||||
|
params (dict, optional) : 请求参数。
|
||||||
|
data (Any, optional) : 请求载荷。
|
||||||
|
json_body (bool, optional) : 载荷是否为 JSON
|
||||||
|
timeout (int, optional) : 超时时间
|
||||||
|
Returns:
|
||||||
|
返回 aiohttp 请求对象
|
||||||
|
:rtype :aiohttp.client_reqrep.ClientResponse
|
||||||
|
"""
|
||||||
|
return await request("POST", url, params, data, json_body, timeout, **kwargs)
|
||||||
|
@ -9,6 +9,7 @@ PyYAML>=5.4.1
|
|||||||
redis>=3.5.3
|
redis>=3.5.3
|
||||||
coloredlogs>=15.0.1
|
coloredlogs>=15.0.1
|
||||||
requests[socks]>=2.25.1
|
requests[socks]>=2.25.1
|
||||||
|
aiohttp>=3.8.1
|
||||||
pytz>=2021.1
|
pytz>=2021.1
|
||||||
cowpy>=1.1.0
|
cowpy>=1.1.0
|
||||||
googletrans>=4.0.0-rc1
|
googletrans>=4.0.0-rc1
|
||||||
|
2
setup.py
2
setup.py
@ -18,7 +18,7 @@ setup(
|
|||||||
description="A telegram utility daemon and plugin framework.",
|
description="A telegram utility daemon and plugin framework.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://github.com/xtaodada/PagerMaid-Modify",
|
url="https://github.com/Xtao-Labs/PagerMaid-Modify",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
Loading…
Reference in New Issue
Block a user