Skip to content

Commit

Permalink
chore.迁移项目至nb-cli 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 14, 2022
1 parent 247ac98 commit 0091d18
Show file tree
Hide file tree
Showing 48 changed files with 128 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ENVIRONMENT=dev
ENVIRONMENT=prod
APSCHEDULER_AUTOSTART=true
APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"}
4 changes: 2 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HOST=127.0.0.1
PORT=8080
DEBUG=true
COMMAND_START=["/", ""]
LOG_LEVEL=DEBUG
FASTAPI_RELOAD=true
4 changes: 1 addition & 3 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
HOST=127.0.0.1
HOST=0.0.0.0
PORT=8080
SECRET=
ACCESS_TOKEN=
19 changes: 2 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@ dmypy.json
# pytype static type analyzer
.pytype/

*.db

# End of https://www.toptal.com/developers/gitignore/api/python
resource/voices/1.wav
resource/voices/帕拉斯/帕拉斯_交谈1.wav
resource/voices/帕拉斯/帕拉斯_交谈2.wav
resource/voices/帕拉斯/帕拉斯_交谈3.wav
resource/voices/帕拉斯/帕拉斯_任命助理.wav
resource/voices/帕拉斯/帕拉斯_信赖提升后交谈1.wav
resource/voices/帕拉斯/帕拉斯_信赖提升后交谈2.wav
resource/voices/帕拉斯/帕拉斯_信赖提升后交谈3.wav
resource/voices/帕拉斯/帕拉斯_信赖触摸.wav
resource/voices/帕拉斯/帕拉斯_戳一下.wav
resource/voices/帕拉斯/帕拉斯_晋升后交谈1.wav
resource/voices/帕拉斯/帕拉斯_晋升后交谈2.wav
resource/voices/帕拉斯/帕拉斯_问候.wav
resource/voices/帕拉斯/帕拉斯_闲置.wav
.vscode/db.json

