This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
forked from 0xbagp/new-fit-for-your-pfp---discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
168 lines (130 loc) · 4.51 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import os
import io
import discord
from discord.ext import commands
import json
from pprint import pprint
import requests
import typing
from dotenv import load_dotenv
import PIL
from PIL import Image
# discord bot prefix
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
# # Bot command functions overview
# 0. inputs: collection, pfp_id, outfit, variant
# 1. Get base image
# 2. Download base image to clean_pfp dir
# 3. Combine images & save to dressed_pfp dir
# 4. Send dressed_pfp image to discord
# Current Campaigns
# - Bussin
# - Cap
# - Beer
#
# Archive Campaigns
# - Seven
# Collections available
collections = ['ape', 'dtp', 'egg']
# Functions
def get_daa_image(pfp_id):
url = ('https://degenape.nyc3.digitaloceanspaces.com/apes/no-head-traits/' + str(pfp_id) + '.png')
save_image_file_path = ('collections/ape/clean_pfps/' + str(pfp_id) + '.png')
download_image(url, save_image_file_path)
def get_collection_image(collection, pfp_id):
search_value = {
'dtp': {
'project_id': 'degentrashpandas',
'search_value': 'Degen Trash Panda #',
},
'egg': {
'project_id': 'degenerateapekindergarten',
'search_value': 'Degen Egg #',
},
}
payload = json.dumps({
'condition': {
'project_ids': [
{
'project_id': search_value[collection]['project_id']
}
],
'name': {
'operation': 'EXACT',
'value': search_value[collection]['search_value'] + str(pfp_id)
},
}
})
headers = {
'Authorization': os.environ['HYPER_TOKEN'],
'Content-Type': 'application/json'
}
r = requests.post('https://beta.api.solanalysis.com/rest/get-market-place-snapshots', headers=headers, data=payload)
url = r.json()['market_place_snapshots'][0]['meta_data_img']
save_image_file_path = ('collections/' + collection + '/clean_pfps/' + str(pfp_id) + '.png')
download_image(url, save_image_file_path)
def download_image(url, image_file_path):
r = requests.get(url, timeout=4.0)
if r.status_code != requests.codes.ok:
assert False, 'Status code error: {}.'.format(r.status_code)
with Image.open(io.BytesIO(r.content)) as im:
im.save(image_file_path)
def combine_images(collection, outfit, fit, pfp_id):
save_file_path = ('collections/' + collection + '/dressed_pfps/' + str(pfp_id) + '_' + outfit + '_' + fit + '.png')
pfp = Image.open('collections/' + collection + '/clean_pfps/' + str(pfp_id) + '.png')
outfit = Image.open('collections/' + collection + '/outfits/' + outfit + '/' + fit + '.png')
# Better blending method
dressed = Image.new("RGBA", pfp.size)
dressed = Image.alpha_composite(dressed, pfp)
dressed = Image.alpha_composite(dressed, outfit)
dressed.save(save_file_path)
return save_file_path
@bot.command(name="gib", brief='Gib me cool pfp', description='This command will let you be much cooler than you are... fr fr')
async def gib(ctx, collection: str, pfp_id: int, campaign: str, fit: typing.Optional[str] = 'default' ):
outfit = campaign
collection = collection.lower()
try:
if collection in collections:
if collection == 'ape':
get_daa_image(pfp_id)
else:
get_collection_image(collection, pfp_id)
else:
await ctx.send('Please enter a valid collection. ape / dtp / egg')
save_file_path = combine_images(collection, outfit, fit, pfp_id)
await ctx.send(file=discord.File(save_file_path))
except:
await ctx.send('Please enter valid options for your request.\n\nTry `!gib-help` for more info')
@bot.command(name='gib-help', brief='List avaiable fits', description='This command will list the different outfits available to you')
async def gib_help(ctx):
message = """**Formatting the command examples**
```md
!gib [collection] [id] [campaign] [variant]
!gib [ape/dtp/egg] [123] [solcap/solsnap/bussin/beer] [black/blue/red/white... etc]
!gib ape 123 solcap
!gib ape 123 bussin blue
!gib dtp 456 solsnap
!gib egg 789 beer
```
==========================
**What I Can Gib**
**Beer**
*collections:* `ape`, `dtp`,`egg`
*variants:* `clean`, `background`
**bussin**
*collections:* `ape`, `dtp`
*variants:* `black`, `blue`, `brown`, `gold`, `green`, `purple`, `red`, `white`
**solcap**
*collections:* `ape`, `dtp`
**solsnap**
*collections:* `ape`, `dtp`
"""
await ctx.send(message)
load_dotenv()
bot.run(os.environ['DISCORD_TOKEN'])