├── rickroll_detector.py
├── async_rickroll_detector.py
├── bot.py
└── README.md
/rickroll_detector.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import re
3 |
4 | def find_rickroll(url):
5 | source = str(requests.get(url).content).lower()
6 | phrases = ["rickroll","rick roll","rick astley","never gonna give you up"]
7 | return bool(re.findall("|".join(phrases), source, re.MULTILINE))
8 |
--------------------------------------------------------------------------------
/async_rickroll_detector.py:
--------------------------------------------------------------------------------
1 | import aiohttp
2 | import re
3 |
4 | class RickRollDetector(aiohttp.ClientSession):
5 |
6 | async def find(self, url):
7 | source = str(await (await super().get(url)).content.read()).lower()
8 | phrases = ["rickroll","rick roll","rick astley","never gonna give you up"]
9 | return bool(re.findall('|'.join(phrases), source, re.MULTILINE))
10 |
--------------------------------------------------------------------------------
/bot.py:
--------------------------------------------------------------------------------
1 | import discord
2 | from discord.ext import commands
3 | from async_rickroll_detector import RickRollDetector
4 |
5 | BOT_TOKEN = ""
6 | RICKROLL_FOUND_MESSAGE = "⚠️Rickroll Alert⚠️"
7 |
8 | bot = commands.Bot(command_prefix = ">", intents = discord.Intents.default())
9 |
10 | @bot.event
11 | async def on_ready():
12 | global detector
13 | detector = RickRollDetector()
14 |
15 | @bot.event
16 | async def on_message(msg):
17 | for i in msg.content.split(" "):
18 | i = i.replace("<","").replace(">", "") #Removes <> that could be used to hide embeds
19 | if "https://" in i and await detector.find(i):
20 | await msg.reply(RICKROLL_FOUND_MESSAGE)
21 | break
22 |
23 | await bot.process_commands(msg)
24 |
25 | bot.run(BOT_TOKEN)
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | A simple rickroll detector
4 | # Installation
5 | This isn't a python module on pypi as of now so you'll need to download the rickroll_detector.py file and keep it in the same directory as your main file.
6 | You can also `git clone https://github.com/CodeWithSwastik/rickroll-detector`
7 | # Usage
8 |
9 | ```python
10 | from rickroll_detector import find_rickroll
11 |
12 | result = find_rickroll("https://youtu.be/oHg5SJYRHA0")
13 | print(result) #returns True
14 | ```
15 |
16 | # Async Usage
17 | ```python
18 | from async_rickroll_detector import RickRollDetector
19 |
20 | detector = RickRollDetector()
21 | await detector.find('https://youtu.be/oHg5SJYRHA0')
22 | ```
23 |
24 | # Example bot
25 | I also have a bot.py file here which is an example discord bot that will detect rickrolls
26 |
--------------------------------------------------------------------------------