Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from PIL import Image
- import random
- import requests
- import os
- from copy import deepcopy
- from urllib.request import urlopen
- from .utils.dataIO import dataIO
- from .utils import checks, chat_formatting as cf
- default_settings = {
- "authorlist": [
- "115946460419194889",
- ],
- }
- class wasted:
- """Wasted..."""
- def __init__(self, bot):
- self.bot = bot
- self.author_path = "data/wasted/author.json"
- self.author = dataIO.load_json(self.author_path)
- @commands.command(pass_context=True)
- async def wasted(self, ctx, userName: discord.User):
- channel = ctx.message.channel
- author = ctx.message.author
- if author.id in self.author["authorlist"]:
- if userName.id == "115946460419194889":
- avatarurl = author.avatar_url
- else:
- avatarurl = userName.avatar_url
- avatar1z = Image.open(requests.get(avatarurl, stream=True).raw)
- resolution = (200, 200)
- avatar1 = avatar1z.resize(resolution, Image.ANTIALIAS)
- wasted = Image.open('data/wasted/wasted.png')
- text_img = Image.new('RGBA', (200,200), (0, 0, 0, 0))
- text_img.paste(avatar1, (0,0))
- text_img.paste(wasted, (0,0), mask=wasted)
- text_img.save("data/wasted/image.png", format="png")
- with open('data/wasted/image.png', 'rb') as f:
- await self.bot.send_file(channel, f)
- if os.path.isfile("data/wasted/image.png"):
- os.remove("data/wasted/image.png")
- else:
- return
- else:
- 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)"
- await self.bot.say(messages)
- @commands.command(pass_context=True)
- @checks.serverowner_or_permissions(administrator=True)
- async def allow(self, ctx: commands.Context, userName: discord.User):
- """autorise un utilisateur a utiliser le /wasted .
- (/disallow pour retirer l'autorisation.
- """
- authorized = userName.id
- if authorized not in self.author["authorlist"]:
- self.author["authorlist"].append(authorized)
- dataIO.save_json(self.author_path, self.author)
- messages = "L'utilisateur a été autorisé."
- else:
- messages = "L'utilisateur est déjà autorisé."
- await self.bot.say(messages)
- @commands.command(pass_context=True)
- @checks.serverowner_or_permissions(administrator=True)
- async def disallow(self, ctx: commands.Context, userName: discord.User):
- """retire le droit a un utilisateur d'utiliser le /wasted ."""
- unauthorized = userName.id
- if unauthorized in self.author["authorlist"]:
- self.author["authorlist"].remove(unauthorized)
- dataIO.save_json(self.author_path, self.author)
- messages = "L'utilisateur a perdu le droit d'utiliser /wasted"
- else:
- messages = "L'utilisateur est déjà interdit d'utilisation de /wasted."
- await self.bot.say(messages)
- @commands.command(pass_context=True)
- async def someone(self, ctx):
- userlist = random.choices([member.id for member in ctx.message.server.members])
- userselect = "<@{}>".format(" ".join(userlist))
- await self.bot.say(userselect)
- def check_folders():
- if not os.path.exists("data/wasted"):
- print("Creating data/wasted directory...")
- os.makedirs("data/wasted")
- def check_files():
- f = "data/wasted/author.json"
- if not dataIO.is_valid_json(f):
- print("Creating data/wasted/author.json...")
- dataIO.save_json(f, deepcopy(default_settings))
- def setup(bot):
- check_folders()
- check_files()
- bot.add_cog(wasted(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement