feat(command|Useful|cb): add image generator for credit cards

This commit is contained in:
Romain J 2020-01-15 01:23:53 +01:00
parent b7ed8ffae7
commit ad24e4ba86
6 changed files with 44 additions and 4 deletions

1
.gitignore vendored
View file

@ -13,6 +13,7 @@ private.py
# other
logs/tuxbot.log
utils/images/tmp/*
# Byte-compiled / optimized / DLL files
__pycache__/

4
bot.py
View file

@ -20,7 +20,7 @@ Je suis TuxBot, le bot qui vit de l'OpenSource ! ;)
"""
build = git.Repo(search_parent_directories=True).head.object.hexsha
version = (2, 1, 0)
version = (2, 0, 0)
log = logging.getLogger(__name__)
@ -73,7 +73,7 @@ class TuxBot(commands.AutoShardedBot):
self.fallbacks = Config('./configs/fallbacks.cfg')
self.cluster = self.fallbacks.find('True', key='This', first=True)
self.version = Version(*version, pre_release='rc1', build=build)
self.version = Version(*version, pre_release='rc2', build=build)
self.owner: discord.User = discord.User
self.owners: List[discord.User] = []

View file

@ -8,6 +8,11 @@ import re
import socket
import time
from socket import AF_INET6
from io import BytesIO
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageOps
import aiohttp
import discord
@ -358,11 +363,44 @@ class Useful(commands.Cog):
@_cb.command(name='generate', aliases=['new', 'get'], category='misc')
async def _cb_generate(self, ctx: commands.Context):
await ctx.channel.trigger_typing()
number = random.randint(4000_0000_0000_0000, 5999_9999_9999_9999)
while not self.luhn_checker(number):
number = random.randint(4000_0000_0000_0000, 5999_9999_9999_9999)
number = str(number)
cvv = ''.join(random.choice("abcdefghij") for _ in range(3))
await ctx.send(''.join(str(digit) for digit in str(number)))
with Image.open("utils/images/blank_credit_card.png") as blank:
cc_font = ImageFont.truetype('utils/fonts/credit_card.ttf', 26)
user_font = ImageFont.truetype('utils/fonts/credit_card.ttf', 20)
draw = ImageDraw.Draw(blank)
cvv_text = Image.new('L', (500, 50))
cvv_draw = ImageDraw.Draw(cvv_text)
cvv_draw.text((0, 0), cvv, font=user_font, fill=255)
cvv_rotated = cvv_text.rotate(23, expand=1)
draw.text(
(69, 510),
' '.join([number[i:i+4] for i in range(0, len(number), 4)]),
(210, 210, 210),
font=cc_font
)
draw.text(
(69, 550),
ctx.author.name.upper(),
(210, 210, 210),
font=user_font
)
blank.paste(ImageOps.colorize(cvv_rotated, (0, 0, 0), (0, 0, 0)), (470, 0), cvv_rotated)
output = BytesIO()
blank.save(output, 'png')
output.seek(0)
await ctx.send(file=discord.File(fp=output, filename="credit_card.png"))
def setup(bot: TuxBot):

View file

@ -8,4 +8,5 @@ psycopg2
configparser
psutil
tcp_latency
yarl
yarl
pillow

BIN
utils/fonts/credit_card.ttf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB