-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 18ljones/faces
Faces
- Loading branch information
Showing
6 changed files
with
83 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
opencv-python | ||
numpy | ||
pillow | ||
pycord | ||
python-dotenv | ||
discord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import lib.faces_util as faces_util | ||
import os | ||
import discord | ||
|
||
BYTES_IN_MEGABYTE = 1048576 | ||
|
||
allowable_attachment_types = ['image/png', 'image/jpeg'] | ||
|
||
async def on_message(message, client, conf): | ||
if message.content.startswith("$face"): | ||
if len(message.attachments) > 0: | ||
for attachment in message.attachments: | ||
# check if attachment is a picture and is smaller than 8mb | ||
if attachment.content_type in allowable_attachment_types and attachment.size < (8 * BYTES_IN_MEGABYTE): | ||
if attachment.proxy_url != '404': | ||
try: | ||
await attachment.save('attachment_picture.png', use_cached=True) | ||
found, path = faces_util.get_face_replace('attachment_picture.png') | ||
if found: | ||
await message.channel.send(file=discord.File(path)) | ||
else: | ||
await message.channel.send('No face found :(') | ||
if os.path.exists('face_detected.png'): | ||
os.remove('face_detected.png') | ||
except discord.HTTPException as error: | ||
logging.exception(f'{datetime.now(timezone.utc)} Face on_message') | ||
await message.channel.send('Could not download attachment :(') | ||
except discord.NotFound as error: | ||
logging.exception(f'{datetime.now(timezone.utc)} Face on_message') | ||
await message.channel.send('Attachment not found :(') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters