tgbridge: rework both directions — avatars, stickers, replies, edits
fixes that were dropping messages: - d->tg sent parse_mode=Markdown with an unescaped body, so any message with a stray * _ ` or [ got a 400 from telegram and vanished. now html with proper escaping + a plain-text retry - no allowed_mentions on webhook posts, so telegram could @everyone - forwarder.start() ran from on_ready, which fires again on every gateway reconnect -> second poller on the same token -> 409s and dupes - document.mime_type is nullable and was called directly - sticker finally block hit UnboundLocalError when mkstemp raised - ffmpeg timeouts leaked temp files and orphaned the process stickers, per format instead of one blanket gif convert: - static .webp now passes through (the gif convert crushed 228 alpha levels to 2 and made the file 4x bigger) - video .webm -> animated webp, keeps 8-bit alpha, ~7x smaller than gif. needs -c:v libvpx-vp9 before -i or ffmpeg silently drops the alpha - .tgs is gzipped lottie, ffmpeg exits 183 on it and we were uploading the raw file. renders via optional lottie lib, else thumbnail + emoji added: telegram profile photos as webhook avatars (re-hosted in a private channel, AVATAR_CACHE_CHANNEL_ID), reply threading both ways, edit sync both ways, delete sync d->tg, album batching, voice/poll/location/contact/ dice/forward attribution, utf-16-safe entity conversion, mention and custom emoji resolution, message splitting instead of truncation, shared aiohttp session with 429 backoff, route discovery from env, !bridge status main.py just loads the extension now; routes come from credentials.env Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RXrxDFpyq3VjvxWGuW3CZe
This commit is contained in:
1 parent
f6ba74394f
commit
eac6dbda3a
12 files changed
+2325
-307
No files matched your search
@@ -5,9 +5,6 @@ import os
|
||||
import logging
|
||||
import asyncio
|
||||
|
||||
from tgbridge.forwarder import TelegramForwarder
|
||||
from tgbridge.discord_to_telegram import DiscordToTelegramForwarder
|
||||
|
||||
# from twitterbridge.rss import TwitterRSSForwarder
|
||||
|
||||
load_dotenv('credentials.env')
|
||||
@@ -18,19 +15,8 @@ intents.members = True
|
||||
|
||||
bot = commands.Bot(command_prefix='!', intents=intents, help_command=None)
|
||||
|
||||
# Telegram → Discord
|
||||
forwarder = TelegramForwarder(token=os.getenv('TELEGRAM_BOT_TOKEN'))
|
||||
if os.getenv('TELEGRAM_GROUP_ID') and os.getenv('DISCORD_WEBHOOK_URL'):
|
||||
forwarder.add_route(int(os.getenv('TELEGRAM_GROUP_ID')), os.getenv('DISCORD_WEBHOOK_URL'))
|
||||
if os.getenv('TELEGRAM_GROUP_ID_SHITPOST') and os.getenv('DISCORD_WEBHOOK_URL_SHITPOST'):
|
||||
forwarder.add_route(int(os.getenv('TELEGRAM_GROUP_ID_SHITPOST')), os.getenv('DISCORD_WEBHOOK_URL_SHITPOST'))
|
||||
|
||||
# Discord → Telegram (reverse bridge)
|
||||
d_to_tg = DiscordToTelegramForwarder(bot=bot, tg_token=os.getenv('TELEGRAM_BOT_TOKEN'))
|
||||
if os.getenv('DISCORD_CHANNEL_ID') and os.getenv('TELEGRAM_GROUP_ID'):
|
||||
d_to_tg.add_route(int(os.getenv('DISCORD_CHANNEL_ID')), int(os.getenv('TELEGRAM_GROUP_ID')))
|
||||
if os.getenv('DISCORD_CHANNEL_ID_SHITPOST') and os.getenv('TELEGRAM_GROUP_ID_SHITPOST'):
|
||||
d_to_tg.add_route(int(os.getenv('DISCORD_CHANNEL_ID_SHITPOST')), int(os.getenv('TELEGRAM_GROUP_ID_SHITPOST')))
|
||||
# The Telegram bridge discovers its own routes from credentials.env and
|
||||
# starts polling when the extension loads — see tgbridge/config.py.
|
||||
|
||||
# twitter = TwitterRSSForwarder(
|
||||
# webhook_url=os.getenv('TWITTER_DISCORD_WEBHOOK'),
|
||||
@@ -44,7 +30,6 @@ if os.getenv('DISCORD_CHANNEL_ID_SHITPOST') and os.getenv('TELEGRAM_GROUP_ID_SHI
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'[+] {bot.user} is online!')
|
||||
asyncio.create_task(forwarder.start())
|
||||
# asyncio.create_task(twitter.start())
|
||||
# asyncio.create_task(twitter_mao.start())
|
||||
# Clear stale global slash commands
|
||||
@@ -55,7 +40,7 @@ async def on_ready():
|
||||
|
||||
async def main():
|
||||
async with bot:
|
||||
await bot.add_cog(d_to_tg)
|
||||
await bot.load_extension('tgbridge')
|
||||
await bot.load_extension('cogs.general')
|
||||
await bot.load_extension('cogs.chance')
|
||||
await bot.load_extension('cogs.gifs')
|
||||
@@ -80,7 +65,9 @@ async def main():
|
||||
try:
|
||||
await bot.start(os.getenv('DISCORD_TOKEN'))
|
||||
finally:
|
||||
await forwarder.stop()
|
||||
# bot.close() unloads extensions, so tgbridge.teardown stops the
|
||||
# Telegram poller and closes its aiohttp session for us
|
||||
pass
|
||||
# twitter.stop()
|
||||
# twitter_mao.stop()
|
||||
# await twitter.close()
|
||||
|
||||
Reference in new issue
Block a user