aahnik / tgcf

The ultimate tool to automate custom telegram message forwarding. Live-syncer, Auto-poster, backup-bot, cloner, chat-forwarder, duplicator, ... Call it whatever you like! tgcf can fulfill your custom needs.
https://github.com/aahnik/tgcf/wiki
MIT License
1.38k stars 811 forks source link

I can not run the bot when TGCF_MODE is set to live (Heroku) #360

Closed abdoo9 closed 2 years ago

abdoo9 commented 2 years ago

Describe the bug the bot runs witout problems when TGCF_MODE=past but when I set it to live I got these error

2022-10-14T23:07:24.772959+00:00 app[worker.1]:                     INFO     Added event handler for edited          live.py:130
2022-10-14T23:07:24.774742+00:00 app[worker.1]:                     INFO     Added event handler for start           live.py:130
2022-10-14T23:07:24.776423+00:00 app[worker.1]:                     INFO     Added event handler for forward         live.py:130
2022-10-14T23:07:24.778316+00:00 app[worker.1]:                     INFO     Added event handler for remove          live.py:130
2022-10-14T23:07:24.780086+00:00 app[worker.1]:                     INFO     Added event handler for style           live.py:130
2022-10-14T23:07:24.781808+00:00 app[worker.1]:                     INFO     Added event handler for help            live.py:130
2022-10-14T23:07:26.212901+00:00 heroku[worker.1]: Process exited with status 1
2022-10-14T23:07:25.851108+00:00 app[worker.1]: ╭───────────────────── Traceback (most recent call last) ──────────────────────╮
2022-10-14T23:07:25.851125+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851125+00:00 app[worker.1]: │ /venv/bin/tgcf:8 in <module>                                                 │
2022-10-14T23:07:25.851126+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851126+00:00 app[worker.1]: │   5 from tgcf.cli import app                                                 │
2022-10-14T23:07:25.851126+00:00 app[worker.1]: │   6 if __name__ == '__main__':                                               │
2022-10-14T23:07:25.851127+00:00 app[worker.1]: │   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])     │
2022-10-14T23:07:25.851127+00:00 app[worker.1]: │ ❱ 8 │   sys.exit(app())                                                      │
2022-10-14T23:07:25.851127+00:00 app[worker.1]: │   9                                                                          │
2022-10-14T23:07:25.851128+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/typer/main.py:214 in __call__              │
2022-10-14T23:07:25.851128+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851128+00:00 app[worker.1]: │   211 │   │   )                                                              │
2022-10-14T23:07:25.851129+00:00 app[worker.1]: │   212 │                                                                      │
2022-10-14T23:07:25.851129+00:00 app[worker.1]: │   213 │   def __call__(self, *args: Any, **kwargs: Any) -> Any:              │
2022-10-14T23:07:25.851130+00:00 app[worker.1]: │ ❱ 214 │   │   return get_command(self)(*args, **kwargs)                      │
2022-10-14T23:07:25.851130+00:00 app[worker.1]: │   215                                                                        │
2022-10-14T23:07:25.851130+00:00 app[worker.1]: │   216                                                                        │
2022-10-14T23:07:25.851130+00:00 app[worker.1]: │   217 def get_group(typer_instance: Typer) -> click.Command:                 │
2022-10-14T23:07:25.851130+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851131+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/click/core.py:829 in __call__              │
2022-10-14T23:07:25.851131+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851132+00:00 app[worker.1]: │    826 │                                                                     │
2022-10-14T23:07:25.851149+00:00 app[worker.1]: │    827 │   def __call__(self, *args, **kwargs):                              │
2022-10-14T23:07:25.851150+00:00 app[worker.1]: │    828 │   │   """Alias for :meth:`main`."""                                 │
2022-10-14T23:07:25.851150+00:00 app[worker.1]: │ ❱  829 │   │   return self.main(*args, **kwargs)                             │
2022-10-14T23:07:25.851150+00:00 app[worker.1]: │    830                                                                       │
2022-10-14T23:07:25.851151+00:00 app[worker.1]: │    831                                                                       │
2022-10-14T23:07:25.851151+00:00 app[worker.1]: │    832 class Command(BaseCommand):                                           │
2022-10-14T23:07:25.851151+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851151+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/click/core.py:782 in main                  │
2022-10-14T23:07:25.851151+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851152+00:00 app[worker.1]: │    779 │   │   try:                                                          │
2022-10-14T23:07:25.851152+00:00 app[worker.1]: │    780 │   │   │   try:                                                      │
2022-10-14T23:07:25.851152+00:00 app[worker.1]: │    781 │   │   │   │   with self.make_context(prog_name, args, **extra) as c │
2022-10-14T23:07:25.851153+00:00 app[worker.1]: │ ❱  782 │   │   │   │   │   rv = self.invoke(ctx)                             │
2022-10-14T23:07:25.851153+00:00 app[worker.1]: │    783 │   │   │   │   │   if not standalone_mode:                           │
2022-10-14T23:07:25.851153+00:00 app[worker.1]: │    784 │   │   │   │   │   │   return rv                                     │
2022-10-14T23:07:25.851153+00:00 app[worker.1]: │    785 │   │   │   │   │   # it's not safe to `ctx.exit(rv)` here!           │
2022-10-14T23:07:25.851154+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851154+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/click/core.py:1066 in invoke               │
2022-10-14T23:07:25.851154+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851154+00:00 app[worker.1]: │   1063 │   │   """                                                           │
2022-10-14T23:07:25.851155+00:00 app[worker.1]: │   1064 │   │   _maybe_show_deprecated_notice(self)                           │
2022-10-14T23:07:25.851155+00:00 app[worker.1]: │   1065 │   │   if self.callback is not None:                                 │
2022-10-14T23:07:25.851155+00:00 app[worker.1]: │ ❱ 1066 │   │   │   return ctx.invoke(self.callback, **ctx.params)            │
2022-10-14T23:07:25.851160+00:00 app[worker.1]: │   1067                                                                       │
2022-10-14T23:07:25.851160+00:00 app[worker.1]: │   1068                                                                       │
2022-10-14T23:07:25.851161+00:00 app[worker.1]: │   1069 class MultiCommand(Command):                                          │
2022-10-14T23:07:25.851161+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851161+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/click/core.py:610 in invoke                │
2022-10-14T23:07:25.851197+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851197+00:00 app[worker.1]: │    607 │   │   args = args[2:]                                               │
2022-10-14T23:07:25.851198+00:00 app[worker.1]: │    608 │   │   with augment_usage_errors(self):                              │
2022-10-14T23:07:25.851198+00:00 app[worker.1]: │    609 │   │   │   with ctx:                                                 │
2022-10-14T23:07:25.851199+00:00 app[worker.1]: │ ❱  610 │   │   │   │   return callback(*args, **kwargs)                      │
2022-10-14T23:07:25.851199+00:00 app[worker.1]: │    611 │                                                                     │
2022-10-14T23:07:25.851199+00:00 app[worker.1]: │    612 │   def forward(*args, **kwargs):  # noqa: B902                       │
2022-10-14T23:07:25.851199+00:00 app[worker.1]: │    613 │   │   """Similar to :meth:`invoke` but fills in default keyword     │
2022-10-14T23:07:25.851200+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851200+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/typer/main.py:497 in wrapper               │
2022-10-14T23:07:25.851203+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851203+00:00 app[worker.1]: │   494 │   │   │   │   use_params[k] = v                                      │
2022-10-14T23:07:25.851204+00:00 app[worker.1]: │   495 │   │   if context_param_name:                                         │
2022-10-14T23:07:25.851204+00:00 app[worker.1]: │   496 │   │   │   use_params[context_param_name] = click.get_current_context │
2022-10-14T23:07:25.851204+00:00 app[worker.1]: │ ❱ 497 │   │   return callback(**use_params)  # type: ignore                  │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │   498 │                                                                      │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │   499 │   update_wrapper(wrapper, callback)                                  │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │   500 │   return wrapper                                                     │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/tgcf/cli.py:139 in main                    │
2022-10-14T23:07:25.851205+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851206+00:00 app[worker.1]: │   136 │   else:                                                              │
2022-10-14T23:07:25.851206+00:00 app[worker.1]: │   137 │   │   from tgcf.live import start_sync  # pylint: disable=import-out │
2022-10-14T23:07:25.851206+00:00 app[worker.1]: │   138 │   │                                                                  │
2022-10-14T23:07:25.851206+00:00 app[worker.1]: │ ❱ 139 │   │   asyncio.run(start_sync())                                      │
2022-10-14T23:07:25.851206+00:00 app[worker.1]: │   140                                                                        │
2022-10-14T23:07:25.851207+00:00 app[worker.1]: │   141                                                                        │
2022-10-14T23:07:25.851207+00:00 app[worker.1]: │   142 # AAHNIK 2021                                                          │
2022-10-14T23:07:25.851207+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851207+00:00 app[worker.1]: │ /usr/local/lib/python3.9/asyncio/runners.py:44 in run                        │
2022-10-14T23:07:25.851208+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851208+00:00 app[worker.1]: │   41 │   │   events.set_event_loop(loop)                                     │
2022-10-14T23:07:25.851208+00:00 app[worker.1]: │   42 │   │   if debug is not None:                                           │
2022-10-14T23:07:25.851208+00:00 app[worker.1]: │   43 │   │   │   loop.set_debug(debug)                                       │
2022-10-14T23:07:25.851209+00:00 app[worker.1]: │ ❱ 44 │   │   return loop.run_until_complete(main)                            │
2022-10-14T23:07:25.851209+00:00 app[worker.1]: │   45 │   finally:                                                            │
2022-10-14T23:07:25.851209+00:00 app[worker.1]: │   46 │   │   try:                                                            │
2022-10-14T23:07:25.851209+00:00 app[worker.1]: │   47 │   │   │   _cancel_all_tasks(loop)                                     │
2022-10-14T23:07:25.851209+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851210+00:00 app[worker.1]: │ /usr/local/lib/python3.9/asyncio/base_events.py:647 in run_until_complete    │
2022-10-14T23:07:25.851210+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851214+00:00 app[worker.1]: │    644 │   │   if not future.done():                                         │
2022-10-14T23:07:25.851214+00:00 app[worker.1]: │    645 │   │   │   raise RuntimeError('Event loop stopped before Future comp │
2022-10-14T23:07:25.851214+00:00 app[worker.1]: │    646 │   │                                                                 │
2022-10-14T23:07:25.851215+00:00 app[worker.1]: │ ❱  647 │   │   return future.result()                                        │
2022-10-14T23:07:25.851215+00:00 app[worker.1]: │    648 │                                                                     │
2022-10-14T23:07:25.851215+00:00 app[worker.1]: │    649 │   def stop(self):                                                   │
2022-10-14T23:07:25.851215+00:00 app[worker.1]: │    650 │   │   """Stop running the event loop.                               │
2022-10-14T23:07:25.851216+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851216+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/tgcf/live.py:133 in start_sync             │
2022-10-14T23:07:25.851216+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851216+00:00 app[worker.1]: │   130 │   │   logging.info(f"Added event handler for {key}")                 │
2022-10-14T23:07:25.851217+00:00 app[worker.1]: │   131 │                                                                      │
2022-10-14T23:07:25.851218+00:00 app[worker.1]: │   132 │   if config.is_bot and const.REGISTER_COMMANDS:                      │
2022-10-14T23:07:25.851218+00:00 app[worker.1]: │ ❱ 133 │   │   await client(                                                  │
2022-10-14T23:07:25.851218+00:00 app[worker.1]: │   134 │   │   │   functions.bots.SetBotCommandsRequest(                      │
2022-10-14T23:07:25.851218+00:00 app[worker.1]: │   135 │   │   │   │   commands=[                                             │
2022-10-14T23:07:25.851219+00:00 app[worker.1]: │   136 │   │   │   │   │   types.BotCommand(command=key, description=value)   │
2022-10-14T23:07:25.851219+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851219+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/telethon/client/users.py:30 in __call__    │
2022-10-14T23:07:25.851219+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851219+00:00 app[worker.1]: │    27                                                                        │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │    28 class UserMethods:                                                     │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │    29 │   async def __call__(self: 'TelegramClient', request, ordered=False) │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │ ❱  30 │   │   return await self._call(self._sender, request, ordered=ordered │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │    31 │                                                                      │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │    32 │   async def _call(self: 'TelegramClient', sender, request, ordered=F │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │    33 │   │   requests = (request if utils.is_list_like(request) else (reque │
2022-10-14T23:07:25.851220+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851221+00:00 app[worker.1]: │ /venv/lib/python3.9/site-packages/telethon/client/users.py:79 in _call       │
2022-10-14T23:07:25.851221+00:00 app[worker.1]: │                                                                              │
2022-10-14T23:07:25.851221+00:00 app[worker.1]: │    76 │   │   │   │   │   else:                                              │
2022-10-14T23:07:25.851221+00:00 app[worker.1]: │    77 │   │   │   │   │   │   return results                                 │
2022-10-14T23:07:25.851222+00:00 app[worker.1]: │    78 │   │   │   │   else:                                                  │
2022-10-14T23:07:25.851222+00:00 app[worker.1]: │ ❱  79 │   │   │   │   │   result = await future                              │
2022-10-14T23:07:25.851222+00:00 app[worker.1]: │    80 │   │   │   │   │   self.session.process_entities(result)              │
2022-10-14T23:07:25.851222+00:00 app[worker.1]: │    81 │   │   │   │   │   self._entity_cache.add(result)                     │
2022-10-14T23:07:25.851223+00:00 app[worker.1]: │    82 │   │   │   │   │   return result                                      │
2022-10-14T23:07:25.851223+00:00 app[worker.1]: ╰──────────────────────────────────────────────────────────────────────────────╯
2022-10-14T23:07:25.851224+00:00 app[worker.1]: UserBotRequiredError: This method can only be called by a bot (caused by 
2022-10-14T23:07:25.851225+00:00 app[worker.1]: SetBotCommandsRequest)
2022-10-14T23:07:26.284482+00:00 heroku[worker.1]: State changed from up to crashed

To Reproduce using the deploy button for heroku with TGCF_CONFIG is

admins: [abdood]
# when tgcf is run in live mode, the admins can run commands to change the configuration

forwards:
  - source: ewewewewewewewewe
    dest: [-1001762583348]

#  - source: channelName
#    dest: [anotherChannel,https://t.me/channelLink]

#  - source: channelName
#    dest: [anotherChannel,https://t.me/channelLink]

show_forwarded_from: false

live:
  delete_sync: false
#past:
#    delay: 5

when I set TGCF_MODE to live it works normally

jamregistr commented 2 years ago

I got the same problem on live mode also. Has anyone found a fix? :)

aahnik commented 2 years ago

new version will have a web interface. launching soon. new version will fix all these issues