Exemple #1
0
	async def run(self, t):
		"""Passively deepfries random images."""
		#CHECKS
		if t.author.bot:
			return
		if not t.attachments:
			return
		if t.attachments[0].size > MAX_SIZE:
			return
		if t.guild is None:
			return
		if any([t.content.startswith(x) for x in await self.bot.get_prefix(t)]):
			return
		ext = t.attachments[0].url.split('.')[-1]
		if ext in self.imagetypes:
			isgif = False
		if ext in self.videotypes:
			isgif = True
		#GUILD SETTINGS
		vfry = await self.config.guild(t.guild).fryChance()
		vnuke = await self.config.guild(t.guild).nukeChance()
		#NUKE
		if vnuke != 0:
			l = randint(1,vnuke)
			if l == 1:
				temp = BytesIO()
				temp.filename = f'nuked.{ext}'
				await t.attachments[0].save(temp)
				temp.seek(0)
				img = Image.open(temp)
				if isgif:
					task = functools.partial(self._videonuke, img)
				else:
					task = functools.partial(self._nuke, img)
				task = self.bot.loop.run_in_executor(None, task)
				try:
					image = await asyncio.wait_for(task, timeout=60)
				except asyncio.TimeoutError:
					return
				await t.channel.send(file=discord.File(image))
				return #prevent a nuke and a fry
		#FRY
		if vfry != 0:
			l = randint(1,vfry)
			if l == 1:
				temp = BytesIO()
				temp.filename = f'deepfried.{ext}'
				await t.attachments[0].save(temp)
				temp.seek(0)
				img = Image.open(temp)
				if isgif:
					task = functools.partial(self._videofry, img)
				else:
					task = functools.partial(self._fry, img)
				task = self.bot.loop.run_in_executor(None, task)
				try:
					image = await asyncio.wait_for(task, timeout=60)
				except asyncio.TimeoutError:
					return
				await t.channel.send(file=discord.File(image))
Exemple #2
0
 async def run(self, t):
     """Passively deepfries random images."""
     if t.author.bot:
         return
     if not t.attachments:
         return
     if t.guild is None:
         return
     v = await self.config.guild(t.guild).chance()
     if t.attachments[0].url.split(".")[-1] not in self.imagetypes:
         return
     if t.attachments[0].size > MAX_SIZE:
         return
     if v == 0:
         return
     if not any(
         [t.content.startswith(x) for x in await self.bot.get_prefix(t)]):
         l = randint(1, v)
         if l == 1:
             ext = t.attachments[0].url.split(".")[-1]
             temp = BytesIO()
             temp.filename = f"deepfried.{ext}"
             r = await t.attachments[0].save(temp)
             temp.seek(0)
             img = Image.open(temp)
             task = fuctools.partial(self._fry, img)
             task = self.bot.loop.run_in_executor(None, task)
             try:
                 image = await asyncio.wait_for(task, timeout=60)
             except asyncio.TimeoutError:
                 return
             await t.channel.send(file=discord.File(image))
         else:
             pass
Exemple #3
0
 def unit_iter(self):
     """Iterator over all the units in all the files in this zip file."""
     for dirname, filename in self.file_iter():
         strfile = BytesIO(self.archive.read("/".join((dirname, filename))))
         strfile.filename = filename
         store = factory.getobject(strfile)
         # TODO: don't regenerate all the storage objects
         yield from store.unit_iter()
Exemple #4
0
 def get_files(self, url):
     album_id = url.split('/')[-1]
     images = self._client.get_album_images(album_id)
     for image in images:
         r = self._requests.get(image.link)
         file = BytesIO(r.content)
         file.filename = image.link.split('/')[-1]
         file.mimetype = r.headers.get('Content-Type')
         yield file
Exemple #5
0
def create_fake_image(mock_django_file_storage, settings):  # noqa
    data = BytesIO()
    image_name = 'image.png'
    Image.new('RGB', (40, 40)).save(data, 'PNG')
    data.filename = image_name
    data.seek(0)
    image_file = SimpleUploadedFile(image_name,
                                    data.getvalue(),
                                    content_type='image/png')
    return image_file
