annotate pixivimageposter.py @ 27:0f81a012ead6

minor inconvenience it wouldn't work with it anyway committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Sat, 15 May 2021 01:14:13 -0400
parents 7eccf59ddec0
children 2aa9614cb39a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
24
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
4 help_command = commands.DefaultHelpCommand(no_category="Commands")
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
5 client = commands.Bot(command_prefix = '!!',help_command = help_command)
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
6
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
7 @client.event
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
8 async def on_ready():
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
9 print("Ready!")
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
10
24
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
11 @client.command(help = "Posts a random image from my pixiv bookmarks")
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
12 async def pixiv(ctx):
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
13 files = glob.glob("*.png")
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
14 files.extend(glob.glob("*.jpg"))
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
15 files.extend(glob.glob("*.gif"))
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
16 file = random.choice(files)
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
17 '''
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
18 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
19 "(id)_p(imgnumber) - (title).(ext)"
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
20
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
21 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
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
23 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
24 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
25 '''
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
26 link1 = file.split("_", 1)[0]
24
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
27 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', ''))+1
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
28 await ctx.send("https://pixiv.net/member_illust.php?mode=medium&illust_id=" + link1 + ", Image " + str(link2),file = discord.File(file))
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
29
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
30 client.run("token")