Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2

Merged
merged 29 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

基于clash 核心运作的、进行全量订阅测试的telegram机器人

# 最近更新(3.3.5)
- 配置文件优化,代理相关配置统一为proxy键值对,旧版代理配置proxyport仍旧可用,但已废弃。推荐使用proxy配置,proxyport配置在启动时会发出警告。
- 节点分析新增出口ip显示,用于判断复用节点,ip仅显示最后一位。
- 优化help指令,不同权限组看到的内容不同。
- 新增 /version 指令用于查询当前版本信息
- 自定义字体。可通过在配置文件添加 font键值对自定义你喜欢的字体,具体案例查看配置模板。
- 新增延迟配色。可通过配置文件修改想要的配色。具体使用方法查看config.yaml.example
- 修复部分不合法的输入,会导致任务无限阻塞的bug。
# 最近更新(3.3.7)

- 新增Netflix新检测方法,优化新版奈飞检测逻辑。
- bot的操作界面优化。新增节点存活率、御三家(Netflix、disney+、Youtube)按钮,新增取消任务按钮。
- 优化 login.py 文件。现如今不会强制要求输入代理(之前必须提供代理)。
- 修复bot因任务源消息被群组管理员删除导致崩溃的问题。
- 修复speedtest绘图偶现出错问题。
- 修复UDP类型检测偶现失败问题。
- 修复emoji源中,部分emoji不全导致生成图片出错的问题
- 修复节点拓扑测试生成图片宽度不一致的问题
- 移动 emoji_custom.py 到 ./addons 目录中,因为它更像一个插件功能。


