Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes + improvements #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions Config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"region_list": ["EU", "JP", "WW", "MY", "AU"],
"bot_token": "",
"embed_footer_text": "",
"embed_author_url": "",
"embed_color": "7180222",
"webhook_url": "",
"monitor_delay": 60
}
674 changes: 0 additions & 674 deletions LICENSE.md

This file was deleted.

159 changes: 159 additions & 0 deletions Main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import json, os, time, discord, threading, datetime, requests
from discord_webhook import DiscordEmbed, DiscordWebhook

intents = discord.Intents().all()
client = discord.Bot(intents = intents)

with open(os.getcwd() + '/Config.json') as f:
data = json.load(f)
region_list = data['region_list']
bot_token = data['bot_token']
embed_footer_text = data['embed_footer_text']
embed_author_url = data['embed_author_url']
embed_color = data['embed_color']
webhook_url = data['webhook_url']
delay = data['monitor_delay']

with open(os.getcwd() + '/Region_emoji.json') as f:
region_emoji = json.load(f)

def get_raffles(region):
product_data = []
headers = {
'Pragma': 'no-cache',
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Host': 'www.soleretriever.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',
}

params = {
'term': '',
'from': '0',
'limit': '24',
'locales': region.upper(),
'types': '',
'isHideEntered': 'true',
}

response = requests.get('https://www.soleretriever.com/api/products/raffles', params=params, headers=headers)
if response.status_code == 200:
data_json = json.loads(response.text)
for product in data_json['products']:
product_slug = product['slug']
for raffle in product['raffle']:
product_raffle = str(raffle['id'])
product_data.append([product_slug, product_raffle])

return product_data

def get_raffle_details(product_data, region_data):
headers = {
'Pragma': 'no-cache',
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Host': 'www.soleretriever.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',
}

response = requests.get(
f'https://www.soleretriever.com/raffles/{str(product_data[0])}/raffle/{str(product_data[1])}',
headers=headers,
)

if response.status_code == 200:
response_data = response.text.split('<script id="__NEXT_DATA__" type="application/json">')[1].split('</script>')[0]
data_json = json.loads(response_data)['props']['pageProps']['raffleData']

raffle_url = data_json['url']
raffle_type = data_json['type']
raffle_pickup = data_json['isPickup']
raffle_shipping = data_json['hasPostage']
raffle_end = data_json['endDate']
product_sku = data_json['product']['pid']
product_name = data_json['product']['name']
product_image = data_json['product']['imageUrl']
raffle_store= data_json['retailer']['name']

webhook = DiscordWebhook(url = webhook_url)
embed = DiscordEmbed(title = f'{str(product_name)}', url = f'https://www.soleretriever.com/raffles/{str(product_data[0])}/raffle/{str(product_data[1])}', color = int(embed_color), description=f'> New Raffle Live For {str(region_data["name"])} :{str(region_data["flag"])}:')
embed.set_thumbnail(url = product_image)
embed.set_footer(text = f'SoleRetriever Monitor by {embed_footer_text} \U000000B7 {datetime.datetime.now()}')
embed.add_embed_field(name = 'Product SKU: ', value = f'`{product_sku}`')

if raffle_type == 'In app':
embed.add_embed_field(name = 'Raffle Type: ', value = 'In App :mobile_phone:')
elif raffle_type == 'Online':
embed.add_embed_field(name = 'Raffle Type: ', value = 'Online :desktop:')
elif raffle_type == 'In store':
embed.add_embed_field(name = 'Raffle Type: ', value = 'Instore :shopping_cart:')

if raffle_pickup == True:
embed.add_embed_field(name = 'Delivery:', value = 'Instore Pickup :door:')
if raffle_shipping == True:
embed.add_embed_field(name = 'Delivery:', value = 'Shipping :package:')

embed.add_embed_field(name = 'Store:', value = raffle_store)
embed.add_embed_field(name = 'Closing: ', value = f'<t:{str(int(datetime.datetime.fromisoformat(raffle_end).timestamp())).split(".")[0]}>')
embed.add_embed_field(name = 'Entry:', value = f'[ENTER HERE]({raffle_url})')
embed.add_embed_field(name = 'Links:', value = f'[Restocks](https://restocks.net/en/shop/?q={product_sku}) | [StockX](https://stockx.com/search?s={product_sku}) | [Goat](https://www.goat.com/search?query={product_sku}) | [FlightClub](https://www.flightclub.com/catalogsearch/result?query={product_sku})', inline=False)
webhook.add_embed(embed)
webhook.execute()

return

@client.event
async def on_ready():
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f] Bot Is Ready"))

for region in region_list:
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f | Region: {region}] Starting..."))
with open(os.getcwd() + '/Region_emoji.json') as f:
region_emoji = json.load(f)
region_data = region_emoji[region]
t1 = threading.Thread(target=main, args=(region,region_data)).start()

def main(region,region_data):
initial_data = get_raffles(region)
while True:
monitor_data = get_raffles(region)

if monitor_data != initial_data:
for raffle in monitor_data:
if raffle not in initial_data:
get_raffle_details(raffle, region_data)
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f | Region: {region}] New Raffle Live: {raffle[0]}"))

time.sleep(3)

initial_data = monitor_data

else:
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f | Region: {region}] Waiting For New Raffles"))

time.sleep(delay)

@client.slash_command(description = 'Command To Test Webhook')
async def webhook_test(ctx: discord.ApplicationContext):
await ctx.defer(ephemeral=True)
try:
raffle = get_raffles(region_list[0])
get_raffle_details(raffle[0], region_emoji[region_list[0]])
await ctx.respond('Testing Succesful', ephemeral=True)
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f | Region: {region_list[0]}] Successfully Send Testing Webhook"))

except Exception as e:
await ctx.respond(f'Error: {str(e)}', ephemeral=True)
print(datetime.datetime.now().strftime(f"[%d %B %Y %H:%M:%S.%f | Region: {region_list[0]}] Error Sending Testing Webhook. Error: {str(e)}"))

@client.event
async def on_message(message: discord.Message):
if message.channel.id == 1100043271503351858:
try:
await message.add_reaction("\U00002705")
except:
pass
else:
pass

client.run(data['bot_token'])
128 changes: 15 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,16 @@
<p align="center">
<a href="https://discord.gg/b6zyJyCQUu">
<img src="https://cdn.discordapp.com/attachments/955216634522525746/1099813661943550002/logo-modified.png" alt="Logo" width="auto" height="256">
</a>

<h3 align="center">Sole Retriever Raffle Monitor</h3>

<p align="center">
A Web Monitor that Notifies you through Discord Webhook when a New Raffle is Added to Sole Retriever
<br />
<a href="https://github.com/Sufyan123o/SufRetriever">Report Bug</a>
·
<a href="https://github.com/Sufyan123o/SufRetriever">Request Feature</a>
</p>

<p align="center">
<a href="https://paypal.me/SufyanO?country.x=GB&locale.x=en_GB">
<img src="https://pics.paypal.com/00/s/OGQwMWQ4YzQtN2QwZS00OTA0LWJjNzktZGI3OTE2NjRmYWIz/file.PNG" alt="Logo" width="auto" height="50" >
</a>
</p>
</p>
<br />

Please **star** this repository to increase the awareness of the project for others to use or add to.

Join the Discord Server YasCommunity for Code, Sneakers and Everything in-between! Join [here](https://discord.gg/b6zyJyCQUu)

<p align="center">
<a href="https://github.com/Sufyan123o/SufRetriever">
<img src="https://media.discordapp.net/attachments/597104422123995136/1099811349166575686/download_2-modified.png" alt="Logo" width="auto" height="256">
<img src="https://cdn.discordapp.com/attachments/692518598241026139/1099801733884035134/image.png" alt="Logo" width="auto" height="256">
</a>
</p>
<br />

<div align="center">

# Suf Retriever Discord Bot 🤖

</div>


Suf Retriever is a **Discord bot** that monitors and notifies users about new sneaker raffles on the [Sole Retriever](https://www.soleretriever.com/) website. It fetches the latest raffle data and sends a notification through a webhook with an embedded message, including the raffle details such as region, delivery method & raffle type.

## 🌟 Features

- Monitors New Sneaker Raffles on Sole Retriever
- Sends notifications with Embedded Messages through a Discord Webhook
- Supports a Test Command for Manual Testing `!test` .Type this in the Discord Channel

## 🛠 Setup and Installation

1. Make Sure you have Python Installed. Then Install the required Python packages in using Command Prompt or Terminal:
Python and PIP installation guides can be found in the Discord server [here](https://discord.gg/b6zyJyCQUu).
```
pip install -r requirements.txt
```

2. Open the SufRetriever.py file in an IDE or a Text Editior such as NotePad and add your Discord Bot token:

A guide on How to get a Bot Token Can be found [here](https://discordgsm.com/guide/how-to-get-a-discord-bot-token).

LEAVE THE TOKEN WITHIN THE APOSTROPHES
```
TOKEN=your_discord_bot_token_here
```

Replace `your_discord_bot_token_here` with your actual Discord bot token.

3. Set the `WEBHOOK_URL` variable in the script to the webhook URL you created in your Discord server.

A guide on How to get a Webhook Can be found [here](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks).

LEAVE THE WEBHOOK WITHIN THE APOSTROPHES
```
TOKEN=your_discord_webhook_here
```

4. Open a terminal or command prompt and navigate to the directory containing the bot script using the `cd` command:

```
cd path/to/your/bot/script
```

Replace `path/to/your/bot/script` with the actual path to the directory containing the bot script.

For example, if the script is located in `C:\Users\YourUsername\Documents\DiscordBots\SufRetriever`, you would type:

```
cd C:\Users\YourUsername\Documents\DiscordBots\SufRetriever
```

Once you are in the correct directory, run the bot script:

```
python SufRetriever.py
```
or if on Mac:
```
python3 SufRetriever.py
```


Replace `bot_script.py` with the name of the Python script containing the bot code.



## 📚 Commands

- `!test`: Sends a test webhook notification with a pre-defined raffle URL. This command can be used to check if the webhook and embed formatting are working correctly.

## 📄 License

Distributed under the GNU General Public License v3.0 License. See [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.en.html) for more information..
Example Config.json
```json
{
"region_list": ["EU", "JP", "WW", "MY", "AU"],
"bot_token": "OTY2Nzg3NjAxODAzNjQ5MDg0.YmG1Hg.2QnsnqrfDjNL",
"embed_footer_text": "je_mi_to_burt#2604",
"embed_author_url": "https://i.imgur.com/rdWuZBR.png",
"embed_color": "7180222",
"webhook_url": "https://discord.com/api/webhooks/...",
"monitor_delay": 60
}
```

* embed color needs to be decimal value, convert hex to decimal [Here](https://www.colorhexa.com/)
* monitor delay is in seconds
30 changes: 30 additions & 0 deletions Region_emoji.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"JP": {
"name": "Japan",
"flag": "flag_jp"
},
"US": {
"name": "United States",
"flag": "flag_us"
},
"AU": {
"name": "Australia",
"flag": "flag_au"
},
"EU": {
"name": "Europe",
"flag": "flag_eu"
},
"MY": {
"name": "Malasia",
"flag": "flag_my"
},
"WW": {
"name": "Worldwide",
"flag": "globe_with_meridians"
},
"CA": {
"name": "Canada",
"flag": "flag_ca"
}
}
Loading