def init(config): none.init(config) bot = none.get_bot() none.load_builtin_plugins() none.load_plugins(path.join(path.dirname(__file__), 'plugins'), 'popuko.plugins') return bot
def get_nlp_client() -> AipNlp: global _nlp if _nlp is None: bot = get_bot() _nlp = AipNlp(bot.config.BAIDU_AIP_APP_ID, bot.config.BAIDU_AIP_API_KEY, bot.config.BAIDU_AIP_SECRET_KEY) return _nlp
async def _(): bot = none.get_bot() now = datetime.now(pytz.timezone('Asia/Shanghai')) try: await bot.send_group_msg(group_id=672076603, message=f'现在{now.hour}点整啦!') except CQHttpError: pass
def get_data_folder(sub_folder: str = '') -> str: data_folder = get_bot().config.DATA_FOLDER if sub_folder: data_folder = os.path.join(data_folder, sub_folder) logger.debug(f'Creating data folder {data_folder} if not exists') os.makedirs(data_folder, mode=0o755, exist_ok=True) return data_folder
def init() -> None: """ Initialize the cache module. This must be called before any plugins using cache, and after initializing "none" module. """ bot = get_bot() caches.set_config({'default': bot.config.AIOCACHE_DEFAULT_CONFIG})
async def _scheduled_commands_callback( ctx: Dict[str, Any], commands: List[ScheduledCommand]) -> None: # get the current bot, we may not in the original running environment now bot = none.get_bot() for cmd in commands: await call_command(bot, ctx, cmd.name, current_arg=cmd.current_arg, check_perm=True, disable_interaction=True)
def init() -> None: """ Initialize database module. This must be called before any plugins using database, and after initializing "none" module. """ logger.debug('Initializing database') bot = get_bot() asyncio.get_event_loop().run_until_complete( db.set_bind(bot.config.DATABASE_URL))
async def find(location: str) -> Optional[Dict[str, Any]]: try: resp = await requests.get('https://search.heweather.com/find', params={ 'location': location, 'key': get_bot().config.HEWEATHER_KEY, 'group': 'cn', }) if resp.ok: return (await resp.json()).get('HeWeather6', [])[0] except (requests.RequestException, json.JSONDecodeError, AttributeError, IndexError): pass
async def analysis(text: str, pattern: str) -> LTPCloudResult_T: bot = get_bot() try: resp = await requests.post('https://api.ltp-cloud.com/analysis/', data={ 'api_key': bot.config.LTP_CLOUD_API_KEY, 'text': text, 'pattern': pattern, 'format': 'json', }) return await resp.json() if resp.ok else [] except (requests.RequestException, json.JSONDecodeError): return []
async def _(): none.logger.info("Running scheduled Job") loadConfig() bot = none.get_bot() tmp = rss("db").query(URLS) for i, post in enumerate(tmp): text = [] text.append({"type": "text", "data": {"text": f'{post.title}\n'}}) text.append({"type": "text", "data": {"text": f'发布于 {post.author}\n'}}) text.append({"type": "text", "data": {"text": f'{post.link}'}}) none.logger.info(text) try: for num in QQGroup: await bot.send_group_msg(group_id=num, message=text) except CQHttpError: pass
async def update_map_status(): bot = none.get_bot() mapdata = open('mapdata.json', 'r') old_data = mapdata.read() old_data = json.loads(old_data) mapdata.close() list = getUser.getUsers() users = list['user'] groups = list['group'] new_data = getData.get_nominate_data() remove_list = [] for d in new_data: for d2 in new_data: if d['hash'] == d2['hash'] and d['mapstatus'] == 'nominate' and d2[ 'mapstatus'] == 'qualify': remove_list.append(d2) d['mapstatus'] = 'qualify' for item in remove_list: new_data.remove(item) for d in new_data: time.sleep(2) if not ifExisted(d, old_data): old_data.append(d) for usr in users: time.sleep(0.5) try: await bot.send_private_msg(user_id=usr, message=dataToString(d)) except CQHttpError: pass for group in groups: time.sleep(0.5) try: await bot.send_group_msg(group_id=group, message=dataToString(d)) except CQHttpError: pass with open('mapdata.json', "r+") as f: read_data = f.read() f.seek(0) f.truncate() f.write(json.dumps(new_data))
import asyncio import atexit from datetime import datetime from os import path import signal from typing import Optional from none import on_natural_language, NLPSession, get_bot from none.helpers import context_id from pandas import DataFrame, read_parquet from amadeus import fs, aio, dt PLUGIN_NAME = 'message_collector' bot = get_bot() data_frame: DataFrame = None last_collect_dt: datetime = None lock = asyncio.Lock() @on_natural_language(only_to_me=False, only_short_message=False) async def _(session: NLPSession): data = { 'timestamp': [session.ctx['time']], 'ctx_id': [context_id(session.ctx)], 'self_id': [session.ctx['self_id']], 'message': [str(session.ctx['message'])] } # we don't want to block the processing of message, # so just make sure it will append in the future
from none import on_command, CommandSession, Message, message_preprocessor, MessageSegment, get_bot, permission import re import json import os import demjson import none import pymysql from os import path bot = none.get_bot() @on_command('forgetall', only_to_me=False, permission=permission.GROUP_ADMIN) async def forget(session: CommandSession): msg = session.ctx text_report = await fg_text(msg) await session.send(text_report) @forget.args_parser async def _(session: CommandSession): # 去掉消息首尾的空白符 stripped_arg = session.current_arg_text.strip() session.args['text'] = stripped_arg async def fg_text(msg) -> dict: if 'group_id' in msg: QG = msg['group_id'] else: QG = 'NULL'
async def cb(): bot_ = none.get_bot() try: await bot_.send_private_msg(user_id=1002647525, message='哇') except Exception as e: none.logger.exception(e)
from os import path import none from none_demo import config none.init(config) app = none.get_bot().asgi if __name__ == '__main__': none.load_builtin_plugins() none.load_plugins(path.join(path.dirname(__file__), 'plugins'), 'none_demo.plugins') none.run(host=config.HOST, port=config.PORT)