resource/voices/*
27 changes: 22 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
FROM namiya233/go-cqhttp
FROM python:3.9 as requirements-stage

FROM python:3.8
WORKDIR /tmp

COPY ./pyproject.toml ./poetry.lock* /tmp/

RUN curl -sSL https://install.python-poetry.org -o install-poetry.py

RUN python install-poetry.py --yes

ENV PATH="${PATH}:/root/.local/bin"

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9

COPY / /app/
RUN pip install --no-cache-dir -r /app/requirements.txt
WORKDIR /app
CMD ["python","bot.py"]

COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt

RUN pip install --no-cache-dir --upgrade -r requirements.txt

RUN rm requirements.txt

COPY ./ /app/
11 changes: 4 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-

import nonebot
from nonebot.adapters.cqhttp import Bot as CQHTTPBot
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter

# Custom your logger
#
# from nonebot.log import logger, default_format
Expand All @@ -17,16 +18,12 @@
app = nonebot.get_asgi()

driver = nonebot.get_driver()
driver.register_adapter("cqhttp", CQHTTPBot)
driver.register_adapter(ONEBOT_V11Adapter)


# Please DO NOT modify this file unless you know what you are doing!
# As an alternative, you should use command `nb` or modify `pyproject.toml` to load plugins
nonebot.load_from_toml("pyproject.toml")
nonebot.load_plugins("bot/plugins")
nonebot.init(apscheduler_autostart=True)
nonebot.init(apscheduler_config={
"apscheduler.timezone": "Asia/Shanghai"
})

# Modify some config / config depends on loaded configs
#
Expand Down
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ account:
password: "机器人密码"

message:
post-format: array
post-format: string

servers:
- ws-reverse:
universal: ws://127.0.0.1:8080/cqhttp/ws
universal: ws://127.0.0.1:8080/onebot/v11/ws
10 changes: 3 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
version: "2"
version: "3"
services:
# 其他配置参考 https://hub.docker.com/r/tiangolo/uvicorn-gunicorn-fastapi/
nonebot:
build: bot
volumes:
- "/etc/localtime:/etc/localtime"
- "./:/app/"
build: .
container_name: nonebot
ports:
- "8080:8080" # 映射端口到宿主机 宿主机端口:容器端口
env_file:
- ".env.prod" # fastapi 使用的环境变量文件
environment:
- ENVIRONMENT=prod # 配置 nonebot 运行环境,此项会被 .env 文件覆盖
- APP_MODULE=bot:app # 配置 asgi 入口
- SECRET # 通过 SECRET=xxx nb up -d 传递密钥
- ACCESS_TOKEN # 通过 ACCESS_TOKEN=xxx nb up -d 传递密钥
- MAX_WORKERS=1 # 如果你有多个QQ,且存在 self_id 指定,多个 worker 会导致无法找到其他 websocket 连接
network_mode: bridge
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
[tool.poetry]
name = "bot"
name = "Pallas-Bot"
version = "0.1.0"
description = "bot"
description = "Pallas-Bot"
authors = []
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7.3"
nonebot2 = "^2.0.0.a1"
nonebot2 = "^2.0.0-beta.1"

[tool.poetry.dev-dependencies]
nb-cli = "^0.5.0"
nonebot-plugin-test = "^0.3.0"
nb-cli = "^0.6.0"

[nonebot.plugins]
[tool.nonebot]
plugins = ["nonebot_plugin_apscheduler"]
plugin_dirs = ["bot/plugins"]
plugin_dirs = ["src/plugins"]

[build-system]
requires = ["poetry_core>=1.0.0"]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
from nonebot import on_command
from nonebot import on_message
from nonebot.adapters.cqhttp import MessageSegment, Message
from nonebot.adapters.onebot.v11 import MessageSegment, Message
from nonebot.rule import to_me
from nonebot.rule import startswith
from nonebot.rule import regex
Expand All @@ -18,6 +18,8 @@

door = False
hello = on_message(block=False, priority=10)


@hello.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
# print(event.dict())
Expand All @@ -29,21 +31,24 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State):
if(msg['type'] == 'image') & door:
# print(msg['data']['url'])
reply = doImgCheck(str(msg['data']['url']))
if (reply != "")&(reply != None) & door:
if (reply != "") & (reply != None) & door:
if float(reply['probability']) > plugin_config.recall_nsfw_pic_probability:
await doRecall(bot,event,state)
await hello.send(reply['conclusion'])
await doRecall(bot, event, state)
await hello.send(reply['conclusion'])
# await hello.send(msgStr)
return False

switch = on_command("色图检测", rule=to_me(), priority=5)


@switch.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
# print("in setu check")
args = str(event.get_message()).strip()
if args:
state["param"] = args


@switch.got("param", prompt="开启或关闭")
async def handle_param(bot: Bot, event: Event, state: T_State):
global door
Expand All @@ -52,14 +57,15 @@ async def handle_param(bot: Bot, event: Event, state: T_State):
await switch.reject("参数错误!")
if param in "开启":
door = True
if param in "关闭":
if param in "关闭":
door = False
await switch.finish("已"+str(param))


def doImgCheck(picUrl: str):
# print("in img check function")
request_url = "https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined"
params = {"imgUrl":picUrl}
params = {"imgUrl": picUrl}
access_token = plugin_config.baidu_api_ak
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
Expand All @@ -71,12 +77,13 @@ def doImgCheck(picUrl: str):
if response.json()['conclusion'] != "合规":
conclusion = response.json()['data'][0]['msg']
deep = response.json()['data'][0]['probability']
reply = {'conclusion':str(conclusion),'probability':str(deep)}
reply = {'conclusion': str(
conclusion), 'probability': str(deep)}
return reply
except KeyError:
print('KeyError')
return
else:
else:
return
return

Expand All @@ -86,4 +93,4 @@ async def doRecall(bot: Bot, event: Event, state: T_State):
# print(event.dict())
msgId = event.dict()['message_id']
# print(msgId)
await bot.call_api('delete_msg',message_id=msgId)
await bot.call_api('delete_msg', message_id=msgId)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from nonebot import on_message
from nonebot.adapters.cqhttp import MessageSegment, Message, permission, GroupMessageEvent
from nonebot.adapters.onebot.v11 import MessageSegment, Message, permission, GroupMessageEvent
from nonebot.rule import keyword, startswith, endswith, Rule
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nonebot import on_command
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, PrivateMessageEvent
from nonebot.adapters.cqhttp.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, PrivateMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER

status = {}
help_text = r'''“战争女神”的故事经历,就交给前赴后继渴望解放的人们好好使用吧!
Expand All @@ -14,21 +14,24 @@

help = on_command("牛牛帮助", aliases={'牛牛功能', '帕拉斯帮助', '帕拉斯功能'})


@help.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if status.get(event.group_id, True):
await help.finish(help_text)


@help.handle()
async def _(bot: Bot, event: PrivateMessageEvent):
await help.finish(help_text)


help_mode_switch = on_command(
"牛牛开启帮助", aliases={"牛牛关闭帮助"},
permission=GROUP_ADMIN|GROUP_OWNER
permission=GROUP_ADMIN | GROUP_OWNER
)


@help_mode_switch.handle()
async def _(bot: Bot, event: GroupMessageEvent):
msg = event.dict()['raw_message']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from nonebot import on_command , on_message
from nonebot.adapters.cqhttp import MessageSegment, Message, permission, GroupMessageEvent
from nonebot import on_command, on_message
from nonebot.adapters.onebot.v11 import MessageSegment, Message, permission, GroupMessageEvent
from nonebot.rule import keyword, startswith
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
Expand All @@ -11,8 +11,9 @@
status = {}

can = on_message(rule=startswith('牛牛涩涩'),
priority=10,
permission=permission.GROUP)
priority=10,
permission=permission.GROUP)


@can.handle()
async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_State):
Expand All @@ -23,15 +24,16 @@ async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_Stat
return False
can.block = True
url = f'https://www.pixiv.net/artworks/{p.id}'
msg: Message = MessageSegment.text(url) + MessageSegment.image(file=p.pic)
msg: Message = MessageSegment.text(
url) + MessageSegment.image(file=p.pic)
await can.finish(msg)
else:
can.block = False


tags = on_message(rule=startswith('牛牛我要看'),
priority=10,
permission=permission.GROUP)
priority=10,
permission=permission.GROUP)


@tags.handle()
Expand All @@ -49,7 +51,8 @@ async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_Stat
await tags.finish("呃......咳嗯,下次不能喝、喝这么多了......呀,博士。你今天走起路来,怎么看着摇摇晃晃的?")
return
url = f'https://www.pixiv.net/artworks/{p.id}'
msg: Message = MessageSegment.text(url) + MessageSegment.image(file=p.pic)
msg: Message = MessageSegment.text(
url) + MessageSegment.image(file=p.pic)
await tags.finish(msg)
else:
await tags.finish("听啊,悲鸣停止了。这是幸福的和平到来前的宁静。")
Expand All @@ -58,8 +61,8 @@ async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_Stat


cannot = on_message(rule=startswith('牛牛涩涩'),
priority=17,
permission=permission.GROUP)
priority=17,
permission=permission.GROUP)


@cannot.handle()
Expand All @@ -73,11 +76,12 @@ async def handle_first_receive(bot: Bot, event: GroupMessageEvent, state: T_Stat
status = {}

switch = on_message(
rule=keyword("牛牛可以涩涩", "牛牛不可以涩涩"),
rule=keyword("牛牛可以涩涩", "牛牛不可以涩涩"),
block=True,
priority=5,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER)


@switch.handle()
async def sw(bot: Bot, event: GroupMessageEvent, state: T_State):
s = event.get_plaintext()
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0091d18

Please sign in to comment.