예제 #1
0
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from botoy import AsyncAction, S
from botoy.async_decorators import on_regexp
from botoy.contrib import get_cache_dir
from botoy.model import GroupMsg

from .generate import *

scheduler = AsyncIOScheduler()

group_data = {}

action: Optional[AsyncAction] = None

data_path = get_cache_dir("genshin_calendar") / "data.json"


def load_data():
    if not data_path.is_file():
        return
    try:
        with open(data_path, encoding="utf8") as f:
            data = json.load(f)
            for k, v in data.items():
                group_data[k] = v
    except:
        traceback.print_exc()


def save_data():
예제 #2
0
"""撕开头像
1. AT一人发送撕
2. 发送图片加撕
"""
from io import BytesIO
from typing import Union

import httpx
from botoy import GroupMsg, S
from botoy.collection import MsgTypes
from botoy.contrib import download, get_cache_dir
from botoy.decorators import ignore_botself
from botoy.parser import group as gp
from PIL import Image

TEMPLATE_PATH = get_cache_dir("rip_avatar") / "rip.png"
if not TEMPLATE_PATH.exists():
    download(
        "https://github.com/opq-osc/botoy-plugins/releases/download/rip.png/rip.png",
        TEMPLATE_PATH,
    )
TEMPLATE_PATH = str(TEMPLATE_PATH)


def get_avator(image: Union[int, str]):
    if isinstance(image, int):
        image = f"http://q1.qlogo.cn/g?b=qq&nk={image}&s=640"

    content = httpx.get(image, timeout=20).content
    return Image.open(BytesIO(content)).convert("RGBA")
예제 #3
0
"""吃啥?我帮你选! 格式:今天吃啥?早上吃啥?晚餐吃什么?..."""
import os
import random
import re

from botoy import GroupMsg
from botoy.collection import MsgTypes
from botoy.contrib import get_cache_dir
from botoy.decorators import ignore_botself, on_regexp, these_msgtypes
from botoy.sugar import Picture

recipe_dir = get_cache_dir("what do you want to eat")


@ignore_botself
@these_msgtypes(MsgTypes.TextMsg)
@on_regexp(r"(今天|[早中午晚][上饭餐]|夜宵)吃(什么|啥|点啥)")
def receive_group_msg(ctx: GroupMsg):
    time = ctx._match.group(1).strip()
    recipes = os.listdir(recipe_dir)
    if recipes:
        choose = recipe_dir / random.choice(recipes)
        Picture(
            pic_path=choose,
            text=f"建议你{time}吃: {choose.name[:-4]}",
        )


if __name__ == "__main__":
    import asyncio
예제 #4
0
import pathlib
import shutil
from io import BytesIO
from typing import Union

import httpx
from botoy.contrib import get_cache_dir
from PIL import Image, ImageDraw

HERE = pathlib.Path(__file__).parent.absolute()
FRAMES_DIR = get_cache_dir("kiss_gif") / "frames"
if not FRAMES_DIR.exists() or not FRAMES_DIR.is_dir():
    ARCHIVE = HERE / "frames.zip"
    shutil.unpack_archive(ARCHIVE, FRAMES_DIR)


def get_avator(image: Union[int, str]):
    if isinstance(image, int):
        image = f"http://q1.qlogo.cn/g?b=qq&nk={image}&s=640"

    content = httpx.get(image, timeout=20).content
    return Image.open(BytesIO(content)).convert("RGBA")


OPERATOR_X = [92, 135, 84, 80, 155, 60, 50, 98, 35, 38, 70, 84, 75]
OPERATOR_Y = [64, 40, 105, 110, 82, 96, 80, 55, 65, 100, 80, 65, 65]
TARGET_X = [58, 62, 42, 50, 56, 18, 28, 54, 46, 60, 35, 20, 40]
TARGET_Y = [90, 95, 100, 100, 100, 120, 110, 100, 100, 100, 115, 120, 96]


def kiss(operator, target) -> BytesIO:
예제 #5
0
"""生成花体字符

格式:花体+{可选字符串(字母或数字)}
"""
import json

from botoy.collection import MsgTypes
from botoy.contrib import get_cache_dir
from botoy.decorators import ignore_botself, startswith, these_msgtypes
from botoy.session import SessionHandler, ctx, session

from .internal import convert, font_names, get_font, get_font_styles

weirdfonts_cache = get_cache_dir("weirdfonts") / "cache.json"
if not weirdfonts_cache.is_file():
    with open(weirdfonts_cache, "w") as f:
        json.dump({}, f)

weirdfonts = SessionHandler(
    ignore_botself,
    these_msgtypes(MsgTypes.TextMsg),
    startswith("花体"),
).receive_group_msg()


# 因为这个插件发了蛮多废话,所以都自动撤回一下。需要配合autoRevoke插件
def revoke(msg) -> str:
    return f"{msg}\n\nrevoke[30]"


@weirdfonts.handle
예제 #6
0
from botoy.contrib import download, get_cache_dir
from PIL import Image, ImageDraw, ImageFont

from .event import *

font_path = get_cache_dir("genshin_calendar") / "wqy-microhei.ttc"
if not font_path.is_file():
    download(
        "https://cdn.staticaly.com/gh/NepPure/genshin_calendar/master/wqy-microhei.ttc",
        font_path,
    )
font = ImageFont.truetype(str(font_path), 20)

width = 500

color = [
    {
        "front": "black",
        "back": "white"
    },
    {
        "front": "white",
        "back": "ForestGreen"
    },
    {
        "front": "white",
        "back": "DarkOrange"
    },
    {
        "front": "white",
        "back": "BlueViolet"
예제 #7
0
import json
import sqlite3
import time
from collections import defaultdict

from botoy import Action, EventMsg, GroupMsg
from botoy.collection import MsgTypes
from botoy.contrib import get_cache_dir
from botoy.decorators import ignore_botself, these_msgtypes
from botoy.parser import event as ep

db_cache_dir = get_cache_dir("for_stop_revoke_plugin")


class DB:
    def init(self, db_name: str):
        self.db_name = db_name

        self.con = sqlite3.connect(db_cache_dir / self.db_name)
        self.cs = self.con.cursor()

        self.create()
        self.clear()

    def create(self):
        try:
            self.cs.execute("""
            create table message(
            id integer primary key autoincrement,
            msg_type varchar(20),
            msg_random integer,
예제 #8
0
from botoy.schedule import scheduler
from pydantic import BaseModel

__name__ = "疫情订阅"
__doc__ = "疫情最新资讯订阅:发送 疫情订阅 或 疫情退订"


class New(BaseModel):
    pubDate: int = 0
    pubDateStr: str = ""
    title: str = ""
    summary: str = ""
    sourceUrl: str = ""


cache = get_cache_dir("corona_virus") / "data.json"


class CacheData:
    def __init__(self):
        try:
            with open(cache, "r") as f:
                data = json.load(f)
        except FileNotFoundError:
            data = {"groups": [], "new": New().dict()}

        self._groups: List[int] = data["groups"]
        self._new: New = New(**data["new"])

    def save(self):
        with open(cache, "w") as f:
예제 #9
0
"""绝绝子生成器
1. 绝绝子更新:  更新词库
2. 绝绝子+{内容}: 内容请使用空格间隔动词与名词,例如:喝奶茶 => 喝 奶茶
"""
import random
from typing import List

from botoy import GroupMsg, S
from botoy import decorators as deco
from botoy.contrib import download, get_cache_dir
from pydantic import BaseModel

data_path = get_cache_dir("juejuezi") / "juejuezi.json"


def download_material():
    download(
        "https://cdn.jsdelivr.net/gh/kingcos/JueJueZiGenerator@main/materials.json",
        data_path,
    )


if not data_path.exists():
    download_material()


class Emotion(BaseModel):
    emoji: List[str]
    xiaohongshu: List[str]
    weibo: List[str]
예제 #10
0

def get_config(key, default=None):
    return jconfig.get_jconfig(f"custom_image_{key}") or default


FONT_MIN = 15

IMAGES_PATH = Path(__file__).parent.absolute() / "images"

# 屏蔽群
BLOCK_GROUP = get_config("block_group", [])
# 是否开启emoji
ENABLE_EMOJI = get_config("enable_emoji", True)

CACHE_PATH = get_cache_dir("custom_image")

if not (CACHE_PATH / "user").exists():
    (CACHE_PATH / "user").mkdir()
if ENABLE_EMOJI:
    font_name = "simhei-emoji.ttf"
else:
    font_name = "simhei.ttf"

FONT_PATH = CACHE_PATH / font_name

if not FONT_PATH.exists():
    download(
        f"https://github.com/opq-osc/botoy-plugins/releases/download/simhei-fonts/{font_name}",
        FONT_PATH,
    )
예제 #11
0
파일: db.py 프로젝트: opq-osc/botoy-plugins
import sqlite3
from typing import List

from botoy.contrib import get_cache_dir

DB_PATH = get_cache_dir("bili_subscriber") / "db.sqlite3"


class DB:
    def __init__(self):
        self.con = sqlite3.connect(DB_PATH)
        self.cur = self.con.cursor()
        # up's video
        # up_video_data: mid, create
        self.cur.execute(
            "CREATE TABLE IF NOT EXISTS up_video_data(mid interger primary key, created integer);"
        )
        # up_subscribed: id, gid, mid
        self.cur.execute(
            "CREATE TABLE IF NOT EXISTS up_subscribed(id integer primary key autoincrement, gid integer, mid interger);"
        )
        # bangumi
        # bangumi_data: mid, ep_id
        self.cur.execute(
            "CREATE TABLE IF NOT EXISTS bangumi_data(mid interger primary key, ep_id integer);"
        )
        # bangumi_subscribed: id, gid, mid
        self.cur.execute(
            "CREATE TABLE IF NOT EXISTS bangumi_subscribed(id integer primary key autoincrement, gid integer, mid interger);"
        )
        self.con.commit()
예제 #12
0
from botoy.decorators import ignore_botself, queued_up
from botoy.sugar import Picture
from PIL import Image, ImageDraw, ImageFont

LEFT_PART_VERTICAL_BLANK_MULTIPLY_FONT_HEIGHT = 2
LEFT_PART_HORIZONTAL_BLANK_MULTIPLY_FONT_WIDTH = 1 / 4
RIGHT_PART_VERTICAL_BLANK_MULTIPLY_FONT_HEIGHT = 1
RIGHT_PART_HORIZONTAL_BLANK_MULTIPLY_FONT_WIDTH = 1 / 4
RIGHT_PART_RADII = 10
BG_COLOR = "#000000"
BOX_COLOR = "#F7971D"
LEFT_TEXT_COLOR = "#FFFFFF"
RIGHT_TEXT_COLOR = "#000000"
FONT_SIZE = 50

FONT_PATH = get_cache_dir("phlogo") / "ArialEnUnicodeBold.ttf"
if not FONT_PATH.exists():
    print("phlogo插件: 下载字体中....")
    import os

    import httpx

    try:
        with httpx.stream(
            "GET",
            "https://github.com/opq-osc/botoy-plugins/releases/download/phlogo%E6%89%80%E9%9C%80%E5%AD%97%E4%BD%93/ArialEnUnicodeBold.ttf",
        ) as resp:
            print("连接字体资源成功")
            total_size = int(resp.headers["content-length"])
            downloaded_size = 0
            with open(FONT_PATH, "wb") as f:
예제 #13
0
class TemporaryFile:
    def __init__(self, suffix=None) -> None:
        self.path = Path(tempfile.mkstemp(suffix=suffix)[1])

    def __enter__(self) -> Path:
        return self.path

    def __exit__(self, *_):
        try:
            os.remove(self.path)
        except FileNotFoundError:
            pass


mp4 = get_cache_dir("bot_sese") / "kick.mp4"
if not mp4.is_file():
    download(
        "https://cdn.jsdelivr.net/gh/opq-osc/OPQ-PHP-plugins@main/public/templates/sese/template-small.mp4",
        mp4,
    )


@deco.ignore_botself
@deco.on_regexp(r"sese(\w+)")
def receive_group_msg(ctx: GroupMsg):
    text: str = ctx._match.group(1).strip()
    with TemporaryFile(".ass") as template:
        template.write_text(TEMPLATE.format(text=text))
        with TemporaryFile(".gif") as gif:
            process = subprocess.run([
예제 #14
0
"""不能好好说话

发送 说个屁+{缩写}  如:说个屁ynmm
"""
import pickle

from botoy import GroupMsg, S
from botoy import decorators as deco
from botoy.contrib import download, get_cache_dir

data = get_cache_dir("bnhhsh") / "data.pkl"
if not data.is_file():
    download(
        "https://github.com/opq-osc/botoy-plugins/releases/download/bnhhsh%E6%95%B0%E6%8D%AE/data.pkl",
        data,
    )

with open(data, "rb") as f:
    词桶 = pickle.load(f)

n = max(词桶)


def dp(target):
    代价 = {-1: 0}
    记录 = {-1: []}
    for x in range(len(target)):
        代价[x] = 2**32
        for k in range(n, 0, -1):
            s = x - k + 1
            if s < 0: