ssttkkl / PixivBot

集成插件nonebot-plugin-pixivbot的NoneBot实例的Docker镜像,适用于Docker方式部署。
MIT License
259 stars 16 forks source link

启动bot时报错 AttributeError: 'ApplicationLaunched' object has no attribute 'app' #9

Closed mtuba closed 3 years ago

mtuba commented 3 years ago

我的问题 运行 python3 bot.py 时报错AttributeError: 'ApplicationLaunched' object has no attribute 'app'

控制台完整输出

root@VM-0-12-ubuntu:~/PixivBot/PixivBot-0.2.0# python3 bot.py
2020-10-29 12:30:40.694 | INFO     | utils.settings:<module>:38 - Config file was loaded successfully.
2020-10-29 12:30:41.234 | INFO     | my_logger:info:7 - initializing app...
Traceback (most recent call last):
  File "bot.py", line 89, in <module>
    app.launch_blocking()
  File "/usr/local/lib/python3.8/dist-packages/graia/application/__init__.py", line 1076, in launch_blocking
    loop.run_until_complete(self.initialize())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/dist-packages/graia/application/__init__.py", line 997, in initialize
    self.broadcast.postEvent(ApplicationLaunched(self))
  File "/usr/local/lib/python3.8/dist-packages/graia/application/event/lifecycle.py", line 9, in __init__
    self.app = app
AttributeError: 'ApplicationLaunched' object has no attribute 'app'

我的思路 我猜想是

 File "/usr/local/lib/python3.8/dist-packages/graia/application/event/lifecycle.py", line 9, in __init__
    self.app = app

中传入的 ‘app’ 类型不正确,print(app) 看了一下,输出为: <graia.application.GraiaMiraiApplication object at 0x7f63a0b8b220> 似乎没有问题,有点束手无策

setting.template.json

