Skip to content
Permalink
Browse files

[reverseimagesearch] new cog

tracemoe is returns 500 for me, needs investigation
  • Loading branch information...
fixator10 committed May 19, 2019
1 parent 9684251 commit a89d7264d7f9e7d41f5bf1a727986ba743657215
@@ -0,0 +1,5 @@
from .reverseimagesearch import ReverseImageSearch


def setup(bot):
bot.add_cog(ReverseImageSearch(bot))
@@ -0,0 +1,81 @@
# https://github.com/TrustyJAID/Trusty-cogs/blob/master/notsobot/converter.py

import re

from discord.ext.commands.converter import Converter
from discord.ext.commands.errors import BadArgument
from redbot.core.i18n import Translator

_ = Translator("ReverseImageSearch", __file__)

IMAGE_LINKS = re.compile(r"(https?://[^\"\'\s]*\.(?:png|jpg|jpeg|gif|svg))")
EMOJI_REGEX = re.compile(r"(<(a)?:[a-zA-Z0-9_]+:([0-9]+)>)")
MENTION_REGEX = re.compile(r"<@!?([0-9]+)>")
ID_REGEX = re.compile(r"[0-9]{17,}")


class ImageFinder(Converter):
"""
This is a class to convert notsobots image searching capabilities
into a more general converter class
"""

async def convert(self, ctx, argument):
attachments = ctx.message.attachments
mentions = MENTION_REGEX.finditer(argument)
matches = IMAGE_LINKS.finditer(argument)
emojis = EMOJI_REGEX.finditer(argument)
ids = ID_REGEX.finditer(argument)
urls = []
if matches:
for match in matches:
# print(match.group(1))
urls.append(match.group(1))
if emojis:
for emoji in emojis:
ext = "gif" if emoji.group(2) else "png"
url = "https://cdn.discordapp.com/emojis/{id}.{ext}?v=1".format(
id=emoji.group(3), ext=ext
)
urls.append(url)
if mentions:
for mention in mentions:
user = ctx.guild.get_member(int(mention.group(1)))
if user.is_avatar_animated():
url = IMAGE_LINKS.search(str(user.avatar_url_as(format="gif")))
urls.append(url.group(1))
else:
url = IMAGE_LINKS.search(str(user.avatar_url_as(format="png")))
urls.append(url.group(1))
if not urls and ids:
for possible_id in ids:
user = ctx.guild.get_member(int(possible_id.group(0)))
if user:
if user.is_avatar_animated():
url = IMAGE_LINKS.search(str(user.avatar_url_as(format="gif")))
urls.append(url.group(1))
else:
url = IMAGE_LINKS.search(str(user.avatar_url_as(format="png")))
urls.append(url.group(1))
if attachments:
for attachment in attachments:
urls.append(attachment.url)

if not urls:
ctx.command.reset_cooldown(ctx)
raise BadArgument(_("No images provided."))
return urls

async def search_for_images(self, ctx):
urls = []
async for message in ctx.channel.history(limit=10):
if message.attachments:
for attachment in message.attachments:
urls.append(attachment.url)
match = IMAGE_LINKS.match(message.content)
if match:
urls.append(match.group(1))
if not urls:
ctx.command.reset_cooldown(ctx)
raise ValueError(_("No Images found in recent history."))
return urls
@@ -0,0 +1,10 @@
{
"author": [
"Fixator10"
],
"install_msg": "Thanks for install.",
"short": "",
"description": "",
"tags": [],
"requirements": []
}
@@ -0,0 +1,90 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-05-19 21:38+0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: redgettext 2.2\n"


msgid "No images provided."
msgstr ""

msgid "No Images found in recent history."
msgstr ""

msgid "(Anime) Reverse Image Search"
msgstr ""

msgid "Reverse search image via SauceNAO"
msgstr ""

msgid "Similarity: {}%"
msgstr ""

msgid "Part/Episode: {}"
msgstr ""

msgid "Year: {}"
msgstr ""

msgid "Est. Time: {}"
msgstr ""

msgid "Via SauceNAO • Page {}/{}"
msgstr ""

msgid "Set API key for SauceNAO"
msgstr ""

msgid ""
"To get SauceNAO API key:\n"
"1. [Login](https://saucenao.com/user.php) to your SauceNAO account\n"
"2. Go to [Search > api](https://saucenao.com/user.php?page=search-api) page\n"
"3. Copy your *api key*\n"
"4. Use `{}set api reverseimagesearch saucenao,<your_api_key>`\n"
"\n"
"Note: These tokens are sensitive and should only be used in a private channel\n"
"or in DM with the bot."
msgstr ""

