最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python制作機(jī)器人的實(shí)現(xiàn)方法

 更新時(shí)間:2021年06月17日 08:45:23   作者:川川菜鳥(niǎo)  
機(jī)器人自動(dòng)回復(fù)在很多場(chǎng)景中都可以用的上,本文主要介紹了python制作機(jī)器人的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

是否也像擁有自己的機(jī)器人呢?

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

不挨個(gè)展示了。
比如說(shuō)你想實(shí)現(xiàn)一個(gè)夸人的功能:

"""
作者:川川
時(shí)間:2021/4/6
"""

from nonebot.adapters.cqhttp import Message, PokeNotifyEvent,Bot
from nonebot import on_notice
import warnings
from nonebot.permission import *
import requests
warnings.filterwarnings("ignore")
from aiocqhttp.exceptions import Error as CQHttpError
poke = on_notice()


@poke.handle()
async def _(bot: Bot, event: PokeNotifyEvent):
    if event.is_tome() and event.user_id != event.self_id:
        msg=await kua()
        chuo = f"[CQ:tts,text={msg}]"
        try:
            await poke.send(Message(f'{Message(chuo)}'))
        except CQHttpError:
            pass

async def kua():
    url = 'https://chp.shadiao.app/api.php'
    resp = requests.get(url)
    return resp.text

在這里插入圖片描述

或者你也想機(jī)器人發(fā)送美女圖片:

"""
作者:川川
時(shí)間:2021/5/5
"""
from nonebot.adapters.cqhttp import Message
from nonebot import on_keyword,on_notice
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
import requests, re
from aiocqhttp.exceptions import Error as CQHttpError
from nonebot.adapters.cqhttp import message,GroupMessageEvent,Message,MessageEvent
from nonebot.typing import T_State
from nonebot.permission import SUPERUSER
yulu = on_keyword({'澀圖'},priority=10)
@yulu.handle()
async def j(bot: Bot, event:message, state: T_State):
    msg = await mei()
    try:
        await yulu.send(Message(msg))
    except CQHttpError:
        pass


async def mei():
    url = 'https://api.66mz8.com/api/rand.img.php?type=美女&format=json'
    resp = requests.get(url)
    data = resp.json()
    ur = data.get('pic_url')
    tu = f"[CQ:image,file={ur}]"
    return tu

在這里插入圖片描述

再或者你想要機(jī)器人每天定時(shí)給你發(fā)天氣預(yù)報(bào):

"""
作者:川川
時(shí)間:2021/5/10
"""
from nonebot import require
import nonebot
import requests
scheduler = require('nonebot_plugin_apscheduler').scheduler

@scheduler.scheduled_job('cron', hour='12',minute='08', id='sleep4')
async def co():
    # d = time.strftime("%m-%d %H:%M:%S", time.localtime())
    url = 'http://apis.juhe.cn/simpleWeather/query?city=上海&key=a8b3dd5052f0e3e2dff14175165500d6'
    data = requests.get(url=url, timeout=5).json()
    # to=resp['result']['future'][0]
    t = "時(shí)間:" + data['result']['future'][0]['date']
    w = "溫度:" + data['result']['future'][0]['temperature']
    e = "天氣:" + data['result']['future'][0]['weather']
    f = "風(fēng)向:" + data['result']['future'][0]['direct']

    a = "時(shí)間:" + data['result']['future'][1]['date']
    b = "溫度:" + data['result']['future'][1]['temperature']
    c = "天氣:" + data['result']['future'][1]['weather']
    g = "風(fēng)向:" + data['result']['future'][1]['direct']
    tu=str(t + '\n' + w + '\n' + e + '\n' + f + '\n\n\n' + a + '\n' + b + '\n' + c + '\n' + g)

    bot = nonebot.get_bots()['1786691956']
    return await bot.call_api('send_msg', **{
        'message': '天氣預(yù)報(bào):\n{}'.format(tu),
        'user_id': '2835809579'
    })

在這里插入圖片描述

當(dāng)然也有bot源碼:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import nonebot
from nonebot.adapters.cqhttp import Bot as CQHTTPBot
# Custom your logger
# 
# from nonebot.log import logger, default_format
# logger.add("error.log",
#            rotation="00:00",
#            diagnose=False,
#            level="ERROR",
#            format=default_format)

# You can pass some keyword args config to init function
nonebot.init()
app = nonebot.get_asgi()

driver = nonebot.get_driver()
driver.register_adapter("cqhttp", CQHTTPBot)
nonebot.load_builtin_plugins()
nonebot.load_from_toml("pyproject.toml")
# Modify some config / config depends on loaded configs
# 
# config = driver.config
# do something...


if __name__ == "__main__":
    nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!")
    nonebot.run(app="__mp_main__:app")

當(dāng)然還有一些配置文件源碼,我覺(jué)得可能沒(méi)有多的必要繼續(xù)發(fā),新手可能看不懂了。大概就
似乎群友玩得挺嗨!

在這里插入圖片描述

到此這篇關(guān)于python制作機(jī)器人的實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)python 機(jī)器人內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python3.6簡(jiǎn)單反射操作示例

    Python3.6簡(jiǎn)單反射操作示例

    這篇文章主要介紹了Python3.6簡(jiǎn)單反射操作,結(jié)合實(shí)例形式分析了Python3反射的概念、原理、相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2018-06-06
  • Python使用random.shuffle()隨機(jī)打亂字典排序

    Python使用random.shuffle()隨機(jī)打亂字典排序

    本文主要介紹了Python使用random.shuffle()隨機(jī)打亂字典排序,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Python基于PycURL實(shí)現(xiàn)POST的方法

    Python基于PycURL實(shí)現(xiàn)POST的方法

    這篇文章主要介紹了Python基于PycURL實(shí)現(xiàn)POST的方法,涉及Python實(shí)現(xiàn)curl傳遞post數(shù)據(jù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • Python排序算法之堆排序算法

    Python排序算法之堆排序算法

    堆排序看字面意思是一種排序方法,那堆是什么呢?堆是一個(gè)近似完全二叉樹(shù)的結(jié)構(gòu),并同時(shí)滿(mǎn)足堆積的性質(zhì)。其實(shí)堆排序是指利用堆這種數(shù)據(jù)結(jié)構(gòu)所設(shè)計(jì)的一種排序算法。
    2023-01-01
  • 解決python3 整數(shù)數(shù)組轉(zhuǎn)bytes的效率問(wèn)題

    解決python3 整數(shù)數(shù)組轉(zhuǎn)bytes的效率問(wèn)題

    這篇文章主要介紹了解決python3 整數(shù)數(shù)組轉(zhuǎn)bytes的效率問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • 最新評(píng)論

    泊头市| 扶风县| 江孜县| 肃宁县| 宾阳县| 防城港市| 洪泽县| 高陵县| 大连市| 合阳县| 上杭县| 马关县| 清苑县| 铜梁县| 徐汇区| 巴南区| 海兴县| 准格尔旗| 马尔康县| 静海县| 随州市| 普兰县| 英吉沙县| 新干县| 中山市| 自治县| 景泰县| 滦平县| 双鸭山市| 洮南市| 慈溪市| 永丰县| 威远县| 灵川县| 祁东县| 平武县| 永新县| 葫芦岛市| 宜阳县| 大冶市| 民县|