{
  // 这部分是与 MiraiAPIHTTP 通信的参数
  "mirai": {
    "qq": 264****201,
    "host": "127.0.0.1",
    "auth_key": "114514810",
    "port": 8080,
    "enable_websocket": true
  },
  // 这部分是用于登入 pixiv 的账号密码
  "pixiv": {
    "username": "********@outlook.com",
    "password": "*********",
    "bypass": true, // 打开pixivpy自带的免代理访问支持
    "proxy": null // 为pixiv设置代理,如:"http://localhost:7890",不建议和bypass同时使用,null表示不设代理
  },
  // 这部分是监听的群组和好友,以及开启什么功能的配置
  "function": {
    "group": {
      "listen": null, // 若为null则监听所有群组,否则应为包含欲监听群组id的一个列表
      "ranking": true,
      "illust": true,
      "random_illust": true,
      "random_user_illust": true,
      "random_bookmark": false
    },
    "friend": {
      "listen": null, // 若为null则监听所有好友,否则应为包含欲监听好友id的一个列表
      "ranking": true,
      "illust": true,
      "random_illust": true,
      "random_user_illust": true,
      "random_bookmark": true
    }
  },
  // 这部分是查看排行榜的配置
  "ranking": {
    "trigger": { // 触发词,当消息中包含这些词语时就会触发
      "default": [
        "看看榜",
        "ランキングを見せてください"
      ],
      "day": [
        "看看日榜"
      ],
      "week": [
        "看看周榜"
      ],
      "month": [
        "看看月榜"
      ],
      "day_male": [
        "看看男性榜"
      ],
      "day_female": [
        "看看女性榜"
      ],
      "week_original": [
        "看看原创榜"
      ],
      "week_rookie": [
        "看看新人榜"
      ],
      "day_manga": [
        "看看漫画榜"
      ]
    },
    "default_ranking_mode": "day", // 默认查看的排行榜
    "default_range": "1-20", // 默认查看的排行榜范围
    "item_per_group_message": 50, // 每条群消息包含多少个插画(避免消息过长)
    "item_per_friend_message": 10, // 每条好友消息包含多少个插画(避免消息过长)
    "item_pattern": "#$rank $title (https://www.pixiv.net/artworks/$id)\n" // 每个插画的消息模板(仅支持$rank, $title, $id三个参数)
  },
  // 这部分是通过id查看插画的配置
  "illust": {
    "trigger": [
      "看看图",
      "イラストを見せてください"
    ], // 触发词
    "domain": null, // 反代使用的域名,若不希望使用反代则设为null
    "download_dir": "cache/illust_img", // 下载插画的目录
    "download_quantity": "original", // 下载插画的品质,可选值:original, medium, square_medium
    "download_outdated_time": 172800, // 自动清理下载目录时删除多久以前的文件(单位:秒),null表示无限期
    "download_timeout": 60,
    "download_timeout_message": "下载超时",
    "compress": true, // 是否要对图片进行压缩
    "compress_size": 1200, // 将图片的长或宽压缩至此处设定的数值,保持原有长宽比
    "compress_quantity": 75, // 压缩品质,0—100
    "reply_pattern": "「$title」\ntags: $tags\nhttps://www.pixiv.net/artworks/$id\n", // 回复消息的模板(仅支持$title, $tags, $id三个参数)
    "block_tags": [
      "R-18",
      "NSFW"
    ], // 当画像包含设定的标签时拦截
    "block_mode": "escape_img", // 拦截模式:"escape_img"不显示画像、"fully_block"不显示任何内容
    "block_message": "该画像因含有 %tag tag 而被自主规制" // 当被拦截时回复的消息,%tag指代被拦截的标签
  },
  // 这部分是搜索关键字随机抽选插画的配置
  "random_illust": {
    "trigger": [
      "来$number张$keyword图",
      "$keywordのイラスト$numberつをください"
    ], // 触发词的模板,其中$keyword指代关键字,$number指代数量
    "limit_per_query": 10, // 单次请求最大的图片数量
    "not_found_message": "别看了,没有的。", // 当搜索结果为空时回复的消息
    "overlimit_message": "别看那么多色图了。", // 当请求数量超过限制时回复的消息
    "random_method": "bookmark_proportion", // 抽选方法。"uniform"均匀分布、"bookmark_proportion"概率与书签数呈比例、"view_proportion"概率与浏览数呈比例、"time_proportion"概率与发布时间的时间差的负指数呈比例。
    "search_cache_dir": "cache/search_cache", // 搜索结果缓存的目录
    "search_cache_outdated_time": 7200, // 搜索结果缓存的时间(单位:秒),null表示无限期
    "search_item_limit": 500, // 一次搜索最多包含多少插画,null表示无上限(慎用)
    "search_page_limit": 30, // 一次搜索最多翻多少页,null表示无上限(慎用)
    "bookmark_lower_bound": 100, // 搜索结果只包含书签数不少于指定值的插画
    "view_lower_bound": 0, // 搜索结果只包含浏览数不少于指定值的插画
    "block_tags": [
      "R-18",
      "NSFW"
    ] // 搜索结果过滤掉包含设定的标签的画像
  },
  // 这部分是随机抽选书签插画的配置
  "random_bookmarks": {
    "trigger": [
      "来$number张私家车",
      "ブックマーク$numberつをください"
    ], // 触发词,其中$number指代数量
    "user_id": null, // 要查看书签的用户id,若为null则为登录用户的id
    "limit_per_query": 10, // 单次请求最大的图片数量
    "not_found_message": "别看了,没有的。", // 当搜索结果为空时回复的消息
    "overlimit_message": "别看那么多色图了。", // 当请求数量超过限制时回复的消息
    "random_method": "uniform", // 抽选方法。同上
    "search_cache_filename": "cache/bookmarks.json", // 搜索结果缓存的文件
    "search_cache_outdated_time": 7200, // 搜索结果缓存的时间,null表示无限期(单位:秒)
    "search_item_limit": 1000, // 一次搜索最多包含多少插画,null表示无上限(慎用)
    "search_page_limit": 50, // 一次搜索最多翻多少页,null表示无上限(慎用)
    "bookmark_lower_bound": 0, // 搜索结果只包含书签数不少于指定值的插画
    "view_lower_bound": 0, // 搜索结果只包含浏览数不少于指定值的插画
    "block_tags": [
      "R-18",
      "NSFW"
    ] // 过滤掉包含设定的标签的画像
  },
  "random_user_illust": {
    "trigger": [
      "来$number张$illustrator老师的作品",
      "$illustrator先生の作品$numberつをください"
    ], // 触发词的模板,其中$illustrator指代画师,$number指代数量
    "limit_per_query": 10, // 单次请求最大的图片数量
    "not_found_message": "别看了,没有的。", // 当搜索结果为空时回复的消息
    "overlimit_message": "别看那么多色图了。", // 当请求数量超过限制时回复的消息
    "random_method": "time_proportion", // 抽选方法。同上
    "search_cache_dir": "cache/illustrator_cache", // 搜索结果缓存的目录
    "search_cache_outdated_time": 7200, // 搜索结果缓存的时间,null表示无限期(单位:秒)
    "search_item_limit": null, // 一次搜索最多包含多少插画,null表示无上限(慎用)
    "search_page_limit": null, // 一次搜索最多翻多少页,null表示无上限(慎用)
    "bookmark_lower_bound": 0, // 搜索结果只包含书签数不少于指定值的插画
    "view_lower_bound": 0, // 搜索结果只包含浏览数不少于指定值的插画
    "block_tags": [
      "R-18",
      "NSFW"
    ] // 过滤掉包含设定的标签的画像
  }
}

MiraiApiHttp/setting.yml

## 该配置为全局配置,对所有Session有效

# 可选,默认值为0.0.0.0
host: '127.0.0.1'

# 可选,默认值为8080
port: 8080          

# 可选,默认由插件第一次启动时随机生成,建议手动指定
authKey: 114514810  

# 可选,缓存大小,默认4096.缓存过小会导致引用回复与撤回消息失败
cacheSize: 4096

# 可选,是否开启websocket,默认关闭,建议通过Session范围的配置设置
enableWebsocket: true

# 可选,配置CORS跨域,默认为*,即允许所有域名
cors: 
  - '*'

## 消息上报
report:
# 功能总开关
  enable: false
  # 群消息上报
  groupMessage:
    report: false
  # 好友消息上报
  friendMessage:
    report: false
  # 临时消息上报
  tempMessage:
    report: false
  # 事件上报
  eventMessage:
    report: false
  # 上报URL
  destinations: []
  # 上报时的额外Header
  extraHeaders: {}

## 心跳
heartbeat:
  # 功能总开关
  enable: false
  # 启动延迟
  delay: 1000
  # 心跳间隔
  period: 15000
  # 心跳上报URL
  destinations: []
  # 上报时的额外信息
  extraBody: {}
  # 上报时的额外头
  extraHeaders: {}
mtuba commented 3 years ago

问题已解决,参考 https://github.com/GraiaProject/Application/issues/51