Add files via upload
This commit is contained in:
parent
d7b9566c77
commit
6ccc44a675
3 changed files with 67 additions and 0 deletions
12
api.py
Normal file
12
api.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from google_images_search import GoogleImagesSearch
|
||||
import creds
|
||||
|
||||
gis = GoogleImagesSearch(creds.api, creds.cx)
|
||||
|
||||
def get_img(query):
|
||||
gis.search(search_params= {
|
||||
'q': query,
|
||||
'safe': 'active',
|
||||
'num': 1,
|
||||
})
|
||||
return gis.results()[0].url
|
5
creds.py
Normal file
5
creds.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
bot = "" # bot api-key from next
|
||||
api = "" # google api key
|
||||
cx = "" # google cx
|
||||
|
||||
# tutorial for api&cx - https://pypi.org/project/Google-Images-Search/
|
50
main.py
Normal file
50
main.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import asyncio
|
||||
import aiohttp
|
||||
import next
|
||||
import creds
|
||||
from next.ext import commands
|
||||
from api import get_img
|
||||
|
||||
gimgsettings = {
|
||||
"usestoplist": True,
|
||||
"stoplist": ["пенис", "хуй", "шлюха", "penis", "pride", 'lgbt', "лгбт", "прайд", "dick", "1488", "swastika", "свастика", "свастон"]
|
||||
}
|
||||
|
||||
class Client(commands.CommandsClient):
|
||||
async def get_prefix(self, message: next.Message):
|
||||
return "!"
|
||||
|
||||
@commands.command()
|
||||
async def gimg(self, ctx: commands.Context, *args):
|
||||
"""Get image from Google Images"""
|
||||
|
||||
arg = ""
|
||||
|
||||
for word in args: # very stupid way to get args
|
||||
arg += f"{word} "
|
||||
|
||||
banned = False
|
||||
if gimgsettings['usestoplist'] == True:
|
||||
for banword in gimgsettings['stoplist']:
|
||||
if banword in arg:
|
||||
banned = True
|
||||
else:
|
||||
pass
|
||||
|
||||
if banned == False:
|
||||
try:
|
||||
url = get_img(arg) # requesting image
|
||||
await ctx.send(f"Search query: {arg}\n{url}") # sending image via embed
|
||||
except IndexError:
|
||||
await ctx.send("No images found")
|
||||
else:
|
||||
await ctx.send(f"Your search query contains banned words")
|
||||
|
||||
|
||||
async def main():
|
||||
async with aiohttp.ClientSession() as session:
|
||||
client = Client(session, creds.bot)
|
||||
print("Running GIMG")
|
||||
await client.start()
|
||||
|
||||
asyncio.run(main())
|
Loading…
Reference in a new issue