Skip to content

Commit

Permalink
[Discord] Change twitter status command to use Nitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Oct 18, 2023
1 parent 2127244 commit 4614678
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Discord/cogs/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import re
import sys
import traceback
import urllib.parse

from more_itertools import chunked
import feedparser

from utilities import checks, tasks

sys.path.insert(0, "..")
from units import nitter
sys.path.pop(0)


errors_logger = logging.getLogger("errors")

Expand Down Expand Up @@ -101,8 +106,10 @@ async def twitter_status(

username = handle.lstrip('@')

nitter_instance_url = await nitter.get_best_healthy_rss_instance_url()

async with ctx.bot.aiohttp_session.get(
"https://openrss.org/twitter.com/" + username
f"{nitter_instance_url}/{username}/rss"
) as resp:
if resp.status == 404:
await ctx.embed_reply(
Expand All @@ -123,20 +130,21 @@ async def twitter_status(
# TODO: Change to pagination
for entry in feed_info.entries:
if not retweets and (
entry.title[
:len(username) + 13 # 13 == len("@ retweeted: ")
].lower() == f"@{username.lower()} retweeted: "
entry.author.lstrip('@').lower() != username.lower()
):
continue

if not replies and (
entry.title[
:len(username) + 14 #14 == len("@ replied to: ")
].lower() == f"@{username.lower()} replied to: "
):
if not replies and entry.title.startswith("R to @"):
# TODO: Handle false positives
continue

await ctx.reply(entry.link)
await ctx.reply(
urllib.parse.urlparse(entry.link)._replace(
scheme = "https",
netloc = "twitter.com",
fragment = ""
).geturl()
)
return

await ctx.embed_reply(f"{ctx.bot.error_emoji} Error: Status not found")
Expand Down

0 comments on commit 4614678

Please sign in to comment.