msgid ""
"Set API count of results count for SauceNAO\n"
"\n"
" 6 by default"
msgstr ""

msgid "See how many requests are left"
msgstr ""

msgid ""
"Remaining requests:\n"
"Short (30 seconds): {}/{}\n"
"Long: (24 hours): {}/{}"
msgstr ""

msgid "Command `{}` has not been used yet"
msgstr ""

msgid ""
"Unable to search for provided image, SauceNAO returned {status} ({message})\n"
"This is server issue, try again later."
msgstr ""

msgid "Unable to search for provided image, SauceNAO returned {status} ({message})"
msgstr ""

msgid "Unable to get image: {}"
msgstr ""

msgid "Unable to search for provided image, trace.moe returned {status} ({message})"
msgstr ""

@@ -0,0 +1,119 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2019-05-19 21:38+0400\n"
"PO-Revision-Date: 2019-05-19 21:43+0400\n"
"Last-Translator: Максим Невзоров\n"
"Language-Team: \n"
"Language: ru_RU\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: redgettext 2.2\n"
"X-Generator: Poedit 2.2.2\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"

msgid "No images provided."
msgstr "Не указано никаких изображений."

msgid "No Images found in recent history."
msgstr "Изображений в последних сообщениях не обнаружено."

msgid "(Anime) Reverse Image Search"
msgstr "Поиск (аниме) по изображению"

msgid "Reverse search image via SauceNAO"
msgstr "Поиск по изображению через SauceNAO"

msgid "Similarity: {}%"
msgstr "Схожесть: {}%"

msgid "Part/Episode: {}"
msgstr "Часть/Эпизод: {}"

msgid "Year: {}"
msgstr "Год: {}"

msgid "Est. Time: {}"
msgstr "Пр. время: {}"

msgid "Via SauceNAO • Page {}/{}"
msgstr "Через SauceNAO • Страница {}/{}"

msgid "Set API key for SauceNAO"
msgstr "Установить API ключ для SauceNAO"

msgid ""
"To get SauceNAO API key:\n"
"1. [Login](https://saucenao.com/user.php) to your SauceNAO account\n"
"2. Go to [Search > api](https://saucenao.com/user.php?page=search-api) "
"page\n"
"3. Copy your *api key*\n"
"4. Use `{}set api reverseimagesearch saucenao,<your_api_key>`\n"
"\n"
"Note: These tokens are sensitive and should only be used in a private "
"channel\n"
"or in DM with the bot."
msgstr ""
"Для получения ключа API SauceNAO:\n"
"1. [Войдите](https://saucenao.com/user.php) в ваш аккаунт SauceNAO\n"
"2. Перейдите на страницу [Search > api](https://saucenao.com/user.php?"
"page=search-api)\n"
"3. Скопируйте ваш ключ API в поле *api key*\n"
"4. Используйте `{}set api reverseimagesearch saucenao,<ваш_ключ_api>`\n"
"\n"
"Примечание: Эти ключи регистрозависимы и их настройка должна\n"
"\"производится только в приватном канале или в ЛС с ботом."

msgid ""
"Set API count of results count for SauceNAO\n"
"\n"
" 6 by default"
msgstr ""
"Установить количество результатов для API SauceNAO\n"
"\n"
" По умолчанию 6"

msgid "See how many requests are left"
msgstr "Посмотреть сколько запросов осталось"

msgid ""
"Remaining requests:\n"
"Short (30 seconds): {}/{}\n"
"Long: (24 hours): {}/{}"
msgstr ""
"Оставшихся запросов:\n"
"Короткосрочных: (30 секунд): {}/{}\n"
"Долгосрочных: (24 часа): {}/{}"

msgid "Command `{}` has not been used yet"
msgstr "Команда `{}` пока еще не использовалась"

msgid ""
"Unable to search for provided image, SauceNAO returned {status} "
"({message})\n"
"This is server issue, try again later."
msgstr ""
"Невозможно выполнить поиск по указанному изображению, SauceNAO вернул код "
"{status} ({message})\n"
"Эта проблема наблюдается на стороне сервера, попробуйте позже."

msgid ""
"Unable to search for provided image, SauceNAO returned {status} ({message})"
msgstr ""
"Невозможно выполнить поиск по указанному изображению, SauceNAO вернул код "
"{status} ({message})"

msgid "Unable to get image: {}"
msgstr "Невозможно получить изображение: {}"

msgid ""
"Unable to search for provided image, trace.moe returned {status} ({message})"
msgstr ""
"Невозможно выполнить поиск по указанному изображению, trace.moe вернул код "
"{status} ({message})"

0 comments on commit a89d726

Please sign in to comment.
You can’t perform that action at this time.