Skip to content

Commit

Permalink
Fixing more bugs, improved error message
Browse files Browse the repository at this point in the history
parsing .it urls wasnt urllib's fault, was caused by <> around the url to suppress embeds via discord markdown instead of the suppress_embeds flag which was broken.
Changed back to nitter.it and improved error message to show accepted urls
  • Loading branch information
King0fgames committed Apr 4, 2023
1 parent 6ae6c45 commit 9289e1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions FKTwitter1.3.0.py → FKTwitter1.3.1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FKTwitter Discord Bot
# Author: King0fgames
# Ver: 1.3.0
# Ver: 1.3.1
# Last update: 4/4/23
# Source: https://github.com/King0fgames/FKTwitterBot

Expand All @@ -11,6 +11,10 @@

# enables url parse debugging
debug = False
if(debug):
import logging
logging.basicConfig(filename="debug.txt", level=logging.DEBUG)


# Get configuration.json
with open("configuration.json", "r") as config:
Expand All @@ -32,11 +36,11 @@ def __init__(self, inputs, output, embed=True, del_query=True):
#Site objects (inputs, output, embed, del_query)
nitter = Site(
("twitter.com", "mobile.twitter.com", "vxtwitter.com"),
"nitter.net",
"nitter.it",
embed = False
)
vxtwitter = Site(
("twitter.com", "mobile.twitter.com", "nitter.net"),
("twitter.com", "mobile.twitter.com", "nitter.net", "nitter.it"),
"vxtwitter.com"
)
libreddit = Site(
Expand Down Expand Up @@ -189,7 +193,7 @@ async def replace_url(ctx, link: str, site: Site):
#url validation
url = urlparse(link)

#url parse debugging, apparently python's urllib doesn't support .it extensions
#url parse debugging
if(debug):
print("Validating:\nscheme: " + url.scheme + "\nnetloc: " + url.netloc + "\npath: "
+ url.path + "\nquery:" + url.query + "\nfragment:" + url.fragment)
Expand All @@ -208,10 +212,12 @@ async def replace_url(ctx, link: str, site: Site):
if site.embed: #default = True
await ctx.send(f'{new_link}')
else:
await ctx.send(f'<{new_link}>')
await ctx.send(f'{new_link}', suppress_embeds=True)

#Failure message
else:
await ctx.send(f"Invalid URL, accepted URLS: ".join(site.inputs), ephemeral=True)
error_message = "Invalid URL, accepted URLs:\n" + '\n'.join(site.inputs)
await ctx.send(error_message, ephemeral=True)

print("FKTwitter Bot starting")
bot.start()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Discord bot to convert social media links to privacy-oriented alternative front-

**[Add To Server](https://discord.com/api/oauth2/authorize?client_id=970097140888121344&permissions=277025410048&scope=bot%20applications.commands)**

- Twitter -> https://nitter.net ~ [Nitter](https://github.com/zedeus/nitter) (embeds disabled)
- Twitter -> https://nitter.it ~ [Nitter](https://github.com/zedeus/nitter) (embeds disabled)
- Twitter -> https://vxtwitter.com ~ [BetterTwitFix](https://github.com/dylanpdx/BetterTwitFix) (for fixing twitter embeds)
- Reddit -> https://r.nf ~ [Libreddit](https://github.com/spikecodes/libreddit)
- Youtube -> https://yewtu.be ~ [Invidious](https://github.com/iv-org/invidious)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constantly==15.1.0
cryptography==40.0.1
dbus-python==1.2.18
decorator==5.1.1
discord-py-interactions==4.4.0
discord-py-interactions==4.3.3
distro==1.8.0
distro-info==1.0
docutils==0.19
Expand Down

0 comments on commit 9289e1f

Please sign in to comment.