Skip to content

Instantly share code, notes, and snippets.

@eduzappa18
Created August 22, 2021 01:01
Show Gist options
  • Save eduzappa18/574b28557c06f93c628984bca753c94f to your computer and use it in GitHub Desktop.
Save eduzappa18/574b28557c06f93c628984bca753c94f to your computer and use it in GitHub Desktop.
vBulletin RSS Python Discord Bot
import datetime
import asyncio
import discord
import feedparser
# https://pypi.org/project/discord.py/
# https://pypi.org/project/feedparser/
TOKEN = "TOKEN_HERE"
CHANNEL_ID = 709857039433597029
RSS = "https://www.x-null.net/forums/external.php?type=rss2&lastpost=1"
async def loop():
last_entries = []
while True:
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "Checking for new posts...")
d = feedparser.parse(RSS)
if d.entries:
if last_entries and d.entries != last_entries:
await embed(d)
else:
pass # No new posts found
else:
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "xNULL is down")
last_entries = d.entries
await asyncio.sleep(60*5)
async def embed(d):
embed = discord.Embed(
title=d.entries[0].title,
url=d.entries[0].link,
colour=discord.Colour.blue(),
timestamp=datetime.datetime.utcnow()
)
embed.add_field(name=f"{d.entries[0].author} posted in: {d.entries[0].title}", value=d.entries[0].description, inline=False)
embed.set_footer(text=f"Posted by {d.entries[0].author}")
channel = client.get_channel(CHANNEL_ID)
await channel.send(embed=embed)
async def start():
embed = discord.Embed(
title="xNULL Bot",
colour=discord.Colour.green(),
description="I have been booted up! Waiting for new xNULL posts!",
timestamp=datetime.datetime.utcnow(),
)
channel = client.get_channel(CHANNEL_ID)
await channel.send(embed=embed)
class Client(discord.Client):
async def on_ready(self):
print(f"Logged on as {self.user}!")
await start()
await loop()
client = Client()
client.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment