comparison pixivimageposter.py @ 22:9782a1f6c1a6

Update and rename randomimageposter.py to pixivimageposter.py this code is very readable trust me committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Fri, 09 Apr 2021 23:09:16 -0400
parents
children 7eccf59ddec0
comparison
equal deleted inserted replaced
21:358cad883bc3 22:9782a1f6c1a6
1 import glob, os, random, discord
2 from discord.ext import commands
3
4 client = commands.Bot(command_prefix = '!!')
5
6 @client.event
7 async def on_ready():
8 print("Ready!")
9
10 @client.command()
11 async def pixiv(ctx):
12 files = glob.glob("*.png")
13 files.extend(glob.glob("*.jpg"))
14 files.extend(glob.glob("*.gif"))
15 file = random.choice(files)
16 '''
17 filenames are the default to pixivutil2, being
18 "(id)_p(imgnumber) - (title).(ext)"
19
20 link1 takes "file" and splits it with the character "_", giving you the id and the rest of the file
21
22 link2 takes the rest of the file and splits it with a space, giving you the image number and other stuff we don't need
23 it then removes "p" which just gets in the way, converts it to an integer, and adds 1 to it because pixivutil2 uses an initial zero in numbering
24 '''
25 link1 = file.split("_", 1)[0]
26 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', '')) + 1
27 await ctx.send("https://pixiv.net/en/artworks/" + link1 + ", Image " + str(link2),file = discord.File(file))
28
29 client.run("token")