예제 #1
0
    async def send_msg(self):
        bot = get_bot()

        for rss in self.rsss:
            update_msg = [
                "{}\n{}".format(item['title'], item['link'])
                for item in rss.get_update()
            ]

            if len(update_msg) > 0:
                for suber in rss.subscribers:
                    info = "\n\n".join(update_msg)

                    if suber.type == 'group':
                        msg = "群订阅的《{}》更新了~\n\n".format(rss.title) + info
                        xlogger.debug("send group: {} rss msg".format(
                            suber.id))
                        await bot.send_group_msg(group_id=suber.id,
                                                 message=msg)

                    elif suber.type == 'private':
                        msg = "你的订阅的《{}》更新了~\n\n".format(rss.title) + info
                        xlogger.debug("send private: {} rss msg".format(
                            suber.id))
                        await bot.send_private_msg(user_id=suber.id,
                                                   message=msg)

                    elif suber.type == 'discuss':
                        msg = "讨论组订阅的《{}》更新了~\n\n".format(rss.title) + info
                        xlogger.debug("send discuss: {} rss msg".format(
                            suber.id))
                        await bot.send_discuss_msg(discuss_id=suber.id,
                                                   message=msg)

        self.save_rss()
예제 #2
0
async def _():
    mesg = await ceic.getceicinfo()
    if mesg:
        bot = get_bot()
        group_list = await bot.get_group_list()
        try:
            for group in group_list:
                xlogger.info("send group {} mesg……".format(
                    group['group_name']))
                await bot.send_group_msg(group_id=group['group_id'],
                                         message=mesg)
        except CQHttpError as e:
            xlogger.error(e)
예제 #3
0
from ...xlog import xlogger
from xunbot import get_bot

__plugin_name__ = '搜番'
__plugin_usage__ = r"""
搜索动漫资源

搜番  [番剧名称或者关键词]
anime  [番剧名称或者关键词]

eg.
搜番 Aria
""".strip()


@on_command('anime', aliases=('anime', '搜番'), permission=get_bot().level)
async def anime(session: CommandSession):
    key_word = session.get('key_word', prompt='需要的番剧名称是什么?')
    anime_report = await from_anime_get_info(key_word)
    if anime_report:
        await session.send(anime_report)
    else:
        xlogger.warning("Not found animeInfo")
        await session.send("[ERROR]Not found animeInfo")


@anime.args_parser
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()

    if session.is_first_run:
예제 #4
0
import requests
from urllib import parse
from html import unescape
from lxml import etree
from lxml.etree import Element

from xunbot import get_bot
from ...xlog import xlogger

MAXINFO_BT = get_bot().config.MAXINFO_BT

header = {
    "Host": "www.btmet.xyz",
    "Connection": "keep-alive",
    "Accept":
    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "User-Agent":
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
    "Accept-Language": "zh-CN,zh;"
}

cookiesDit = {'r18': '0'}


async def get_bt_info(url: str) -> str:
    xlogger.info("Now starting get the {}".format(url))
    html_data = requests.get(url, headers=header, cookies=cookiesDit)
    html = etree.HTML(html_data.text)

    num = html.xpath('//div[@id="wall"]//span/b/text()')[0]
    if num == '0':
예제 #5
0
import http.client
import hashlib
import urllib
import random
import json

from googletrans import Translator
from kth_timeoutdecorator import *

from xunbot import get_bot
from ...xlog import xlogger

TIMELIMIT_TRANSL = get_bot().config.TIMELIMIT_TRANSL
BAIDUAPPID_TRANSL = get_bot().config.BAIDUAPPID_TRANSL
BAIDUKEY_TRANSL = get_bot().config.BAIDUKEY_TRANSL
TO_TRANSL = get_bot().config.TO_TRANSL


def baidu_translator(content: str, appid: str, secretKey: str,
                     fromLang: "str = 'auto'", toLang: "str = 'zh'") -> str:
    httpClient = None
    myurl = '/api/trans/vip/translate'
    salt = random.randint(32768, 65536)
    q = content
    sign = appid + q + str(salt) + secretKey
    sign = hashlib.md5(sign.encode()).hexdigest()
    myurl = myurl + '?appid=' + appid + '&q=' + urllib.parse.quote(
        q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str(
            salt) + '&sign=' + sign

    try:
예제 #6
0

__plugin_name__ = '彩虹六号战绩查询'
__plugin_usage__ = r"""
彩虹六号战绩查询

彩虹六号战绩 [游戏名称]
r6s [游戏名称]
r6战绩 [游戏名称]

eg.
r6s Original_04
""".strip()


@on_command('r6s', aliases=('彩虹六号战绩', 'r6s', 'r6战绩'), permission=get_bot().level)
async def translation(session: CommandSession):
    content = session.get('content', prompt='需要给出你想查询的游戏名称')
    r6s_report = await get_r6smessage_of_username(content)
    if r6s_report:
        await session.send(r6s_report)
    else:
        xlogger.error("Not found userName")
        await session.send("[ERROR]Not found userName")


@translation.args_parser
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()

    if session.is_first_run:
예제 #7
0
from .data_source import get_weather_of_city
from ...xlog import xlogger
from xunbot import get_bot

__plugin_name__ = '天气查询'
__plugin_usage__ = r"""
天气 [地区]
查天气 [地区]
[NLP模块] XXXX天气XXXX地区XXXX
ps: 目前只支持国内地区查询
""".strip()


@on_command('weather',
            aliases=('天气', '查天气', '天氣', '查天氣'),
            permission=get_bot().level)
async def weather(session: CommandSession):
    city = session.get('city', prompt='你想查询哪个城市的天气呢?')
    weather_report = await get_weather_of_city(city)
    if weather_report:
        await session.send(weather_report)
    else:
        xlogger.error("Not found weatherInfo")
        await session.send("[ERROR]Not found weatherInfo")


@weather.args_parser
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()

    if session.is_first_run:
예제 #8
0
import requests
from lxml import etree
import time
import feedparser
from urllib import parse

from kth_timeoutdecorator import *
from xunbot import get_bot

from ...xlog import xlogger

TIMELIMIT_ANIME = get_bot().config.TIMELIMIT_ANIME
MAXINFO_ANIME = get_bot().config.MAXINFO_ANIME


async def from_anime_get_info(key_word: str) -> str:
    repass = ""
    url = 'https://share.dmhy.org/topics/rss/rss.xml?keyword=' + parse.quote(
        key_word)
    try:
        xlogger.debug("Now starting get the {}".format(url))
        repass = await get_repass(url)
    except TimeoutException as e:
        xlogger.error("Timeout! {}".format(e))

    return repass


@timeout(TIMELIMIT_ANIME)
async def get_repass(url: str) -> str:
    repass = ""
예제 #9
0
from aiocqhttp.exceptions import Error as CQHttpError
from nonebot import scheduler

from ...xlog import xlogger
from .data_source import Ceicinfo
from xunbot import get_bot

EM = get_bot().config.EM
CEICONLYCN = get_bot().config.CEICONLYCN

__plugin_name__ = '地震通报'
__plugin_usage__ = r"""
【群技能】【被动技能】地震通报(误差±10min)
""".strip()

xlogger.info("Loading CeicInfo……")
ceic = Ceicinfo(EM, CEICONLYCN)


@scheduler.scheduled_job('cron', minute='*')
async def _():
    mesg = await ceic.getceicinfo()
    if mesg:
        bot = get_bot()
        group_list = await bot.get_group_list()
        try:
            for group in group_list:
                xlogger.info("send group {} mesg……".format(
                    group['group_name']))
                await bot.send_group_msg(group_id=group['group_id'],
                                         message=mesg)
예제 #10
0
import json
import requests
from os import path
from random import choice

import thulac

from xunbot import get_bot
from ...hanziconv import HanziConv
from ...xlog import xlogger

RECOMMENDER_MUSIC = get_bot().config.RECOMMENDER_MUSIC
PLAYLIST_MUSIC = get_bot().config.PLAYLIST_MUSIC


async def get_recommend(music_command: str):
    music_command = HanziConv.toSimplified(music_command)
    xlogger.debug("Start fetching keywords……")
    keywords = []
    user_words_path = path.join(path.dirname(__file__), "user_words.txt")
    user_words = []
    with open(user_words_path, 'r', encoding='UTF-8') as f:
        for line in f:
            usr = str(line.strip('\n'))
            if usr.lower() in music_command.lower():
                keywords.append(usr.lower())
            user_words.append(usr)

    thu1 = thulac.thulac()
    words = thu1.cut(music_command)
예제 #11
0
import time
from typing import Dict, List
from os import path, getcwd

import feedparser
import pandas as pd
from nonebot import scheduler

from ...xlog import xlogger
from xunbot import get_bot

RSSHUBAPP = get_bot().config.RSSHUBAPP


class Subscriber():
    def __init__(self, type: str, id: int, jointime: float = None):
        self.type = type
        self.id = id
        self.jointime = jointime or time.time()

    def __str__(self):
        return str({name: value for name, value in vars(self).items()})

    def __eq__(self, obj):
        return (self.type == obj.type and self.id == obj.id)


class RSS():
    def __init__(self,
                 rss_route: str,
                 title: str = None,
예제 #12
0
from ...xlog import xlogger
from xunbot import get_bot

__plugin_name__ = '日语词典'
__plugin_usage__ = r"""
日语词典

日典 [日语单词]
jd [日语单词]

eg.
jd 草
""".strip()


@on_command('jpd', aliases=('日典', 'jd'), permission=get_bot().level)
async def jpd(session: CommandSession):
    word = session.get('word', prompt='你想查询哪个单词呢?')
    jpd_report = ""
    try:
        jpd_report = await get_definition_of_word(word)
    except TimeoutException as e:
        xlogger.error("Timeout! {}".format(e))
        jpd_report = "[ERROR]Timeout!"

    if jpd_report:
        await session.send(jpd_report)
    else:
        xlogger.error("Not found jpdInfo")
        await session.send("[ERROR]Not found jpdInfo")
예제 #13
0
from lxml import etree
import requests
import re

from kth_timeoutdecorator import *

from ...xlog import xlogger
from xunbot import get_bot

TIMELIMIT_JD = get_bot().config.TIMELIMIT_JD
MAXLINE_JD = get_bot().config.MAXLINE_JD
MAXWOED_JD = get_bot().config.MAXWOED_JD


@timeout(TIMELIMIT_JD)
async def get_definition_of_word(word: str) -> str:
    is_hidden = False
    url = 'https://www.weblio.jp/content/' + word
    xlogger.debug("[info] Now get definition from: {}".format(url))
    html_data = requests.get(url)
    html = etree.HTML(html_data.text)

    notfound = html.xpath('//div[@id="nrCntTH"]/p/text()')
    if notfound:
        return notfound[0]

    source = html.xpath('//div[@class="pbarTL"]')
    definition = []
    d_html = html.xpath('//div[@class="kiji"]')
    for d in d_html:
        definition.append(
예제 #14
0
__plugin_usage__ = r"""
不定期神隐的功能
*请各位使用后不要转发*
默认检索排序为相关度,如果需要按更新时间排序,加上参数: -U

-按相关度检索(默认)
bt [关键词]
磁力 [关键词]

-按更新时间检索(参数不区分大小写,但要注意空格)
bt -U [关键词]
磁力 -U [关键词]
""".strip()


@on_command('bt', aliases=('bt', '磁力'), permission=get_bot().level)
async def bt(session: CommandSession):
    url = session.get('url', prompt='关键字给我')
    bt_report = await get_bt_info(url)
    if bt_report:
        await session.send(bt_report)
    else:
        xlogger.error("Not found btInfo")
        await session.send("[ERROR]Not found btInfo")


@bt.args_parser
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()
    url = get_url(stripped_arg)
예제 #15
0
import json
import requests
from lxml import etree

from kth_timeoutdecorator import *

from xunbot import get_bot
from ...xlog import xlogger

TIMELIMIT_IMAGE = get_bot().config.TIMELIMIT_IMAGE


class SauceNAO():
    def __init__(self,
                 api_key,
                 output_type=2,
                 testmode=0,
                 dbmask=None,
                 dbmaski=None,
                 db=999,
                 numres=3,
                 shortlimit=20,
                 longlimit=300):
        params = dict()
        params['api_key'] = api_key
        params['output_type'] = output_type
        params['testmode'] = testmode
        params['dbmask'] = dbmask
        params['dbmaski'] = dbmaski
        params['db'] = db
        params['numres'] = numres
예제 #16
0
import time

from nonebot import on_command, CommandSession, permission

from ...xlog import xlogger
from xunbot import get_bot

Bot = get_bot()

PUSH_GROUP_DICT = Bot.config.PUSH_GROUP_DICT

__plugin_name__ = '群通知'
__plugin_usage__ = r"""
【管理员功能】
用于管理员通知群的功能

通知 【信息】
push 【信息】
""".strip()


@on_command('notice', aliases=('push', '通知'), permission=0xF000)
async def notice(session: CommandSession):
    info = session.get('info', prompt='请给出需要通知的信息')

    if PUSH_GROUP_DICT:
        header = "🔈群通知🔈\n\n"
        sender_info = "\n\n——{}(管理员) 发布于 {}".format(
            session.event['sender']['nickname'],
            time.strftime("%Y-%m-%d", time.localtime(session.event['time'])))
예제 #17
0
import requests
from lxml import etree
import time

from kth_timeoutdecorator import *

from xunbot import get_bot
from ...xlog import xlogger

TIMELIMIT_REIMU = get_bot().config.TIMELIMIT_REIMU
MAXINFO_REIMU = get_bot().config.MAXINFO_REIMU


async def from_reimu_get_info(key_word: str) -> str:
    if "miku" in key_word.lower():
        xlogger.warning("Taboo words are being triggered")
        return None
    repass = ""
    url = 'https://blog.reimu.net/search/' + key_word
    url_s = 'https://blog.reimu.net/'
    try:
        if key_word == "最近的存档":
            xlogger.debug("Now starting get the {}".format(url_s))
            repass = await get_repass(url_s)
        else:
            xlogger.debug("Now starting get the {}".format(url))
            repass = await get_repass(url)
    except TimeoutException as e:
        xlogger.error("Timeout! {}".format(e))

    return repass
예제 #18
0
from xunbot import get_bot


__plugin_name__ = '使用帮助'
__plugin_usage__ = r"""
help [功能名称]
帮助 [功能名称]
使用帮助 [功能名称]
使用方法 [功能名称]
ps.无参数时,返回功能列表
eg.
help [无参数] #返回功能列表
help 使用帮助
""".strip()


@on_command('help', aliases=('help', '使用帮助', '帮助', '使用方法'), permission=get_bot().level)
async def help(session: CommandSession):
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('我现在支持的功能有:\n\n' + '\n'.join(p.name for p in plugins))
        return
    
    check = set(filter(lambda p: p.name.lower() == arg, plugins))
    if check:
        for p in check:
            await session.send(p.usage)
    else: await session.send("功能不存在:)")
예제 #19
0
import io
import tokenize
from copy import deepcopy

from xunbot import get_bot
from ...xlog import xlogger

MORE_COMPLEX = get_bot().config.MORE_COMPLEX
CALCULATE_LIST = get_bot().config.CALCULATE_LIST


def check_unsafe_attributes(string) -> (dict, dict):
    """This code is modified from:
    https://mozillazg.com/2016/05/python-some-security-problems-about-use-exec-function.rst.html
    """
    g = {}
    l = {}
    model_del_list = [
        '__import__', 'open', 'quit', 'exit', 'requests', 'help', 'license',
        'exec', 'eval', 'copyright', 'credits'
    ]

    exec('print("[info] calculate test code……")', g, l)
    if MORE_COMPLEX:
        for fn in CALCULATE_LIST.keys():
            sn = CALCULATE_LIST[fn]
            if sn:
                exec("import {} as {}".format(fn, sn), g, l)
            else:
                exec("import {}".format(fn), g, l)
    g_c = deepcopy(g)
예제 #20
0
__plugin_name__ = '使用帮助'
__plugin_usage__ = r"""
help [功能名称]
帮助 [功能名称]
使用帮助 [功能名称]
使用方法 [功能名称]
ps.无参数时,返回功能列表
eg.
help [无参数] #返回功能列表
help [功能名称]
""".strip()


@on_command('help',
            aliases=('help', '使用帮助', '帮助', '使用方法'),
            permission=get_bot().level)
async def help(session: CommandSession):
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('我现在支持的功能有:\n\n' + '\n'.join(p.name
                                                        for p in plugins))
        return

    check = set(filter(lambda p: p.name.lower() == arg, plugins))
    if check:
        for p in check:
            await session.send(p.usage)
    else:
        await session.send("功能不存在:)")
예제 #21
0
from ...xlog import xlogger
from xunbot import get_bot

__plugin_name__ = '上车'
__plugin_usage__ = r"""
不定期神隐的功能
*请各位使用后不要转发*

上车 [目的地]
reimu [目的地]

ps: 请尽量提供具体的目的地名称
""".strip()


@on_command('reimu', aliases=('reimu', '上车', '上車'), permission=get_bot().level)
async def reimu(session: CommandSession):
    key_word = session.get('key_word', prompt='你想到哪儿下车?')
    reimu_report = await from_reimu_get_info(key_word)
    if reimu_report:
        await session.send(reimu_report)
    else:
        xlogger.error("Not found reimuInfo")
        await session.send("[ERROR]Not found reimuInfo")


@reimu.args_parser
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()

    if session.is_first_run:
예제 #22
0
from datetime import timedelta

from nonebot import on_command, scheduler, permission, CommandSession
# from apscheduler.triggers.interval import IntervalTrigger

from ...xlog import xlogger
from .data_source import RSS_reader, RSS
from xunbot import get_bot

MAX_RSS_P = get_bot().config.MAX_RSS_P
MAX_RSS_G = get_bot().config.MAX_RSS_G
MAX_RSS_D = get_bot().config.MAX_RSS_D
RSSINTERVAL = get_bot().config.RSSINTERVAL
xlogger.debug("time interval: {}".format(RSSINTERVAL))


__plugin_name__ = 'RSSHub订阅'
__plugin_usage__ = r"""
配合RSSHub实现RSS订阅
-当前订阅检索的时间间隔为: {}

rss [RSSHub 路由]
订阅 [RSSHub 路由]

unrss [RSSHub 路由]
取消订阅 [RSSHub 路由]

无参数时返回当前的订阅表:
rss #返回订阅表

-[RSSHub 路由]请参考:https://docs.rsshub.app/social-media.html
예제 #23
0

__plugin_name__ = '音乐推荐'
__plugin_usage__ = r"""
推荐首 [描述]
推荐一首 [描述]
推荐音乐 [描述]
音乐推荐 [描述]
[NLP模块] XXXX推进首XXXX

eg: 给屑SK推荐一首适合一个人孤零零回家路上平地摔后倍感伤心回家后没人关心只能孤独的打开QQ的歌
eg: 推荐首打麻将的时候可以摸到天和字一色大四喜四暗刻单骑六倍役满的歌
""".strip()


@on_command('music_recommend', aliases=('推荐音乐', '音乐推荐', '推荐首', '推荐一首', '推薦音樂', '音樂推薦', '推薦首', '推薦一首'), permission=get_bot().level)
async def music_recommend(session: CommandSession):
    music_command = session.get('command', prompt='你想听什么样的音乐呢?')
    keywords = await get_recommend(music_command)
    music_report, infot = await get_song_of_music(keywords)
    if music_report:
        await session.send(music_report)
        for info in infot:
            await session.send(info)
    else:
        xlogger.error("Not found musicInfo")
        await session.send("[ERROR]Not found musicInfo")

@music_recommend.args_parser
async def _(session: CommandSession):
    arg = session.current_arg