Mercurial > codedump
annotate 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 | 
| rev | line source | 
|---|---|
| 22 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 1 import glob, os, random, discord | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 2 from discord.ext import commands | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 3 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 4 client = commands.Bot(command_prefix = '!!') | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 5 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 6 @client.event | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 7 async def on_ready(): | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 8 print("Ready!") | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 9 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 10 @client.command() | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 11 async def pixiv(ctx): | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 12 files = glob.glob("*.png") | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 13 files.extend(glob.glob("*.jpg")) | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 14 files.extend(glob.glob("*.gif")) | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 15 file = random.choice(files) | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 16 ''' | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 17 filenames are the default to pixivutil2, being | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 18 "(id)_p(imgnumber) - (title).(ext)" | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 19 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 20 link1 takes "file" and splits it with the character "_", giving you the id and the rest of the file | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 21 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 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 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 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 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 24 ''' | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 25 link1 = file.split("_", 1)[0] | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 26 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', '')) + 1 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 27 await ctx.send("https://pixiv.net/en/artworks/" + link1 + ", Image " + str(link2),file = discord.File(file)) | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 28 | 
| 
9782a1f6c1a6
Update and rename randomimageposter.py to pixivimageposter.py
 Paper <37962225+mrpapersonic@users.noreply.github.com> parents: diff
changeset | 29 client.run("token") | 
