def get_hour_call(): """从HOUR_CALLS中挑出一组时报,每日更换,一日之内保持相同""" config = util.load_config(__file__) now = datetime.now(pytz.timezone('Asia/Shanghai')) hc_groups = config["HOUR_CALLS"] g = hc_groups[ now.day % len(hc_groups) ] return config[g]
def _load_data(): config = util.load_config(__file__) db = config.get("data", {}) rex = re.compile(r"\[CQ:image,file=(.*)\]") for k, v in db.items(): m = rex.search(v) if m: img = str(R.img('kancolle/', m.group(1)).cqcode) db[k] = rex.sub(img, v) return db
def load_pool(self): config = util.load_config(__file__) pool = config["GACHA_POOL"] self.up_prob = pool["up_prob"] self.s3_prob = pool["s3_prob"] self.s2_prob = pool["s2_prob"] self.s1_prob = 1000 - self.s2_prob - self.s3_prob self.up = pool["up"] self.star3 = pool["star3"] self.star2 = pool["star2"] self.star1 = pool["star1"]
def load_pool(self, pool_name: str): config = util.load_config(__file__) pool = config[pool_name] self.up_prob = pool["up_prob"] self.s3_prob = pool["s3_prob"] self.s2_prob = pool["s2_prob"] self.s1_prob = 1000 - self.s2_prob - self.s3_prob self.up = pool["up"] self.star3 = pool["star3"] self.star2 = pool["star2"] self.star1 = pool["star1"]
def __init__(self, pool_name: str = "MIX"): super().__init__() config = util.load_config(__file__) pool = config[pool_name] self.up_prob = pool["up_prob"] self.s3_prob = pool["s3_prob"] self.s2_prob = pool["s2_prob"] self.s1_prob = 1000 - self.s2_prob - self.s3_prob self.up = pool["up"] self.star3 = pool["star3"] self.star2 = pool["star2"] self.star1 = pool["star1"]
async def group_approve(session: RequestSession): cfg = load_config(__file__) cfg = cfg.get('group_approve', {}) gid = str(session.event.group_id) if gid not in cfg: return key = cfg[gid].get('keywords', []) for k in key: if k in session.event.comment: await session.approve() return if cfg[gid].get('reject_when_not_match', False): await session.reject() return
async def today_fortune_query(bot, event): uid = event['user_id'] if not lmt.check(uid): await bot.send(event, '今天已经查过运势了哦,请明天再来吧~', at_sender=True) return lmt.increase(uid) config = util.load_config(__file__) gacha_hour = random.randint(0, 24) gacha_min = random.randint(0, 60) gacha_sec = random.randint(0, 60) gachatime = f'{gacha_hour}时{gacha_min}分{gacha_sec}秒' hournow = time.localtime().tm_hour timenow = time.strftime('%Y年%m月%d日%H时%M分%S秒', time.localtime(time.time())) characters = random.choice(config["characters"]) position = random.choice(config["position"]) actions = random.choice(config["actions"]) inputnum = int(event.match.group(1)) flag = random.randint(1, 100) diff = abs(inputnum - flag) if 0 < diff <= 16: fortune = '大吉' elif 16 < diff <= 33: fortune = '中吉' elif 33 < diff <= 50: fortune = '小吉' elif 50 < diff <= 67: fortune = '小凶' elif 67 < diff <= 84: fortune = '凶' elif 84 < diff <= 99: fortune = '大凶' all_things = ['gacha', 'arena', 'mainmap', 'story', 'clanbattle', 'hard'] things = random.sample(all_things, 2) suitable_thing = things[0] unsuitable_thing = things[1] suitable = config["suitable"][suitable_thing] unsuitable = config["unsuitable"][unsuitable_thing] msg = f'\n今日运势:{fortune}\n当前时间:{timenow}\n今日幸运角色:{characters}\n宜{suitable}\n忌{unsuitable}\n抽卡加成时间:{gachatime}\n抽卡加成方向:{position}\n抽卡加成动作:{actions}\n' await bot.send(event, msg, at_sender=True)
def load_pool(self, pool_name: str): config = util.load_config(__file__) pool = config[pool_name] self.s3_prob = pool["s3_prob"] self.s2_prob = pool["s2_prob"] self.s1_prob = 1000 - self.s2_prob - self.s3_prob self.star3 = pool["star3"] self.star2 = pool["star2"] self.star1 = pool["star1"] self.s3_up_prob = self.star3[ "up_prob"] if 'up_prob' in self.star3 else 0 self.s2_up_prob = self.star2[ "up_prob"] if 'up_prob' in self.star2 else 0 self.s1_up_prob = self.star1[ "up_prob"] if 'up_prob' in self.star1 else 0 s3Up = self.star3["up"] if 'up' in self.star3 else [] s2Up = self.star2["up"] if 'up' in self.star2 else [] s1Up = self.star1["up"] if 'up' in self.star1 else [] self.up = s3Up + s2Up + s1Up
def load_pool(self, pool_name: str): config = util.load_config(__file__) pool = config[pool_name] self.up_prob = pool["up_prob"] self.s3_prob = pool["s3_prob"] self.s2_prob = pool["s2_prob"] self.s1_prob = 1000 - self.s3_prob - self.s2_prob self.up = pool["up"] self.star3 = pool["star3"] self.star2 = pool["star2"] self.star1 = pool["star1"] self.up_star = pool["up_star"] self.up3_prob = 0 self.up2_prob = 0 self.up1_prob = 0 for i in range(len(self.up)): if self.up_star[i] == 3: self.up3_prob += self.up_prob[i] elif self.up_star[i] == 2: self.up2_prob += self.up_prob[i] else: self.up1_prob += self.up_prob[i]
async def leave_notice(session: NoticeSession): cfg = util.load_config(__file__) no_leave_notice_group = cfg.get('no_leave_notice', []) if session.ctx['group_id'] not in no_leave_notice_group: await session.send(f"{session.ctx['user_id']}退群了。")
def get_config(): return util.load_config(__file__)
def __get_auth_key(): config = util.load_config(__file__) return config["AUTH_KEY"]
import random from hoshino import Service, util from hoshino.typing import CQEvent import time from .choicer import Choicer sv = Service('2d_girl', enable_on_default=True, help_='''今天也是少女! [今天我是什么少女] 看看今天你是什么少女 [@xxx今天是什么少女] 看看xxx今天是什么少女''') inst = Choicer(util.load_config(__file__)) @sv.on_fullmatch('今天我是什么少女') async def my_shoujo(bot, ev: CQEvent): uid = ev.user_id name = ev.sender['card'] or ev.sender['nickname'] msg = inst.format_msg(uid, name) await bot.send(ev, msg) @sv.on_prefix('今天是什么少女') @sv.on_suffix('今天是什么少女') async def other_shoujo(bot, ev: CQEvent): arr = [] for i in ev.message: if i['type'] == 'at' and i['data']['qq'] != 'all': arr.append(int(i['data']['qq'])) gid = ev.group_id
def load_chara(self, pool_name: str): config = util.load_config(__file__) pool = config[pool_name] self.player = pool["player"] self.number = pool["number"]
def get_token(): config = util.load_config(__file__) return config["MIKAN_TOKEN"]
from typing import Iterable from lxml import etree import json import os from asyncio import sleep from nonebot import CommandSession from hoshino import service, aiorequests from hoshino.util import load_config sv = service.Service("steam", enable_on_default=False, visible=False) subscribe_file = os.path.join(os.path.dirname(__file__), 'subscribes.json') with open(subscribe_file, mode="r") as f: f = f.read() sub = json.loads(f) cfg = load_config(__file__) playing_state = {} async def format_id(id: str) -> str: if id.startswith('76561198') and len(id) == 17: return id else: resp = await aiorequests.get( f'https://steamcommunity.com/id/{id}?xml=1') xml = etree.XML(await resp.content) return xml.xpath('/profile/steamID64')[0].text @sv.on_command("添加steam订阅") async def steam(session: CommandSession):
import random from hoshino import aiorequests from nonebot import NoneBot from hoshino import util from hoshino.service import Service, Privilege sv = Service('deepchat', manage_priv=Privilege.SUPERUSER, enable_on_default=False, visible=False) api = util.load_config(__file__)['deepchat_api'] @sv.on_message('group') async def deepchat(bot: NoneBot, ctx): msg = ctx['message'].extract_plain_text() if not msg or random.random() > 0.025: return payload = {"msg": msg, "group": ctx['group_id'], "qq": ctx['user_id']} sv.logger.info(payload) rsp = await aiorequests.post(api, data=payload) j = await rsp.json() sv.logger.info(j) if j['msg']: await bot.send(ctx, j['msg'])
import re import pytz import random import asyncio from datetime import datetime from functools import partial, wraps from collections import defaultdict from TwitterAPI import TwitterAPI, TwitterResponse from nonebot import MessageSegment as ms from hoshino import util from hoshino.service import Service, Privilege as Priv cfg = util.load_config(__file__) api = TwitterAPI(cfg['consumer_key'], cfg['consumer_secret'], cfg['access_token_key'], cfg['access_token_secret']) sv = Service('twitter-poller', use_priv=Priv.ADMIN, manage_priv=Priv.ADMIN, visible=False) URL_TIMELINE = 'statuses/user_timeline' subr_dic = { Service('kc-twitter', enable_on_default=False): ['KanColle_STAFF', 'C2_STAFF', 'ywwuyi'], Service('pcr-twitter', enable_on_default=True): ['priconne_redive', 'priconne_anime'], Service('pripri-twitter', enable_on_default=False, visible=False): ['pripri_anime'], Service('shiratama-twitter', enable_on_default=False, visible=False):
async def increace_notice(session: NoticeSession): cfg = util.load_config(__file__) welcome_dic = cfg.get('increase_welcome', {}) gid = str(session.ctx['group_id']) if gid in welcome_dic: await session.send(welcome_dic[gid], at_sender=True)