# HG changeset patch # User Paper <37962225+mrpapersonic@users.noreply.github.com> # Date 1618024156 14400 # Node ID 9782a1f6c1a6c8cd2396f4ed36c3bc0c0a9db017 # Parent 358cad883bc32d3de4701b388d68c8ea49e8fdac Update and rename randomimageposter.py to pixivimageposter.py this code is very readable trust me committer: GitHub diff -r 358cad883bc3 -r 9782a1f6c1a6 pixivimageposter.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pixivimageposter.py Fri Apr 09 23:09:16 2021 -0400 @@ -0,0 +1,29 @@ +import glob, os, random, discord +from discord.ext import commands + +client = commands.Bot(command_prefix = '!!') + +@client.event +async def on_ready(): + print("Ready!") + +@client.command() +async def pixiv(ctx): + files = glob.glob("*.png") + files.extend(glob.glob("*.jpg")) + files.extend(glob.glob("*.gif")) + file = random.choice(files) + ''' + filenames are the default to pixivutil2, being + "(id)_p(imgnumber) - (title).(ext)" + + link1 takes "file" and splits it with the character "_", giving you the id and the rest of the file + + 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 + 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 + ''' + link1 = file.split("_", 1)[0] + link2 = int(file.split("_", 1)[1].split(" ", 1)[0].replace('p', '')) + 1 + await ctx.send("https://pixiv.net/en/artworks/" + link1 + ", Image " + str(link2),file = discord.File(file)) + +client.run("token") diff -r 358cad883bc3 -r 9782a1f6c1a6 randomimageposter.py --- a/randomimageposter.py Fri Apr 09 21:49:49 2021 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -import glob, os, random, discord -from discord.ext import commands - -client = commands.Bot(command_prefix = '!!') - -@client.event -async def on_ready(): - print("Ready!") - -@client.command() -async def post(ctx): - files = glob.glob("*.png") - files.extend(glob.glob("*.jpg")) - files.extend(glob.glob("*.gif")) - file = random.choice(files) - await ctx.send(file=discord.File(file)) - -client.run("PUT TOKEN HERE")