mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 22:27:28 +00:00
Added ability to switch order:random tag for another order:
This commit is contained in:
parent
ba78274b36
commit
8eee78a70d
1 changed files with 15 additions and 13 deletions
|
@ -569,12 +569,14 @@ class MsG:
|
||||||
if tag == 'swf' or tag == 'webm' or tag in blacklist:
|
if tag == 'swf' or tag == 'webm' or tag in blacklist:
|
||||||
raise exc.TagBlacklisted(tag)
|
raise exc.TagBlacklisted(tag)
|
||||||
|
|
||||||
|
order = [tag for tag in tags if 'order:' in tag]
|
||||||
|
if order:
|
||||||
|
order = order[0]
|
||||||
|
tags.remove(order)
|
||||||
|
else:
|
||||||
|
order = 'order:random'
|
||||||
|
|
||||||
# Checks for blacklisted tags in endpoint blacklists - try/except is for continuing the parent loop
|
# Checks for blacklisted tags in endpoint blacklists - try/except is for continuing the parent loop
|
||||||
order = False
|
|
||||||
for tag in tags:
|
|
||||||
if 'order:' in tag:
|
|
||||||
order = True
|
|
||||||
tags = ','.join(['order:random'] + tags) if not order else ','.join(tags)
|
|
||||||
posts = {}
|
posts = {}
|
||||||
temposts = len(posts)
|
temposts = len(posts)
|
||||||
empty = 0
|
empty = 0
|
||||||
|
@ -582,7 +584,7 @@ class MsG:
|
||||||
while len(posts) < limit:
|
while len(posts) < limit:
|
||||||
if c == limit * 5 + self.LIMIT:
|
if c == limit * 5 + self.LIMIT:
|
||||||
raise exc.Timeout
|
raise exc.Timeout
|
||||||
request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': tags, 'limit': int(self.LIMIT * limit)}, json=True)
|
request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join([order] + tags), 'limit': int(self.LIMIT * limit)}, json=True)
|
||||||
if len(request) == 0:
|
if len(request) == 0:
|
||||||
raise exc.NotFound(formatter.tostring(tags))
|
raise exc.NotFound(formatter.tostring(tags))
|
||||||
if len(request) < limit:
|
if len(request) < limit:
|
||||||
|
@ -613,7 +615,7 @@ class MsG:
|
||||||
c += 1
|
c += 1
|
||||||
|
|
||||||
if posts:
|
if posts:
|
||||||
return posts
|
return posts, order
|
||||||
else:
|
else:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
|
@ -788,14 +790,14 @@ class MsG:
|
||||||
|
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
|
|
||||||
posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit)
|
posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit)
|
||||||
keys = list(posts.keys())
|
keys = list(posts.keys())
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color)
|
title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color)
|
||||||
embed.set_image(url=values[c - 1]['url'])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, random=True),
|
embed.set_author(name=formatter.tostring(tags, order=order),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)),
|
embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)),
|
||||||
icon_url=self._get_score(values[c - 1]['score']))
|
icon_url=self._get_score(values[c - 1]['score']))
|
||||||
|
@ -936,12 +938,12 @@ class MsG:
|
||||||
|
|
||||||
await dest.trigger_typing()
|
await dest.trigger_typing()
|
||||||
|
|
||||||
posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit)
|
posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit)
|
||||||
|
|
||||||
for ident, post in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url'])
|
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, random=True),
|
embed.set_author(name=formatter.tostring(tags, order=order),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=post['score'], icon_url=self._get_score(post['score']))
|
text=post['score'], icon_url=self._get_score(post['score']))
|
||||||
|
@ -990,12 +992,12 @@ class MsG:
|
||||||
|
|
||||||
await dest.trigger_typing()
|
await dest.trigger_typing()
|
||||||
|
|
||||||
posts = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit)
|
posts, order = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit)
|
||||||
|
|
||||||
for ident, post in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url'])
|
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, random=True),
|
embed.set_author(name=formatter.tostring(tags, order=order),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=post['score'], icon_url=self._get_score(post['score']))
|
text=post['score'], icon_url=self._get_score(post['score']))
|
||||||
|
|
Loading…
Reference in a new issue