twitterbridge: one poller, per-webhook seen sets, fxtwitter links, outage DM

The RSSHub feed isn't strictly chronological, so 'post everything above the
last guid' could skip tweets. Now a single poller fans out to both webhooks,
each remembering posted guids (data/twitter_seen.json, atomic writes): new
tweets anywhere above the oldest known one are posted oldest-first, old tweets
sliding in after a deletion are ignored, failed posts retry next poll and
Discord 429s are honoured. Links go out as fxtwitter.com for real embeds.
The owner gets a DM after 90 min of broken feed and again on recovery.
Night polling is now 1-2 h.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
esefandClaude Opus 5.5 committed 2026-10-06 21:09:44 +03:00
1 parent 234fbe88aa
commit f8b3501637
3 files changed
+177 -151

No files matched your search

+11 -12
View File
@@ -18,23 +18,25 @@ bot = commands.Bot(command_prefix='!', intents=intents, help_command=None)
# 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'),
)
async def alert_owner(text: str):
owner = await bot.fetch_user(int(os.getenv('OWNER_ID', '0')))
await owner.send(text)
twitter_mao = TwitterRSSForwarder(
webhook_url=os.getenv('TWITTER_DISCORD_WEBHOOK_MAO'),
guid_file='data/last_tweet_mao.txt',
# one poller for the @CalabiyauLeaks feed, posting to both servers
twitter = TwitterRSSForwarder(
webhooks={
'main': os.getenv('TWITTER_DISCORD_WEBHOOK'),
'mao': os.getenv('TWITTER_DISCORD_WEBHOOK_MAO'),
},
alert=alert_owner,
)
@bot.event
async def on_ready():
print(f'[+] {bot.user} is online!')
# on_ready fires again after reconnects; don't start duplicate pollers
# on_ready fires again after reconnects; don't start a duplicate poller
if not twitter._running:
asyncio.create_task(twitter.start())
if not twitter_mao._running:
asyncio.create_task(twitter_mao.start())
# Clear stale global slash commands
try:
await bot.tree.sync()
@@ -71,11 +73,8 @@ async def main():
finally:
# 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()
await twitter_mao.close()
logging.basicConfig(level=logging.INFO)
logging.getLogger('httpx').setLevel(logging.WARNING)