Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ooovenenoso authored Mar 1, 2024
1 parent ace2a2a commit 282bf94
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
import discord
from discord.ext import commands
import time
import requests
import urllib.request

# Define TESTING_MODE global variable
TESTING_MODE = True
APITOKEN = 'your_facecheckid_token_here' # Your API Token

# Your Discord bot token
DISCORD_TOKEN = 'DISCORD_API_KEY'

# Initialize bot with intents
# Initialize Intents
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True

# Your Discord bot token
DISCORD_TOKEN = 'your_discord_token_here'

# Initialize bot with intents
bot = commands.Bot(command_prefix='/', intents=intents)

def search_by_face(image_file):
# [Your face search code goes here]
# URL for the FaceCheck API
UPLOAD_URL = "https://facecheck.id/api/upload_pic"

# API token for authorization
API_TOKEN = 'FaceCheck_API_KEY'

async def search_by_face(image_bytes, testing_mode=True):
headers = {'Authorization': f'Bearer {API_TOKEN}'}
params = {'test_mode': testing_mode} if testing_mode else {}

try:
files = {'images': image_bytes}
response = requests.post(UPLOAD_URL, files=files, headers=headers, params=params)
response.raise_for_status() # Raise an error for unsuccessful responses
data = response.json()

# Check if there's an error in the response
error = data.get('error')
if error:
return f"Error searching by face: {error}", None

# Check if there are items in the output
output = data.get('output')
if output and 'items' in output:
items = output['items']
if items:
return None, items

return "No items found in response", None

except Exception as e:
return f"Error searching by face: {str(e)}", None

@bot.event
async def on_message(message):
if message.content.startswith('/findit') and message.attachments:
attachment = message.attachments[0]
image_file = await attachment.save(fp=f"{attachment.filename}")
image_bytes = await attachment.read()

error, urls_images = await search_by_face(image_bytes, testing_mode=TESTING_MODE)

error, urls_images = search_by_face(image_file)

if urls_images:
response = "\n".join([f"{im['score']} {im['url']} {im['base64'][:32]}..." for im in urls_images])
response = "\n".join([f"{im['score']} {im['url']['value']} {im['base64'][:32]}..." for im in urls_images])
await message.channel.send(f"Results:\n{response}")
else:
await message.channel.send(error)
Expand Down

0 comments on commit 282bf94

Please sign in to comment.