mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 22:27:28 +00:00
WIP auto e6 post command
This commit is contained in:
parent
30d558177e
commit
d86c695ee4
1 changed files with 29 additions and 5 deletions
|
@ -25,7 +25,7 @@ class MsG:
|
||||||
self.LIMIT = 100
|
self.LIMIT = 100
|
||||||
self.HISTORY_LIMIT = 100
|
self.HISTORY_LIMIT = 100
|
||||||
self.RATE_LIMIT = u.RATE_LIMIT
|
self.RATE_LIMIT = u.RATE_LIMIT
|
||||||
self.queue = asyncio.Queue()
|
self.qualiqueue = asyncio.Queue()
|
||||||
self.qualitifying = False
|
self.qualitifying = False
|
||||||
|
|
||||||
self.favorites = u.setdefault('cogs/favorites.pkl', {'tags': set(), 'posts': set()})
|
self.favorites = u.setdefault('cogs/favorites.pkl', {'tags': set(), 'posts': set()})
|
||||||
|
@ -36,11 +36,35 @@ class MsG:
|
||||||
if u.tasks['auto_qual']:
|
if u.tasks['auto_qual']:
|
||||||
for channel in u.tasks['auto_qual']:
|
for channel in u.tasks['auto_qual']:
|
||||||
temp = self.bot.get_channel(channel)
|
temp = self.bot.get_channel(channel)
|
||||||
self.bot.loop.create_task(self.queue_for_qualitification(temp))
|
self.bot.loop.create_task(self.qualiqueue_for_qualitification(temp))
|
||||||
print('AUTO-QUALITIFYING : #{}'.format(temp.name))
|
print('AUTO-QUALITIFYING : #{}'.format(temp.name))
|
||||||
self.bot.loop.create_task(self._qualitify())
|
self.bot.loop.create_task(self._qualitify())
|
||||||
self.qualitifying = True
|
self.qualitifying = True
|
||||||
|
|
||||||
|
async def get_post(self, channel):
|
||||||
|
post_request = await u.fetch('https://e621.net/post/index.json', json=True)
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def auto_post(self, ctx):
|
||||||
|
try:
|
||||||
|
if ctx.channel.id not in u.tasks['auto_post']:
|
||||||
|
u.tasks['auto_post'].append(ctx.channel.id)
|
||||||
|
u.dump(u.tasks, 'cogs/tasks.pkl')
|
||||||
|
self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel))
|
||||||
|
if not self.qualitifying:
|
||||||
|
self.bot.loop.create_task(self._qualitify())
|
||||||
|
self.qualitifying = True
|
||||||
|
|
||||||
|
print('AUTO-POSTING : #{}'.format(ctx.channel.name))
|
||||||
|
await ctx.send('**Auto-posting all images in {}.**'.format(ctx.channel.mention), delete_after=5)
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
else:
|
||||||
|
raise exc.Exists
|
||||||
|
|
||||||
|
except exc.Exists:
|
||||||
|
await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10)
|
||||||
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
# Tag search
|
# Tag search
|
||||||
@commands.command(aliases=['rel'], brief='e621 Search for related tags', description='e621 | NSFW\nReturn related tags for a number of given tags', usage='[related|rel]')
|
@commands.command(aliases=['rel'], brief='e621 Search for related tags', description='e621 | NSFW\nReturn related tags for a number of given tags', usage='[related|rel]')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
|
@ -351,7 +375,7 @@ class MsG:
|
||||||
|
|
||||||
async def _qualitify(self):
|
async def _qualitify(self):
|
||||||
while self.qualitifying:
|
while self.qualitifying:
|
||||||
message = await self.queue.get()
|
message = await self.qualiqueue.get()
|
||||||
|
|
||||||
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
||||||
try:
|
try:
|
||||||
|
@ -402,7 +426,7 @@ class MsG:
|
||||||
try:
|
try:
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
message = await self.bot.wait_for('message', check=check)
|
message = await self.bot.wait_for('message', check=check)
|
||||||
await self.queue.put(message)
|
await self.qualiqueue.put(message)
|
||||||
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
|
@ -420,7 +444,7 @@ class MsG:
|
||||||
if ctx.channel.id not in u.tasks['auto_qual']:
|
if ctx.channel.id not in u.tasks['auto_qual']:
|
||||||
u.tasks['auto_qual'].append(ctx.channel.id)
|
u.tasks['auto_qual'].append(ctx.channel.id)
|
||||||
u.dump(u.tasks, 'cogs/tasks.pkl')
|
u.dump(u.tasks, 'cogs/tasks.pkl')
|
||||||
self.bot.loop.create_task(self.queue_for_qualitification(ctx.channel))
|
self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel))
|
||||||
if not self.qualitifying:
|
if not self.qualitifying:
|
||||||
self.bot.loop.create_task(self._qualitify())
|
self.bot.loop.create_task(self._qualitify())
|
||||||
self.qualitifying = True
|
self.qualitifying = True
|
||||||
|
|
Loading…
Reference in a new issue