UrekD / Telegram-To-Discord

Mirror all messages from Telegram channels to Discord via a webhook also translate any message that is not in English.
50 stars 12 forks source link

Hangs after some minutes of inactivity #2

Closed Slona closed 1 year ago

Slona commented 1 year ago

Bot is starting with no issues and works as intended, but after some time (minute or 2-3) stops doing anything. And there is nothing in console.

UrekD commented 1 year ago

Hello,

Will check on it. Could you provide more details about your environment such as OS, Python version and installed package.

Slona commented 1 year ago

Its Ubuntu 20.04.5 LTS, Python 3.8.10. Packages were installed via requirements.txt

Slona commented 1 year ago

image

UrekD commented 1 year ago

image

Would you be able to upgrade to 3.10 or later? As I suspect your outdated python version is the issue, as the bot was designed with at least 3.10 in mind due to changes in Python features. If it would be easier you can also run the bot in a docker container for which I can give you the build file or push an image.

Slona commented 1 year ago

My Ubuntu only wants to work with 3.8 version. When i install 3.10 up ahead, it looses all modules (including pip). And if i install them again, they roll back python to 3.8. I dunno how to fix that So probably docker will be easiest solution

UrekD commented 1 year ago

My Ubuntu only wants to work with 3.8 version. When i install 3.10 up ahead, it looses all modules (including pip). And if i install them again, they roll back python to 3.8. I dunno how to fix that So probably docker will be easiest solution

After installing a new version of Python you must specify it to the system as the primary/priority version or might use the old one still. Either way I will push a docker image when able.

Slona commented 1 year ago

Yeah, i tried to do this via sudo update-alternatives --config python3 and choosing 3.10 version. But packages are still "linked" to 3.8 version and though --version shows that current version is 3.10, running python3 main,py says there are no required packages installed (e.g. telethon)

So i will wait for docker, thank you!

Slona commented 1 year ago

I also let the script run this time after it stops and after some time it has given me a message

Getting difference for channel updates 1882573479 caused AuthKeyUnregisteredError; ending getting difference prematurely until server issues are resolved

UrekD commented 1 year ago

Eh the pipeline isn't happy for what ever reason, pull the new changes and build and image on your own machine then run that in docker. You can find an example how to pass env's with compose in my other repo, building the image I believe is achieved with "docker build -t TelegramBot .

Slona commented 1 year ago

Do you know how to automate entering Telegram bot ID at the start of the script? It asks every time i run it

BTW i have succeeded with installing python 3.10 and that didnt help. Trying to build docker

Slona commented 1 year ago

image

Yeah, this cant be run in container, because it asks for TG bot ID

Slona commented 1 year ago

⠿ Container tgdc-bot1-1 Created 0.1s Attaching to tgdc-bot1-1 tgdc-bot1-1 | Traceback (most recent call last): tgdc-bot1-1 | File "//main.py", line 135, in tgdc-bot1-1 | start() tgdc-bot1-1 | File "//main.py", line 48, in start tgdc-bot1-1 | client.start() tgdc-bot1-1 | File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 134, in start tgdc-bot1-1 | else self.loop.run_until_complete(coro) tgdc-bot1-1 | File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete tgdc-bot1-1 | return future.result() tgdc-bot1-1 | File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 171, in _start tgdc-bot1-1 | value = phone() tgdc-bot1-1 | File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 22, in tgdc-bot1-1 | phone: typing.Callable[[], str] = lambda: input('Please enter your phone (or bot token): '), tgdc-bot1-1 | EOFError: EOF when reading a line tgdc-bot1-1 exited with code 139

I used python 3.10 instead 3.11 as in your Dockerfile

UrekD commented 1 year ago

image

Yeah, this cant be run in container, because it asks for TG bot ID

Have you passed the required env vars to the container? If it asks for input run it in interactive mode. I just got to my PC so I'll boot up a fresh Ubuntu VM and test myself in a few.

Slona commented 1 year ago

image Yeah, this cant be run in container, because it asks for TG bot ID

Have you passed the required env vars to the container? If it asks for input run it in interactive mode. I just got to my PC so I'll boot up a fresh Ubuntu VM and test myself in a few.

Yes, all ENVs were passed, after some lessons i was able to do it in right way :) But TG bot ID is asked separately after script is run, so i was not able to pass it

Slona commented 1 year ago