历史更新请到TG频道查看:
Expand Down Expand Up @@ -66,33 +69,33 @@ FullTclash bot 是承载其测试任务的Telegram 机器人(以下简称bot

## 环境准备

- Python 3.5 以上

- aiohttp>=3.8.1

- aiohttp_socks>=0.7.1

- async_timeout>=4.0.2

- beautifulsoup4>=4.11.1

- Pillow>=9.2.0

- pilmoji>=2.0.1

- Pyrogram>=2.0.26

- PyYAML>=6.0
- Python 3.6 以上

- requests>=2.26.0
- 以及各种相关包依赖


您可以用以下命令,在当前项目目录下运行以快速安装环境(Windows):
您可以用以下命令,在当前项目目录下运行以快速安装环境:

Windows:

```
pip install -r requirements.txt
```

Linux:
```
pip3 install -r requirements.txt
```

## 拉取源码

方法1:直接下载(不会有人不知道在哪下吧?)

方法2:使用git(Linux推荐,方便更新),首先安装git,然后拉取仓库。以下指令为 Ubuntu 发行版作示例,Windows自行解决。
```
apt install -y git && git clone https://github.com/AirportR/FullTclash.git && cd FullTclash
```
此方法在中国大陆可能需要代理加速,请自行解决。
## 获取session文件

您需要在项目文件目录下,放置一个已经登陆好的.session后缀文件,这个文件是程序生成的,形如: my_bot.session
Expand All @@ -110,7 +113,7 @@ python .\login.py

这句话时,即可说明该session文件有效,否则无效。

## 赋予clash核心执行权限(Linux amd64)
## 赋予clash核心执行权限 (Linux)

Windows系统无需此操作
```
Expand Down
138 changes: 138 additions & 0 deletions addons/emoji_custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import contextlib
import re
from io import BytesIO
from typing import ClassVar, Optional

import pilmoji
import requests
from emoji import demojize

"""
自定义的emoji表情源
保留原作者信息
author: https://github.com/Oreomeow
"""


class EmojiPediaSource(pilmoji.source.DiscordEmojiSourceMixin):
"""A base source that fetches emojis from emojipedia."""

BASE_EMOJIPEDIA_URL: ClassVar[
str
] = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/"
STYLE: ClassVar[Optional[str]] = None

def get_emoji(self, emoji: str, /) -> Optional[BytesIO]: # type: ignore
if self.STYLE is None:
raise TypeError("STYLE class variable unfilled.")

name = demojize(emoji).strip(":️").replace("_", "-")
if name[0].isupper():
name = f"flag-{name.lower()}"
uni = re.sub(
r"\\u0*",
"-",
emoji.encode("unicode_escape").decode("utf-8"),
flags=re.IGNORECASE,
).lstrip("-")
url = self.BASE_EMOJIPEDIA_URL + self.STYLE + name + "_" + uni + ".png"

with contextlib.suppress(requests.HTTPError):
return BytesIO(self.request(url))


class ApplePediaSource(EmojiPediaSource):
"""A source that uses Apple emojis."""

STYLE = "apple/325/"


class GooglePediaSource(EmojiPediaSource):
"""A source that uses Google Noto Color Emoji emojis."""

STYLE = "google/346/"


class SamsungPediaSource(EmojiPediaSource):
"""A source that uses Samsung emojis."""

STYLE = "samsung/320/"


class MicrosoftPediaSource(EmojiPediaSource):
"""A source that uses Microsoft emojis."""

STYLE = "microsoft/319/"


class WhatsAppPediaSource(EmojiPediaSource):
"""A source that uses WhatsApp emojis."""

STYLE = "whatsapp/326/"


class TwitterPediaSource(EmojiPediaSource):
"""A source that uses Twitter emojis."""

STYLE = "twitter/322/"


class FacebookPediaSource(EmojiPediaSource):
"""A source that uses Facebook emojis."""

STYLE = "facebook/327/"


class MicrosoftTeamsPediaSource(EmojiPediaSource):
"""A source that uses Microsoft Teams emojis."""

STYLE = "microsoft-teams/337/"


class SkypePediaSource(EmojiPediaSource):
"""A source that uses Skype emojis."""

STYLE = "skype/289/"


class JoyPixelsPediaSource(EmojiPediaSource):
"""A source that uses JoyPixels emojis."""

STYLE = "joypixels/340/"


class TossFacePediaSource(EmojiPediaSource):
"""A source that uses TossFace emojis."""

STYLE = "toss-face/342/"


__all__ = [
"ApplePediaSource",
"GooglePediaSource",
"SamsungPediaSource",
"MicrosoftPediaSource",
"WhatsAppPediaSource",
"TwitterPediaSource",
"FacebookPediaSource",
"MicrosoftTeamsPediaSource",
"SkypePediaSource",
"JoyPixelsPediaSource",
"TossFacePediaSource",
]


if __name__ == "__main__":
from PIL import Image, ImageFont

my_string = """
Hello, world! 👋 Here are some emojis: 🎨 🌊 😎
"""

with Image.new("RGB", (550, 80), (255, 255, 255)) as image:
font = ImageFont.truetype("arial.ttf", 24)

with pilmoji.Pilmoji(image, source=TwitterPediaSource) as pilmoji:
pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font)

image.show()
86 changes: 86 additions & 0 deletions addons/netflix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import asyncio

import aiohttp
from aiohttp import ClientConnectorError
from loguru import logger
from pyrogram.types import InlineKeyboardButton

# collector section
netflix_url1 = "https://www.netflix.com/title/70143836" # 非自制
netflix_url2 = "https://www.netflix.com/title/70242311" # 自制


async def fetch_netflix_new(Collector, session: aiohttp.ClientSession, flag=1, proxy=None, reconnection=2):
"""
新版Netflix检测
:param flag:
:param Collector: 采集器
:param session:
:param proxy:
:param reconnection: 重连次数
:return:
"""
try:
if flag == 1:
async with session.get(netflix_url1, proxy=proxy, timeout=5) as res:
print("n1状态: ", res.status)
if res.status == 200: # 解锁非自制
text = await res.text()
try:
locate = text.find("preferredLocale") # 定位到关键标签
if locate > 0:
region = text[locate + 29:locate + 31]
Collector.info['netflix_new'] = f"解锁({region})"
else:
region = "未知"
Collector.info['netflix_new'] = f"解锁({region})"
except Exception as e:
logger.error(e)
Collector.info['netflix_new'] = "N/A"
else:
await fetch_netflix_new(Collector, session, flag=flag + 1, proxy=proxy, reconnection=reconnection)
elif flag == 2:
async with session.get(netflix_url2, proxy=proxy, timeout=5) as res:
print("n2状态: ", res.status)
if res.status == 200: # 解锁自制
Collector.info['netflix_new'] = "自制"
else:
Collector.info['netflix_new'] = "失败"
else:
return
except ClientConnectorError as c:
logger.warning("Netflix请求发生错误:" + str(c))
if reconnection != 0:
await fetch_netflix_new(Collector, session, flag=flag, proxy=proxy, reconnection=reconnection-1)
except asyncio.exceptions.TimeoutError:
logger.warning("Netflix请求超时,正在重新发送请求......")
if reconnection != 0:
await fetch_netflix_new(Collector, session, flag=flag, proxy=proxy, reconnection=reconnection-1)


def task(Collector, session, proxy):
return asyncio.create_task(fetch_netflix_new(Collector, session, proxy=proxy))


# cleaner section
def get_netflix_info_new(ReCleaner):
"""
获得hbo解锁信息
:param ReCleaner:
:return: str: 解锁信息: [解锁(地区代码)、失败、N/A]
"""
try:
if 'netflix_new' not in ReCleaner.data:
logger.warning("采集器内无数据")
return "N/A"
else:
logger.info("netflix (新)解锁:" + str(ReCleaner.data.get('netflix_new', "N/A")))
return ReCleaner.data.get('netflix_new', "N/A")
except Exception as e:
logger.error(e)
return "N/A"


# bot_setting_board

button = InlineKeyboardButton("✅Netflix(新)", callback_data='✅Netflix(新)')
Loading