Taosky/telegram-search-bot

历史记录导入问题

deskmonster opened this issue · 7 comments

if 'user' not in message['from_id']:

这里遍历messages后检测 user是否在'from_id'中,但是有些特殊事件(比如加群,退群)是没有'from_id'的而是'actor_id',遍历到这种字段会直接报错:

  {
   "id": -000000,
   "type": "service",
   "date": "2022-04-29T21:21:41",
   "actor": "测试号",
   "actor_id": "user5555",
   "action": "join_group_by_link",
   "inviter": "Group",
   "text": ""
  }
[2022-06-15 03:53:09,020] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "web_manager.py", line 92, in upload_file
    success_count, fail_count, fail_messages = insert_messages(history_json['id'],history_json['messages'])
  File "web_manager.py", line 37, in insert_messages
    if 'user' not in message['from_id']:
KeyError: 'from_id'
192.168.208.1 - - [15/Jun/2022 03:53:09] "POST / HTTP/1.1" 500 -

解决方案:
写一个try或者先判断'from_id'是否在字段里:

    if 'from_id' not in message :
        continue
    elif 'user' not in message ['from_id']:
        continue

另外bot自己记录的chat的id是-100xxxx
导入的chatid是xxxxx
好像也会导致无法搜索

解决方案:
导入的时候给加上-100?

chat id应该是唯一的吧,导入的id和实际的不一致吗?

chat id应该是唯一的吧,导入的id和实际的不一致吗?

导入的chat_id 是 123456789
然后bot记录的消息的chat_id 是 -100123456789
数据库里体现如下:
图片

chat id应该是唯一的吧,导入的id和实际的不一致吗?

导入的chat_id 是 123456789 然后bot记录的消息的chat_id 是 -100123456789 数据库里体现如下: 图片

确实是,可能是因为变成supergroup,chat id会多个-100,导出还是原来的chat id。这几个问题已经提交了修复,你试下,因为数据表变了,之前的记录要重新导入。

new_chat = Chat(id=chat_id, title=title, enable=False)

这里 new chat 的chat id 还是没有修改..
另外这里似乎有两个一样的判断

new_chat = Chat(id=chat_id, title=title, enable=False)

这里 new chat 的chat id 还是没有修改..
另外这里似乎有两个一样的判断

修改了,判断是不是小于0,不是的话就加上-100

测试可用