_FROM python:3.10 WORKDIR / ENV WEBHOOK='https://discord.com/api/webhooks/XXXX' ENV APPID="XXXXXX" ENV APIHASH="XXXXXXXXXXX" ENV APINAME="TGDC" ENV DLLOC='/home/slona/temp' ENV INPUTCHANNELS=-1001882573479 COPY . . RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 RUN python3.10 -m pip install -r requirements.txt CMD ["python","-u","main.py"]

Here are contents of Dockerfile. Then i have used sudo docker compose up and after all downloads got the error i posted before. I tried to add one more line with _CMD ["TG_BOTID"], but that also havent worked

UrekD commented 1 year ago

_FROM python:3.10 WORKDIR / ENV WEBHOOK='https://discord.com/api/webhooks/XXXX' ENV APPID="XXXXXX" ENV APIHASH="XXXXXXXXXXX" ENV APINAME="TGDC" ENV DLLOC='/home/slona/temp' ENV INPUTCHANNELS=-1001882573479 COPY . . RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 RUN python3.10 -m pip install -r requirements.txt CMD ["python","-u","main.py"]

Here are contents of Dockerfile. Then i have used sudo docker compose up and after all downloads got the error i posted before. I tried to add one more line with _CMD ["TG_BOTID"], but that also havent worked

Hmm can't really say about passing ENV in Dockerfile never done it I was speaking of in either compose file or docker run command. RUN curl is that needed the python image should have pip by default.

Slona commented 1 year ago

RUN curl is that needed the python image should have pip by default.

It was needed when not using docker to install pip for 3.10 Removed it now, result id the same Also changed python in docker to 3.11

Slona commented 1 year ago

Hmm can't really say about passing ENV in Dockerfile never done it I was speaking of in either compose file or docker run command.

Ah, i understood what you mean. Okay, i have reverted Dockerfile to the one you provided here and changed docker-compose.yml using ENVs. The error now is totally the same i posted before:

tgdcbot | Traceback (most recent call last): tgdcbot | File "//main.py", line 135, in tgdcbot | start() tgdcbot | File "//main.py", line 48, in start tgdcbot | client.start() tgdcbot | File "/usr/local/lib/python3.11/site-packages/telethon/client/auth.py", line 134, in start tgdcbot | else self.loop.run_until_complete(coro) tgdcbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tgdcbot | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete tgdcbot | return future.result() tgdcbot | ^^^^^^^^^^^^^^^ tgdcbot | File "/usr/local/lib/python3.11/site-packages/telethon/client/auth.py", line 171, in _start tgdcbot | value = phone() tgdcbot | ^^^^^^^ tgdcbot | File "/usr/local/lib/python3.11/site-packages/telethon/client/auth.py", line 22, in tgdcbot | phone: typing.Callable[[], str] = lambda: input('Please enter your phone (or bot token): '), tgdcbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tgdcbot | EOFError: EOF when reading a line tgdcbot exited with code 139

UrekD commented 1 year ago

Yeah docker idk how or if it will work, not gonna pursue that. I tested on a fresh instance of ubuntu-22.04.1-live-server-amd64.iso with minimal install and it worked fine on python 3.10.6 and in 20 minutes did not stall. Suggest you try a new machine/VM or another network.

Slona commented 1 year ago

Okay, will do a fresh install and try. Will return after test )

Slona commented 1 year ago

Ha, seems that i have found and solved the issue. For auth i have used the bot, which was already used with another webhook. Seems that after some time it was starting to conflict. So i have regged a brand new one TG bot and used it for auth. Currently running 10 minutes with no stall. Gonna test it for a few hours more, but think that it will continue to work.

Anyway, do you know any way to pass TG bot ID to script as argument without need to enter it every time i run script? So i can put it into autostart and forget?

UrekD commented 1 year ago

Glad to see you resolved it :)

As for TG bot ID, I guess that's from having multiple bots which I haven't ever faced as I only have 1, so no clue. For me it only asks the login code on first run.

ManeFunction commented 1 year ago

I have only one bot either, but still asked every time for bot ID. Or the phone, but I don't want to get random script from the internet full access to my TG account so phone is not an option.

UrekD commented 1 year ago

I have only one bot either, but still asked every time for bot ID. Or the phone, but I don't want to get random script from the internet full access to my TG account so phone is not an option.

A credentials file should be created after you first login, could be missing permissions if it doesn't. It's been a long time since I actually used it so things could have changed, but only needed to login once unless that cache was deleted.

If you're referring to my script, its open source and short so you can verify yourself that it's not malicious or to add your own solutions, reverse engineer etc.