This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTwitterLinkFixer.py
64 lines (51 loc) · 2.03 KB
/
TwitterLinkFixer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import discord, argparse, re
parser = argparse.ArgumentParser(description='set token')
parser.add_argument('-token', type=str, help='set your token', default=None)
args = parser.parse_args()
token = args.token
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print("Ready to replace URL!")
@client.event
async def on_message(message):
channel = message.channel
if type(message.content) == str:
if matchTwitter(message.content):
await message.delete()
fixed = message.content.replace("twitter.com", "fxtwitter.com")
msg = await channel.send(f"Sent by {get_username(message.author)}.\n{fixed}")
await msg.add_reaction('❌')
elif matchX(message.content):
await message.delete()
fixed = message.content.replace("x.com", "fxtwitter.com")
msg = await channel.send(f"Sent by {get_username(message.author)}.\n{fixed}")
await msg.add_reaction('❌')
@client.event
async def on_reaction_add(reaction, user):
if reaction.message.author != client.user:
return
if str(reaction.emoji) != '❌':
return
users = []
async for userr in reaction.users():
users.append(userr)
if (reaction.count > 1 and client.user in users) and (user in users):
await reaction.message.delete()
channel = reaction.message.channel
await channel.send(f"Link deleted by {user.name}")
def get_username(author:discord.User|discord.Member):
if author.discriminator == "0":
return f"@{author.name}"
else:
return f"{author.name}#{author.discriminator}"
def matchTwitter(search:str):
return re.search(r'https://twitter\.com/\w+/status/\d+', search) != None
def matchX(search:str):
return re.search(r'https://x\.com/\w+/status/\d+', search) != None
if args.token is None:
print("Token is empty.")
else:
client.run(token)