Mercurial > codedump
comparison pixivimageposter.py @ 40:2aa9614cb39a
flake8
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 21 Jun 2021 15:16:15 -0400 |
parents | 7eccf59ddec0 |
children |
comparison
equal
deleted
inserted
replaced
39:a93c352af05e | 40:2aa9614cb39a |
---|---|
1 import glob, os, random, discord | 1 import glob |
2 import random | |
3 import discord | |
2 from discord.ext import commands | 4 from discord.ext import commands |
3 | 5 |
4 help_command = commands.DefaultHelpCommand(no_category="Commands") | 6 help_command = commands.DefaultHelpCommand(no_category="Commands") |
5 client = commands.Bot(command_prefix = '!!',help_command = help_command) | 7 client = commands.Bot(command_prefix='!!', help_command=help_command) |
8 | |
6 | 9 |
7 @client.event | 10 @client.event |
8 async def on_ready(): | 11 async def on_ready(): |
9 print("Ready!") | 12 print("Ready!") |
10 | 13 |
11 @client.command(help = "Posts a random image from my pixiv bookmarks") | 14 |
15 @client.command(help="Posts a random image from my pixiv bookmarks") | |
12 async def pixiv(ctx): | 16 async def pixiv(ctx): |
13 files = glob.glob("*.png") | 17 files = glob.glob("*.png") |
14 files.extend(glob.glob("*.jpg")) | 18 files.extend(glob.glob("*.jpg")) |
15 files.extend(glob.glob("*.gif")) | 19 files.extend(glob.glob("*.gif")) |
16 file = random.choice(files) | 20 file = random.choice(files) |
17 ''' | 21 ''' |
18 filenames are the default to pixivutil2, being | 22 filenames are the default to pixivutil2, being |
19 "(id)_p(imgnumber) - (title).(ext)" | 23 "(id)_p(imgnumber) - (title).(ext)" |
20 | 24 |
21 link1 takes "file" and splits it with the character "_", giving you the id and the rest of the file | 25 link1 takes "file" and splits it with the character "_", |
26 giving you the id and the rest of the file | |
22 | 27 |
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 | 28 link2 takes the rest of the file and splits it with a space, |
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 | 29 giving you the image number and other stuff we don't need |
30 it then removes "p" which just gets in the way, converts it to an integer, | |
31 and adds 1 to it because pixivutil2 uses an initial zero in numbering | |
25 ''' | 32 ''' |
26 link1 = file.split("_", 1)[0] | 33 link1 = file.split("_", 1)[0] |
27 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', ''))+1 | 34 link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', ''))+1 |
28 await ctx.send("https://pixiv.net/member_illust.php?mode=medium&illust_id=" + link1 + ", Image " + str(link2),file = discord.File(file)) | 35 await ctx.send(f"https://pixiv.net/member_illust.php?mode=medium&illust_id={link1}, Image {str(link2)}", file=discord.File(file)) |
29 | 36 |
30 client.run("token") | 37 client.run("token") |