Advertisement
maxim_shlyahtin

Untitled

Dec 4th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. import io
  2.  
  3. import aiohttp
  4. import discord
  5. from PIL import Image, ImageDraw, ImageFont
  6.  
  7. import password_generator
  8.  
  9.  
  10. class MyClient(discord.Client):
  11.     async def on_ready(self):
  12.         print('Logged in as')
  13.         print(self.user.name)
  14.         print(self.user.id)
  15.         print('------')
  16.  
  17.     async def on_message(self, message):
  18.         # we do not want the bot to reply to itself
  19.         if message.author.id == self.user.id:
  20.             return
  21.  
  22.         if message.content.startswith('Hello'):
  23.             await message.channel.send('Hello! \nUse prefix "$" before commands')
  24.  
  25.         if message.content.startswith('$picture'):
  26.             await message.channel.send('Choose option: url or file')
  27.  
  28.         if message.content.startswith('$url'):
  29.             await message.channel.send('Send your text and url')
  30.  
  31.             m = await self.wait_for('message')
  32.             cont = m.content.split()
  33.             async with aiohttp.ClientSession() as session:
  34.                 async with session.get(cont[-1]) as resp:
  35.                     if resp.status != 200:
  36.                         return await message.channel.send('Could not download file...')
  37.                     image_file = io.BytesIO(await resp.read())
  38.                     im, txt = Image.open(image_file), ' '.join(cont[:len(cont) - 1])
  39.                     font = ImageFont.truetype(
  40.                         r'S:\drive.google.com\file\d\1Ho7TxrfN8drGMTLf39Ozupys0leACmpk\view?usp=sharing', size=75)
  41.                     draw_text = ImageDraw.Draw(im)
  42.                     width, height = draw_text.textsize(txt, font=font)
  43.                     position: tuple = ((im.width - width) / 2, im.height - 100)
  44.                     draw_text.text(position, txt, font=font, fill='#FF0000')
  45.                     image_content = io.BytesIO()
  46.                     im.seek(0)
  47.                     im.save(image_content, format='JPEG')
  48.                     image_content.seek(0)
  49.                     await message.channel.send(file=discord.File(image_content, 'cool_image.png'))
  50.         if message.content.startswith('$file'):
  51.             await message.channel.send('Send your text and path to your image file')
  52.  
  53.             m = await self.wait_for('message')
  54.             cont = m.content.split()
  55.             im, txt, pallet = Image.open(cont[-1]), ' '.join(cont[:len(cont) - 1]), {'red': '#FF0000',
  56.                                                                                      'black': '#000000',
  57.                                                                                      'white': '#FFFFFF',
  58.                                                                                      'blue': '#0000FF',
  59.                                                                                      'grey': '#C0C0C0'}
  60.             font = ImageFont.truetype(r'C:\Users\MAX-Ryzen\Desktop\Roboto\Roboto-Black.ttf', size=75)
  61.             draw_text = ImageDraw.Draw(im)
  62.             width, height = draw_text.textsize(txt, font=font)
  63.             position: tuple = ((im.width - width) / 2, im.height - 100)
  64.             draw_text.text(position, txt, font=font, fill='#FF0000')
  65.             image_content = io.BytesIO()
  66.             im.seek(0)
  67.             im.save(image_content, format='JPEG')
  68.             image_content.seek(0)
  69.             await message.channel.send(file=discord.File(image_content, 'cool_image.png'))
  70.  
  71.  
  72. client = MyClient()
  73. client.run('NzgwNzQwMzE1NjMxODQ1Mzg2.X7zfFA.9xQQzz-DrgeLfkoSgBnw46zbi9g')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement