annotate pixivimageposter.py @ 105:bf6d6304f6f7

Add files via upload committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Tue, 18 Oct 2022 17:32:24 -0400
parents 2aa9614cb39a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
1 import glob
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
2 import random
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
3 import discord
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
4 from discord.ext import commands
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
5
24
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
6 help_command = commands.DefaultHelpCommand(no_category="Commands")
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
7 client = commands.Bot(command_prefix='!!', help_command=help_command)
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
8
22
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.event
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
11 async def on_ready():
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
12 print("Ready!")
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
13
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
14
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
15 @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
16 async def pixiv(ctx):
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
17 files = glob.glob("*.png")
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
18 files.extend(glob.glob("*.jpg"))
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
19 files.extend(glob.glob("*.gif"))
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
20 file = random.choice(files)
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 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
23 "(id)_p(imgnumber) - (title).(ext)"
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
24
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
25 link1 takes "file" and splits it with the character "_",
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
26 giving you the id and the rest of the file
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
27
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
28 link2 takes the rest of the file and splits it with a space,
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
29 giving you the image number and other stuff we don't need
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
30 it then removes "p" which just gets in the way, converts it to an integer,
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
31 and adds 1 to it because pixivutil2 uses an initial zero in numbering
22
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
32 '''
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
33 link1 = file.split("_", 1)[0]
24
7eccf59ddec0 Update pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 22
diff changeset
34 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', ''))+1
40
Paper <mrpapersonic@gmail.com>
parents: 24
diff changeset
35 await ctx.send(f"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
36
9782a1f6c1a6 Update and rename randomimageposter.py to pixivimageposter.py
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
37 client.run("token")