Advertisement
Yoloswagger

wasted.py

Jun 22nd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.98 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4. from PIL import Image
  5. import random
  6. import requests
  7. import os
  8. from copy import deepcopy
  9. from urllib.request import urlopen
  10.  
  11. from .utils.dataIO import dataIO
  12. from .utils import checks, chat_formatting as cf
  13.  
  14. default_settings = {
  15.     "authorlist": [
  16.         "115946460419194889",
  17.         ],
  18.     }
  19. class wasted:
  20.     """Wasted..."""
  21.     def __init__(self, bot):
  22.         self.bot = bot
  23.         self.author_path = "data/wasted/author.json"
  24.         self.author = dataIO.load_json(self.author_path)
  25.        
  26.     @commands.command(pass_context=True)
  27.     async def wasted(self, ctx, userName: discord.User):
  28.         channel = ctx.message.channel
  29.         author = ctx.message.author
  30.         if author.id in self.author["authorlist"]:
  31.             if userName.id == "115946460419194889":
  32.                 avatarurl = author.avatar_url
  33.             else:    
  34.                 avatarurl = userName.avatar_url
  35.             avatar1z = Image.open(requests.get(avatarurl, stream=True).raw)
  36.             resolution = (200, 200)
  37.             avatar1 = avatar1z.resize(resolution, Image.ANTIALIAS)
  38.             wasted = Image.open('data/wasted/wasted.png')
  39.             text_img = Image.new('RGBA', (200,200), (0, 0, 0, 0))
  40.             text_img.paste(avatar1, (0,0))
  41.             text_img.paste(wasted, (0,0), mask=wasted)
  42.             text_img.save("data/wasted/image.png", format="png")
  43.            
  44.             with open('data/wasted/image.png', 'rb') as f:
  45.                 await self.bot.send_file(channel, f)
  46.             if os.path.isfile("data/wasted/image.png"):
  47.                 os.remove("data/wasted/image.png")
  48.             else:
  49.                 return
  50.         else:
  51.             messages = "Vous n'etes pas autorisé a utiliser cette commande, référez vous a un admin de votre serveur pour qu'il vous y autorise. (/allow)"
  52.            
  53.             await self.bot.say(messages)
  54.        
  55.     @commands.command(pass_context=True)
  56.     @checks.serverowner_or_permissions(administrator=True)
  57.     async def allow(self, ctx: commands.Context, userName: discord.User):
  58.         """autorise un utilisateur a utiliser le /wasted .
  59.  
  60.            (/disallow pour retirer l'autorisation.
  61.        """
  62.         authorized = userName.id
  63.         if authorized not in self.author["authorlist"]:
  64.             self.author["authorlist"].append(authorized)
  65.             dataIO.save_json(self.author_path, self.author)
  66.             messages = "L'utilisateur a été autorisé."
  67.         else:
  68.             messages = "L'utilisateur est déjà autorisé."
  69.         await self.bot.say(messages)
  70.        
  71.     @commands.command(pass_context=True)
  72.     @checks.serverowner_or_permissions(administrator=True)
  73.     async def disallow(self, ctx: commands.Context, userName: discord.User):
  74.         """retire le droit a un utilisateur d'utiliser le /wasted ."""
  75.         unauthorized = userName.id
  76.         if unauthorized in self.author["authorlist"]:
  77.             self.author["authorlist"].remove(unauthorized)
  78.             dataIO.save_json(self.author_path, self.author)
  79.             messages = "L'utilisateur a perdu le droit d'utiliser /wasted"
  80.         else:
  81.             messages = "L'utilisateur est déjà interdit d'utilisation de /wasted."
  82.  
  83.         await self.bot.say(messages)
  84.  
  85.     @commands.command(pass_context=True)
  86.     async def someone(self, ctx):
  87.         userlist = random.choices([member.id for member in ctx.message.server.members])
  88.         userselect = "<@{}>".format(" ".join(userlist))
  89.         await self.bot.say(userselect)
  90.        
  91. def check_folders():
  92.     if not os.path.exists("data/wasted"):
  93.         print("Creating data/wasted directory...")
  94.         os.makedirs("data/wasted")
  95.  
  96.  
  97. def check_files():
  98.     f = "data/wasted/author.json"
  99.     if not dataIO.is_valid_json(f):
  100.         print("Creating data/wasted/author.json...")
  101.         dataIO.save_json(f, deepcopy(default_settings))
  102.  
  103. def setup(bot):
  104.     check_folders()
  105.     check_files()
  106.     bot.add_cog(wasted(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement