import re import asyncio from none import CommandSession, CommandGroup from none.command import call_command from none.helpers import context_id from none.expression import render from amadeus import nlp from amadeus.db import db from amadeus.command import allow_cancellation from . import expressions as expr from .models import Note note = CommandGroup('note') async def note_count(ctx_id: str) -> int: return await db.select([db.func.count(Note.id)] ).where(Note.context_id == ctx_id).gino.scalar() @note.command('add', aliases=('记录', '记笔记', '添加笔记')) async def note_add(session: CommandSession): content = session.get('content', prompt_expr=expr.ADD_WHAT_CONTENT) new_note = await Note.create(content=content, context_id=context_id(session.ctx)) await session.send_expr(expr.ADD_SUCCESS, id=new_note.id, content=new_note.content)
import re from none import CommandSession, CommandGroup from none import on_natural_language, NLPSession, NLPResult from none.expression import render from amadeus import nlp from amadeus.command import allow_cancellation from . import expressions as expr w = CommandGroup('weather') @w.command('weather', aliases=('weather', '天气', '天气预报', '查天气')) async def weather(session: CommandSession): location = session.get('location', prompt_expr=expr.WHERE) # time = session.get_optional('time') if location.province and not location.city and not location.district: # there is no city or district, ask the user for more info! session.get('location_more', prompt=render(expr.WHERE_IN_PROVINCE, province=location.province)) final_loc = location.heweather_format() await session.send(f'位置:{final_loc}') @weather.args_parser @allow_cancellation
import re import shlex import asyncio from typing import List, Optional from none import CommandGroup, CommandSession, permission as perm from none.argparse import ArgumentParser, ParserExit, Namespace from none.command import parse_command from none.helpers import context_id from amadeus import scheduler from amadeus.scheduler import ScheduledCommand PLUGIN_NAME = 'schedule' sched = CommandGroup(PLUGIN_NAME, permission=perm.PRIVATE | perm.GROUP_ADMIN) @sched.command('add', aliases=('schedule', )) async def sched_add(session: CommandSession): parser = ArgumentParser() parser.add_argument('-S', '--second') parser.add_argument('-M', '--minute') parser.add_argument('-H', '--hour') parser.add_argument('-d', '--day') parser.add_argument('-m', '--month') parser.add_argument('-w', '--day-of-week') parser.add_argument('-f', '--force', action='store_true', default=False) parser.add_argument('-v', '--verbose', action='store_true', default=False) parser.add_argument('--name', required=True) parser.add_argument('commands', nargs='+')
import atexit import re import shlex from typing import Iterable, Tuple, Dict, Any from apscheduler.jobstores.base import ConflictingIdError from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore from apscheduler.schedulers.asyncio import AsyncIOScheduler from none import get_bot, CommandGroup, CommandSession, permission as perm from none.argparse import ArgumentParser, ParserExit from none.command import parse_command, call_command from none.helpers import context_id, send sched = CommandGroup('schedule', permission=perm.PRIVATE | perm.GROUP_ADMIN) _bot = get_bot() _scheduler = AsyncIOScheduler( jobstores={ 'default': SQLAlchemyJobStore( url=_bot.config.DATABASE_URL, tablename=make_table_name('schedule', 'apscheduler_jobs') ) }, timezone='Asia/Shanghai' ) if not _scheduler.running: _scheduler.start()
import re import math from none import CommandGroup, CommandSession from amadeus import dt from amadeus.aio import requests bilibili_anime = CommandGroup('bilibili_anime') INDEX_API_URL = 'https://bangumi.bilibili.com/media/web_api/search/result?season_version=-1&area=-1&is_finish=-1©right=-1&season_status=-1&season_month={month}&pub_date={year}&style_id=-1&order=3&st=1&sort=0&page=1&season_type=1&pagesize=20' INDEX_WEB_URL = 'https://www.bilibili.com/anime/index/#season_version=-1&area=-1&is_finish=-1©right=-1&season_status=-1&season_month={month}&pub_date={year}&style_id=-1&order=3&st=1&sort=0&page=1' @bilibili_anime.command('index', aliases={'番剧索引', '番剧', '新番'}) async def index(session: CommandSession): now = dt.beijing_now() year = session.get_optional('year', now.year) month = session.get_optional('month', math.ceil(now.month / 3) * 3 - 3 + 1) api_url = INDEX_API_URL.format(year=year, month=month) resp = await requests.get(api_url) payload = await resp.json() if not payload or payload.get('code') != 0: await session.send('查询失败了……') return anime_list = payload['result']['data'] if not anime_list: await session.send('没有查询到相关番剧……') return