wechaty / python-wechaty

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
https://wechaty.readthedocs.io/zh_CN/latest/
Apache License 2.0
1.62k stars 235 forks source link

🐛🐛 Bug Report: The robot can't send a GIF correctly #254

Open AP-Kai opened 3 years ago

AP-Kai commented 3 years ago

Important:Please file the issue follow the template, or we won't be able to help you to solve the problem.

1. Versions

What is your wechaty version?

Answer:

wechaty-version

What os are you using

Answer:

Windows 10

2. Describe the bug

I find a bug when I want to send a GIF by wechaty-python, each time I want to send a GIF(about 30KB) by

async def on_message(msg: Message):
    if msg.text() == 'ding':
        file_box = FileBox.from_file('./1.gif')
        await msg.say(file_box)

The robot only send me a GIF what I had never used before like this:

QQ截图20210825233340

The GIF what I want is another one.

Besides, when the robot try to send a big GIF(about 20MB), it do nothing.

3. To Reproduce

This part is very important: if you can not provide any reproduce steps, then the problem will be very hard to be recognized.

How to create a Minimal, Reproducible Example

Steps to reproduce the behavior:

  1. just run the code
    
    import os
    import asyncio
    from wechaty import (
    Contact,
    FileBox,
    Message,
    Wechaty,
    ScanStatus,
    )

os.environ['WECHATY_PUPPET'] = "wechaty-puppet-service" os.environ['WECHATY_PUPPET_SERVICE_TOKEN'] = "" # 这里填Wechaty token os.environ['CUDA_VISIBLE_DEVICES'] = "0"

async def on_message(msg: Message): if msg.text() == 'ding': file_box = FileBox.from_file('./1.gif') await msg.say(file_box)

async def on_scan( qrcode: str, status: ScanStatus, _data, ): print('Status: ' + str(status)) print('View QR Code Online: https://wechaty.js.org/qrcode/' + qrcode)

async def on_login(user: Contact): print(user)

async def main():

确保我们在环境变量中设置了WECHATY_PUPPET_SERVICE_TOKEN

if 'WECHATY_PUPPET_SERVICE_TOKEN' not in os.environ:
    print('''
        Error: WECHATY_PUPPET_SERVICE_TOKEN is not found in the environment variables
        You need a TOKEN to run the Python Wechaty. Please goto our README for details
        https://github.com/wechaty/python-wechaty-getting-started/#wechaty_puppet_service_token
    ''')

bot = Wechaty()

bot.on('scan', on_scan)
bot.on('login', on_login)
bot.on('message', on_message)

await bot.start()

print('[Python Wechaty] Ding Dong Bot started.')

asyncio.run(main())



## 4. Expected behavior

> Give a clear and concise description of what you expected to happen.

I can receive a GIF what I want.

## 5. Actual behavior

> If applicable, add screenshots to help explain your problem. But do not paste log screenshots here.

Actually,I received a GIF "大盆哥哥,生日快乐"
wj-Mcat commented 3 years ago

Unfortunately, there are some problems sending GIF pictures. Here is my simple code which should be right.

import asyncio
from wechaty import Wechaty, Message, FileBox

class Bot(Wechaty):
    async def on_message(self, message: Message):
        text = message.text()
        if not text.startswith('image'):
            return
        index = int(text.split()[1])
        image_file = f'./examples/image-{index}.gif'
        file_box: FileBox = FileBox.from_file(image_file)

        talker = message.talker()
        room = message.room()

        conversation = room if room else talker
        await conversation.say(file_box)

async def main():
    bot = Bot()
    await bot.start()

asyncio.run(main())

Please keep eyes on this issue, which I will track on. Thanks for your issue.

AP-Kai commented 3 years ago

Unfortunately, there are some problems sending GIF pictures. Here is my simple code which should be right.

import asyncio
from wechaty import Wechaty, Message, FileBox

class Bot(Wechaty):
    async def on_message(self, message: Message):
        text = message.text()
        if not text.startswith('image'):
            return
        index = int(text.split()[1])
        image_file = f'./examples/image-{index}.gif'
        file_box: FileBox = FileBox.from_file(image_file)

        talker = message.talker()
        room = message.room()

        conversation = room if room else talker
        await conversation.say(file_box)

async def main():
    bot = Bot()
    await bot.start()

asyncio.run(main())

Please keep eyes on this issue, which I will track on. Thanks for your issue.

I tried your method, but it doesn't run correctly. I still got a GIF "生日快乐".

wj-Mcat commented 3 years ago

Yes,my goal is to run the above code correctly. If you are interested at it, you can have a try to solve this bug.

wj-Mcat commented 3 years ago

I'm sorry to tell you that wechaty can't send gif image file beacuase of some wechaty structure reasons, and there will be some changes in sending file implementation. please refer to : https://github.com/wechaty/python-wechaty-puppet-service/pull/64#issuecomment-911103851

Please keep eyes on this issue to get latest progress of this problem.