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

♻️ 翻新 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
64 changes: 38 additions & 26 deletions nonebot_plugin_soup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
'''
"""
Name: ChickenSoup
Author: Monarchdos
Date: 2023-01-11 16:04:41
LastEditTime: 2024-07-15 15:51:41
'''
from nonebot import on_command, logger, get_plugin_config
from nonebot.plugin import PluginMetadata
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, Message, MessageSegment, GroupMessageEvent
"""

from httpx import AsyncClient, HTTPError
from nonebot import get_plugin_config, logger, on_command, require
from nonebot.plugin import PluginMetadata, inherit_supported_adapters

from .config import Config
import requests

require("nonebot_plugin_alconna")

from nonebot_plugin_alconna.uniseg import UniMessage # noqa: E402

__plugin_meta__ = PluginMetadata(
name = "心灵鸡汤",
description = "来一碗心灵鸡汤吧",
usage = "鸡汤,毒鸡汤",
name="心灵鸡汤",
description="来一碗心灵鸡汤吧",
usage="鸡汤,毒鸡汤",
type="application",
homepage="https://github.com/Monarchdos/nonebot_plugin_soup",
supported_adapters={"~onebot.v11"},
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_plugin_alconna"),
)

plugin_config = get_plugin_config(Config)

jt = on_command('鸡汤', priority=1, block=True)
jt = on_command("鸡汤", priority=1, block=True)


@jt.handle()
async def jt_(bot: Bot, event: GroupMessageEvent):
try:
core = "68747470733a2f2f6170692e61796672652e636f6d2f6a743f747970653d626f74267665723d312e312e30"
res = ("\n" if plugin_config.chickensoup_reply_at else "") + str(requests.get(bytes.fromhex(core).decode()).text)
if "wwwroot" in res or "html" in res or len(res) == 1: return
await jt.send(message=Message(res), at_sender=plugin_config.chickensoup_reply_at)
except requests.RequestException as e:
logger.warning("Server connection failed.")
async def _():
await handle("https://api.ayfre.com/jt?type=bot&ver=1.1.0")


djt = on_command("毒鸡汤", priority=1, block=True)


djt = on_command('毒鸡汤', priority=1, block=True)
@djt.handle()
async def djt_(bot: Bot, event: GroupMessageEvent):
async def _():
await handle("https://api.ayfre.com/djt?type=bot&ver=1.1.0")


async def handle(url: str):
try:
core = "68747470733a2f2f6170692e61796672652e636f6d2f646a743f747970653d626f74267665723d312e312e30"
res = ("\n" if plugin_config.chickensoup_reply_at else "") + str(requests.get(bytes.fromhex(core).decode()).text)
if "wwwroot" in res or "html" in res or len(res) == 1: return
await djt.send(message=Message(res), at_sender=plugin_config.chickensoup_reply_at)
except requests.RequestException as e:
async with AsyncClient() as client:
res = ("\n" if plugin_config.chickensoup_reply_at else "") + (
await client.get(url, follow_redirects=True)
).text
if "wwwroot" in res or "html" in res or len(res) == 1:
return
await UniMessage(res).finish(at_sender=plugin_config.chickensoup_reply_at)
except HTTPError:
logger.warning("Server connection failed.")
14 changes: 5 additions & 9 deletions nonebot_plugin_soup/config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'''
"""
Name: ChickenSoup.Config
Author: Monarchdos
Date: 2024-07-15 15:14:38
LastEditTime: 2024-07-15 15:15:56
'''
from pydantic import BaseModel, validator
"""

from pydantic import BaseModel


class Config(BaseModel):
chickensoup_reply_at: bool = True

@validator('chickensoup_reply_at', pre=True, always=True)
def check_boolean(cls, v):
if not isinstance(v, bool):
raise ValueError('chickensoup_reply_at must be a boolean value')
return v
Loading