日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nonebot2+cqhttp 防闪照与防撤回插件

發(fā)布時間:2023/12/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nonebot2+cqhttp 防闪照与防撤回插件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

先是防閃照

from nonebot import on_notice,on_command,on_message from nonebot.adapters.onebot.v11 import Bot,MessageEvent from nonebot.adapters.onebot.v11 import Message from nonebot.rule import to_me from nonebot.matcher import Matcher from nonebot.params import CommandStart,CommandArg from nonebot.permission import SUPERUSER from nonebot.typing import T_State import yaml from ruamel import yaml import osanti_switch = on_command('防閃照', permission=SUPERUSER, priority=1) @anti_switch.handle() async def anti_switch_(matcher: Matcher, args: Message = CommandArg()):plain_text = args.extract_plain_text()if plain_text == '開':#['Anti-flashpic']['status']修改為Truewith open('pluginconfig.yml', 'r', encoding='utf-8') as f:anti_flashpic = yaml.safe_load(f)anti_flashpic['Anti-flashpic']['status'] = Truewith open('pluginconfig.yml', 'w', encoding='utf-8') as nf:yaml.dump(anti_flashpic, nf,Dumper=yaml.RoundTripDumper)await matcher.finish('防閃照已開啟')elif plain_text == '關(guān)':#['Anti-flashpic']['status']修改為Falsewith open('pluginconfig.yml', 'r', encoding='utf-8') as f:anti_flashpic = yaml.safe_load(f)anti_flashpic['Anti-flashpic']['status'] = Falsewith open('pluginconfig.yml', 'w', encoding='utf-8') as nf:yaml.dump(anti_flashpic, nf,Dumper=yaml.RoundTripDumper)await matcher.finish('防閃照已關(guān)閉')anti_flashpic = on_message(priority=1, block=False) @anti_flashpic.handle() async def anti_flashpic_(bot: Bot,event: MessageEvent ,state: T_State):try:if 'type=flash]'in str(event.message) :checkyml = yaml.safe_load(open('pluginconfig.yml','r+',encoding='utf-8'))['Anti-flashpic']['status']if checkyml == True:imgstr = str(event.message).split(',')[1]await bot.send_group_msg(group_id=event.group_id, message=f"[CQ:image,{imgstr},subType=0]")await anti_flashpic.finish()except Exception as e:pass

再是防撤回

from nonebot import on_notice,on_command,on_message from nonebot.adapters.onebot.v11 import Bot,GroupRecallNoticeEvent,MessageEvent from nonebot.adapters.onebot.v11 import Message from nonebot.rule import to_me from nonebot.matcher import Matcher from nonebot.params import CommandStart,CommandArg from nonebot.permission import SUPERUSER from nonebot.typing import T_State import yaml from ruamel import yamlanti_switch = on_command('防撤回', permission=SUPERUSER, priority=1) @anti_switch.handle() async def anti_switch_(matcher: Matcher, args: Message = CommandArg()):plain_text = args.extract_plain_text()if plain_text == '開':#['Anti-flashpic']['status']修改為Truewith open('pluginconfig.yml', 'r', encoding='utf-8') as f:anti_flashpic = yaml.safe_load(f)anti_flashpic['Anti-msg']['status'] = Truewith open('pluginconfig.yml', 'w', encoding='utf-8') as nf:yaml.dump(anti_flashpic, nf,Dumper=yaml.RoundTripDumper)await matcher.finish('防撤回已開啟')elif plain_text == '關(guān)':#['Anti-flashpic']['status']修改為Falsewith open('pluginconfig.yml', 'r', encoding='utf-8') as f:anti_flashpic = yaml.safe_load(f)anti_flashpic['Anti-msg']['status'] = Falsewith open('pluginconfig.yml', 'w', encoding='utf-8') as nf:yaml.dump(anti_flashpic, nf,Dumper=yaml.RoundTripDumper)await matcher.finish('防撤回已關(guān)閉')anti_msgrecall = on_notice(priority=1, block=False) @anti_msgrecall.handle() async def anti_msgrecall_(bot: Bot,event: GroupRecallNoticeEvent,state: T_State):if event.notice_type == 'group_recall':checkyml = yaml.safe_load(open('pluginconfig.yml','r+',encoding='utf-8'))['Anti-msg']['status']if checkyml == True:message_id = event.message_idrecallmsg = await bot.call_api('get_msg',message_id=message_id)#print(recallmsg['group_id'],recallmsg['message'],recallmsg['sender']['nickname'])await bot.send_group_msg(group_id=event.group_id, message=f"群友:{recallmsg['sender']['nickname']}({recallmsg['sender']['user_id']})\n撤回了一條消息,撤回的內(nèi)容為:\n{recallmsg['message']}")await anti_msgrecall.finish()

其中需要機器人運行目錄下創(chuàng)建一個pluginconfig.yml文件

Anti-flashpic:status: true Anti-msg:status: true

總結(jié)

以上是生活随笔為你收集整理的nonebot2+cqhttp 防闪照与防撤回插件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。