nonebot2+cqhttp 防闪照与防撤回插件
生活随笔
收集整理的這篇文章主要介紹了
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机统计知识,计算机知识在统计工作中的
- 下一篇: 设备模型1