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]>
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from dotenv import load_dotenv
|
|
import os
|
|
import logging
|
|
import asyncio
|
|
|
|
from twitterbridge.rss import TwitterRSSForwarder
|
|
|
|
load_dotenv('credentials.env')
|
|
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True
|
|
intents.members = True
|
|
|
|
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.
|
|
|
|
async def alert_owner(text: str):
|
|
owner = await bot.fetch_user(int(os.getenv('OWNER_ID', '0')))
|
|
await owner.send(text)
|
|
|
|
# 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 a duplicate poller
|
|
if not twitter._running:
|
|
asyncio.create_task(twitter.start())
|
|
# Clear stale global slash commands
|
|
try:
|
|
await bot.tree.sync()
|
|
except Exception:
|
|
pass
|
|
|
|
async def main():
|
|
async with bot:
|
|
await bot.load_extension('tgbridge')
|
|
await bot.load_extension('cogs.general')
|
|
await bot.load_extension('cogs.help')
|
|
await bot.load_extension('cogs.chance')
|
|
await bot.load_extension('cogs.gifs')
|
|
await bot.load_extension('cogs.copypasta')
|
|
await bot.load_extension('cogs.sysinfo')
|
|
await bot.load_extension('music.music_wrapper')
|
|
await bot.load_extension('cogs.statchannel')
|
|
await bot.load_extension('cogs.ffmpeg_things')
|
|
await bot.load_extension('cogs.roles')
|
|
await bot.load_extension('cogs.gitpull')
|
|
await bot.load_extension('cogs.currency_converter')
|
|
await bot.load_extension('ai.ai_roleplay')
|
|
await bot.load_extension('twitterbridge.leaks_cmd')
|
|
await bot.load_extension('blue_archive.gacha')
|
|
await bot.load_extension('blue_archive.inventory')
|
|
await bot.load_extension('firebase_website')
|
|
await bot.load_extension('cogs.calendar')
|
|
await bot.load_extension('cogs.bucketlist')
|
|
await bot.load_extension('cogs.timestamp')
|
|
await bot.load_extension('cogs.timestamp_friends')
|
|
|
|
try:
|
|
await bot.start(os.getenv('DISCORD_TOKEN'))
|
|
finally:
|
|
# bot.close() unloads extensions, so tgbridge.teardown stops the
|
|
# Telegram poller and closes its aiohttp session for us
|
|
twitter.stop()
|
|
await twitter.close()
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logging.getLogger('httpx').setLevel(logging.WARNING)
|
|
asyncio.run(main())
|