コード例 #1
0
ファイル: morning.py プロジェクト: Astroelle/CoolQBot
""" 每日早安插件
"""
import re
from random import randint

import requests
from nonebot import CommandSession, on_command

from coolqbot import PluginData, bot

DATA = PluginData('morning', config=True)

HOUR = int(DATA.config_get('morning', 'hour', fallback='7'))
MINUTE = int(DATA.config_get('morning', 'minute', fallback='30'))
SECOND = int(DATA.config_get('morning', 'second', fallback='0'))


@bot.scheduler.scheduled_job('cron',
                             hour=HOUR,
                             minute=MINUTE,
                             second=SECOND,
                             id='morning')
async def morning():
    """ 早安
    """
    hello_str = get_message()
    await bot.get_bot().send_msg(message_type='group',
                                 group_id=bot.get_bot().config.GROUP_ID,
                                 message=hello_str)
    bot.logger.info('发送早安信息')
コード例 #2
0
ファイル: tencent.py プロジェクト: cliuxinxin/CoolQBot_base
import hashlib
import json
import random
import string
import time
from typing import Optional
from urllib import parse

import aiohttp
from nonebot import CommandSession
from nonebot.helpers import context_id

from coolqbot import PluginData

DATA = PluginData('robot', config=True)
TENCENT_AI_APP_ID = DATA.config_get('tencent', 'app_id')
TENCENT_AI_APP_KEY = DATA.config_get('tencent', 'app_key')


async def call_tencent_api(session: CommandSession,
                           text: str) -> Optional[str]:
    """ 调用腾讯机器人的 API 获取回复
    """
    if not TENCENT_AI_APP_KEY:
        return None

    if not text:
        return None

    url = 'https://api.ai.qq.com/fcgi-bin/nlp/nlp_textchat'
コード例 #3
0
""" 复读插件
"""
import re
import secrets
from datetime import datetime, timedelta

from nonebot import (CommandSession, IntentCommand, NLPSession, on_command,
                     on_natural_language, on_notice, permission)

from coolqbot import PluginData, bot

from .recorder import recorder

DATA = PluginData('repeat', config=True)
# 复读概率
REPEAT_RATE = int(DATA.config_get('bot', 'repeat_rate', fallback='10'))
# 复读间隔
REPEAT_INTERVAL = int(DATA.config_get('bot', 'repeat_interval', fallback='1'))


def is_repeat(session: CommandSession, message):
    group_id = session.ctx['group_id']
    user_id = session.ctx['sender']['user_id']
    # 只复读指定群内消息
    if group_id not in session.bot.config.GROUP_ID:
        return False

    # 不要复读指令
    match = re.match(r'^\/', message)
    if match:
        return False
コード例 #4
0
""" 和风天气
"""
import json
import re
import urllib

import requests

from coolqbot import PluginData

DATA = PluginData('weather', config=True)
KEY = DATA.config_get('heweather', 'key')


def heweather(city):
    """ 和风天气 API

    日本 东京
    当前温度:25(体感温度:29)
    2018-08-13 中雨 降水概率:0% 温度:32~26℃
    2018-08-14 小雨 降水概率:13% 温度:33~26℃
    2018-08-15 小雨 降水概率:11% 温度:32~25℃
    """
    if not KEY:
        return None

    try:
        city_name = urllib.parse.quote(city.encode('utf-8'))
        url_str = f'https://free-api.heweather.com/s6/weather?location={city_name}&key={KEY}'
        response = requests.get(url_str)
        data = response.content.decode('utf-8')
コード例 #5
0
ファイル: tuling.py プロジェクト: cliuxinxin/CoolQBot_base
""" 图灵机器人

http://www.turingapi.com/
"""
import json
from typing import Optional

import aiohttp
from nonebot import CommandSession
from nonebot.helpers import context_id

from coolqbot import PluginData

DATA = PluginData('robot', config=True)
TULING_API_KEY = DATA.config_get('tuling', 'api_key')


async def call_tuling_api(session: CommandSession, text: str) -> Optional[str]:
    """ 调用图灵机器人的 API 获取回复
    """
    if not TULING_API_KEY:
        return None

    if not text:
        return None

    url = 'http://openapi.tuling123.com/openapi/api/v2'

    # 构造请求数据
    payload = {
        'reqType': 0,