2024-11-04 17:11:13 +03:00
|
|
|
import asyncio
|
|
|
|
import aiohttp
|
|
|
|
import next
|
|
|
|
import creds
|
2024-11-04 18:28:47 +03:00
|
|
|
from creds import gimgsettings
|
2024-11-04 17:11:13 +03:00
|
|
|
from next.ext import commands
|
|
|
|
from api import get_img
|
|
|
|
|
|
|
|
class Client(commands.CommandsClient):
|
|
|
|
async def get_prefix(self, message: next.Message):
|
|
|
|
return "!"
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
async def gimg(self, ctx: commands.Context, *args):
|
2024-11-04 17:34:13 +03:00
|
|
|
"""[count of images, 1 by default] - get image from Google Images"""
|
2024-11-04 17:11:13 +03:00
|
|
|
|
|
|
|
arg = ""
|
|
|
|
|
|
|
|
banned = False
|
|
|
|
if gimgsettings['usestoplist'] == True:
|
|
|
|
for banword in gimgsettings['stoplist']:
|
|
|
|
if banword in arg:
|
|
|
|
banned = True
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2024-11-04 17:34:13 +03:00
|
|
|
try:
|
|
|
|
count = int(args[0])
|
|
|
|
for word in range(1, len(args)):
|
|
|
|
arg += f"{args[word]} "
|
|
|
|
except:
|
|
|
|
count = 1
|
|
|
|
for word in args:
|
|
|
|
arg += f"{word} "
|
|
|
|
|
|
|
|
|
2024-11-04 18:28:47 +03:00
|
|
|
if count > 10:
|
2024-11-04 17:34:13 +03:00
|
|
|
toomanyimages = True
|
|
|
|
else:
|
|
|
|
toomanyimages = False
|
|
|
|
|
|
|
|
if toomanyimages == False and banned == False:
|
2024-11-04 17:11:13 +03:00
|
|
|
try:
|
2024-11-04 17:34:13 +03:00
|
|
|
url = get_img(arg, count) # requesting image
|
2024-11-04 17:11:13 +03:00
|
|
|
await ctx.send(f"Search query: {arg}\n{url}") # sending image via embed
|
|
|
|
except IndexError:
|
|
|
|
await ctx.send("No images found")
|
2024-11-04 17:34:13 +03:00
|
|
|
elif banned == True:
|
2024-11-04 17:11:13 +03:00
|
|
|
await ctx.send(f"Your search query contains banned words")
|
2024-11-04 17:34:13 +03:00
|
|
|
elif toomanyimages == True:
|
|
|
|
await ctx.send(f"You requested too many images (>10)")
|
2024-11-04 17:11:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
client = Client(session, creds.bot)
|
2024-11-04 18:28:47 +03:00
|
|
|
print("Running GImages")
|
2024-11-04 17:11:13 +03:00
|
|
|
await client.start()
|
|
|
|
|
|
|
|
asyncio.run(main())
|