Exemple #6
0
def df_to_parquet(
    df: pd.DataFrame,
    allow_truncated_timestamps: bool = True,
    filename: str = "file.parquet",
) -> BytesIO:
    """Transform a DataFrame in a parquet file in memory"""
    buffer = BytesIO()
    df.to_parquet(buffer,
                  allow_truncated_timestamps=allow_truncated_timestamps)
    buffer.seek(0)
    buffer.filename = filename
    return buffer
Exemple #7
0
 def post(self):
     if "modulemd" in self.data:
         handle = BytesIO(self.data["modulemd"].encode("utf-8"))
     else:
         handle = request.files["yaml"]
     if self.data.get("module_name"):
         handle.filename = self.data["module_name"]
     stream_name = self.data.get("module_stream", None)
     return submit_module_build_from_yaml(db.session,
                                          self.username,
                                          handle,
                                          self.data,
                                          stream=stream_name)
Exemple #8
0
 def modify_content(self, content):
     replace_results = re.findall(r'<img.*?src="(.*?)".*?/>', content)
     for _ in replace_results:
         if _[:4] == 'http':
             resp = requests.get(_)
             if resp.status_code == 200:
                 if 'Content-Type' in resp.headers.keys():
                     bio = BytesIO(resp.content)
                     bio.mimetype = resp.headers['Content-Type']
                     bio.filename = _.split('/')[-1]
                     img_url = self.file_upload(bio, 'modify_content')
                     content = content.replace(_, img_url)
     return content
     pass
Exemple #9
0
 def openinputfile(self, subfile):
     """returns a pseudo-file object for the given subfile"""
     subfilesrc = self.getsubfilesrc(subfile)
     inputfile = BytesIO(subfilesrc.encode())
     inputfile.filename = subfile
     return inputfile
Exemple #10
0
 async def on_message(self, msg):
     """Passively deepfries random images."""
     #CHECKS
     if msg.author.bot:
         return
     if not msg.attachments:
         return
     if msg.guild is None:
         return
     if await self.bot.cog_disabled_in_guild(self, msg.guild):
         return
     if not msg.channel.permissions_for(msg.guild.me).attach_files:
         return
     if any([
             msg.content.startswith(x)
             for x in await self.bot.get_prefix(msg)
     ]):
         return
     if msg.attachments[0].size > msg.guild.filesize_limit:
         return
     ext = msg.attachments[0].url.split('.')[-1].lower()
     if ext in self.imagetypes:
         isgif = False
     elif ext in self.videotypes:
         isgif = True
     else:
         return
     #GUILD SETTINGS
     vfry = await self.config.guild(msg.guild).fryChance()
     vnuke = await self.config.guild(msg.guild).nukeChance()
     #NUKE
     if vnuke != 0:
         l = randint(1, vnuke)
         if l == 1:
             temp = BytesIO()
             temp.filename = f'nuked.{ext}'
             await msg.attachments[0].save(temp)
             temp.seek(0)
             img = Image.open(temp)
             duration = None
             if isgif:
                 if 'duration' in img.info:
                     duration = img.info['duration']
                 task = functools.partial(self._videonuke, img, duration)
             else:
                 img = img.convert('RGB')
                 task = functools.partial(self._nuke, img)
             task = self.bot.loop.run_in_executor(None, task)
             try:
                 image = await asyncio.wait_for(task, timeout=60)
             except asyncio.TimeoutError:
                 return
             await msg.channel.send(file=discord.File(image))
             return  #prevent a nuke and a fry
     #FRY
     if vfry != 0:
         l = randint(1, vfry)
         if l == 1:
             temp = BytesIO()
             temp.filename = f'deepfried.{ext}'
             await msg.attachments[0].save(temp)
             temp.seek(0)
             img = Image.open(temp)
             duration = None
             if isgif:
                 if 'duration' in img.info:
                     duration = img.info['duration']
                 task = functools.partial(self._videofry, img, duration)
             else:
                 img = img.convert('RGB')
                 task = functools.partial(self._fry, img)
             task = self.bot.loop.run_in_executor(None, task)
             try:
                 image = await asyncio.wait_for(task, timeout=60)
             except asyncio.TimeoutError:
                 return
             await msg.channel.send(file=discord.File(image))