mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
Merge branch 'dev'
This commit is contained in:
commit
5eed4f3dcf
10 changed files with 1861 additions and 1778 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
|
||||||
|
@ -448,7 +472,7 @@ class MsG:
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
if msg.content.lower() == 'cancel' and msg.author is ctx.author and msg.channel is ctx.channel:
|
if msg.content.lower() == 'cancel' and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
with suppress(ValueError):
|
elif msg.content.isdigit():
|
||||||
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is ctx.author and msg.channel is ctx.channel:
|
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -505,7 +529,7 @@ class MsG:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
with suppress(ValueError):
|
if msg.content.isdigit():
|
||||||
if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel:
|
if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -523,7 +547,8 @@ class MsG:
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=dest.me.color if isinstance(dest.channel, d.TextChannel) else self.color).set_image(url=values[c - 1]['url'])
|
title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=dest.me.color if isinstance(dest.channel, d.TextChannel) else self.color)
|
||||||
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
embed.set_author(name=pool['name'],
|
embed.set_author(name=pool['name'],
|
||||||
url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
|
@ -597,18 +622,12 @@ class MsG:
|
||||||
|
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await dest.send('**Exited paginator.**')
|
await dest.send('**Exited paginator.**')
|
||||||
|
|
||||||
finally:
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
try:
|
try:
|
||||||
await paginator.edit(content='**Paginator timed out.**')
|
await paginator.edit(content='**Paginator timed out.**')
|
||||||
|
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await dest.send('**Paginator timed out.**')
|
await dest.send('**Paginator timed out.**')
|
||||||
|
|
||||||
finally:
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await ctx.send('**Pool not found.**', delete_after=10)
|
await ctx.send('**Pool not found.**', delete_after=10)
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
@ -617,11 +636,16 @@ class MsG:
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
if starred:
|
||||||
|
await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
||||||
|
|
||||||
for url in starred:
|
for url in starred:
|
||||||
await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url))
|
await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url))
|
||||||
if len(starred) > 5:
|
if len(starred) > 5:
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
await asyncio.sleep(self.RATE_LIMIT)
|
||||||
|
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
# Messy code that checks image limit and tags in blacklists
|
# Messy code that checks image limit and tags in blacklists
|
||||||
async def check_return_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
async def check_return_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
||||||
guild = ctx.guild if isinstance(
|
guild = ctx.guild if isinstance(
|
||||||
|
@ -690,7 +714,7 @@ class MsG:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
with suppress(ValueError):
|
if msg.content.isdigit():
|
||||||
if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel:
|
if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -711,7 +735,8 @@ class MsG:
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=values[c - 1]['url'])
|
title=values[c - 1]['author'], 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_author(name=formatter.tostring(tags, random=True),
|
embed.set_author(name=formatter.tostring(tags, random=True),
|
||||||
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(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
|
@ -793,18 +818,12 @@ class MsG:
|
||||||
|
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await dest.send('**Exited paginator.**')
|
await dest.send('**Exited paginator.**')
|
||||||
|
|
||||||
finally:
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
try:
|
try:
|
||||||
await paginator.edit(content='**Paginator timed out.**')
|
await paginator.edit(content='**Paginator timed out.**')
|
||||||
|
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await dest.send('**Paginator timed out.**')
|
await dest.send('**Paginator timed out.**')
|
||||||
|
|
||||||
finally:
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
except exc.NotFound as e:
|
except exc.NotFound as e:
|
||||||
await ctx.send('`{}` **not found.**'.format(e), delete_after=10)
|
await ctx.send('`{}` **not found.**'.format(e), delete_after=10)
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
@ -822,11 +841,16 @@ class MsG:
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
if starred:
|
||||||
|
await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
||||||
|
|
||||||
for url in starred:
|
for url in starred:
|
||||||
await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url))
|
await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url))
|
||||||
if len(starred) > 5:
|
if len(starred) > 5:
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
await asyncio.sleep(self.RATE_LIMIT)
|
||||||
|
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@e621_paginator.error
|
@e621_paginator.error
|
||||||
async def e621_paginator_error(self, ctx, error):
|
async def e621_paginator_error(self, ctx, error):
|
||||||
if isinstance(error, errext.CheckFailure):
|
if isinstance(error, errext.CheckFailure):
|
||||||
|
|
|
@ -178,3 +178,15 @@ class Administration:
|
||||||
|
|
||||||
await ctx.send('**Delete command invocations:** `{}`'.format(ctx.guild.id in u.settings['del_ctx']))
|
await ctx.send('**Delete command invocations:** `{}`'.format(ctx.guild.id in u.settings['del_ctx']))
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
|
@commands.command(name='setprefix', aliases=['setpre', 'spre'])
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def set_prefix(self, ctx, prefix=None):
|
||||||
|
if prefix is not None:
|
||||||
|
u.settings['prefixes'][ctx.guild.id] = prefix
|
||||||
|
else:
|
||||||
|
with suppress(KeyError):
|
||||||
|
del u.settings['prefixes'][ctx.guild.id]
|
||||||
|
|
||||||
|
await ctx.send(f'**Prefix set to:** `{"` or `".join(prefix if ctx.guild.id in u.settings["prefixes"] else u.config["prefix"])}`')
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback as tb
|
import traceback as tb
|
||||||
|
from contextlib import suppress
|
||||||
|
|
||||||
import discord as d
|
import discord as d
|
||||||
import pyrasite as pyr
|
import pyrasite as pyr
|
||||||
|
@ -14,8 +15,6 @@ from misc import exceptions as exc
|
||||||
from misc import checks
|
from misc import checks
|
||||||
from utils import utils as u
|
from utils import utils as u
|
||||||
|
|
||||||
nl = re.compile('\n')
|
|
||||||
|
|
||||||
|
|
||||||
class Bot:
|
class Bot:
|
||||||
|
|
||||||
|
@ -99,9 +98,8 @@ class Tools:
|
||||||
return await d.send('```python\n{}```'.format(self.format(i, o)))
|
return await d.send('```python\n{}```'.format(self.format(i, o)))
|
||||||
|
|
||||||
async def refresh(self, m, i='', o=''):
|
async def refresh(self, m, i='', o=''):
|
||||||
global nl
|
output = m.content[9:-3]
|
||||||
output = m.content[10:-2]
|
if len(re.findall('\n', output)) <= 20:
|
||||||
if len(nl.findall(output)) <= 20:
|
|
||||||
await m.edit(content='```python\n{}\n{}\n>>>```'.format(output, self.format(i, o)))
|
await m.edit(content='```python\n{}\n{}\n>>>```'.format(output, self.format(i, o)))
|
||||||
else:
|
else:
|
||||||
await m.edit(content='```python\n{}```'.format(self.format(i, o)))
|
await m.edit(content='```python\n{}```'.format(self.format(i, o)))
|
||||||
|
@ -117,57 +115,89 @@ class Tools:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def console(self, ctx):
|
async def console(self, ctx):
|
||||||
def execute(msg):
|
def execute(msg):
|
||||||
if msg.content == 'exit' and msg.author is ctx.author:
|
if msg.content.startswith('exe') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
raise exc.Abort
|
results.cancel()
|
||||||
elif msg.author is ctx.author and msg.channel is ctx.channel:
|
|
||||||
return True
|
return True
|
||||||
else:
|
return False
|
||||||
|
|
||||||
|
def evaluate(msg):
|
||||||
|
if msg.content.startswith('eval') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
|
results.cancel()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def exit(reaction, user):
|
||||||
|
if reaction.emoji == '\N{LEFTWARDS ARROW WITH HOOK}' and user is ctx.author and reaction.message.id == ctx.message.id:
|
||||||
|
results.cancel()
|
||||||
|
raise exc.Abort
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
|
|
||||||
console = await self.generate(ctx)
|
console = await self.generate(ctx)
|
||||||
exception = await self.generate_err(ctx)
|
exception = await self.generate_err(ctx)
|
||||||
|
|
||||||
|
await ctx.message.add_reaction('\N{LEFTWARDS ARROW WITH HOOK}')
|
||||||
|
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
try:
|
try:
|
||||||
exe = await self.bot.wait_for('message', check=execute)
|
results = await asyncio.gather([self.bot.wait_for('message', check=execute), self.bot.wait_for('message', check=evaluate), self.bot.wait_for('reaction_add', check=exit)], return_exceptions=True)
|
||||||
except exc.Abort:
|
print(results)
|
||||||
raise exc.Abort
|
except exc.Execute:
|
||||||
await exe.delete()
|
|
||||||
try:
|
try:
|
||||||
sys.stdout = io.StringIO()
|
sys.stdout = io.StringIO()
|
||||||
sys.stderr = io.StringIO()
|
sys.stderr = io.StringIO()
|
||||||
exec(exe.content)
|
exec(exe.content)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
await self.refresh_err(exception, tb.format_exc(limit=1))
|
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
await self.refresh(console, exe.content, sys.stdout.getvalue())
|
await self.refresh(console, exe.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
|
|
||||||
|
except exc.Evaluate:
|
||||||
|
try:
|
||||||
|
sys.stdout = io.StringIO()
|
||||||
|
sys.stderr = io.StringIO()
|
||||||
|
eval(exe.content)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
await self.refresh(console, exe.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||||
|
sys.stdout = sys.__stdout__
|
||||||
|
sys.stderr = sys.__stderr__
|
||||||
|
|
||||||
|
finally:
|
||||||
|
with suppress(d.NotFound):
|
||||||
|
await exe.delete()
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
await ctx.send('\N{LEFTWARDS ARROW WITH HOOK} **Exited console.**')
|
pass
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
print('Reset sys output.')
|
print('Reset sys output.')
|
||||||
|
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@commands.command(name='arbitrary', aliases=[',arbit', ',ar'])
|
@commands.command(name='arbitrary', aliases=[',arbit', ',ar'])
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def arbitrary(self, ctx, *, exe):
|
async def arbitrary(self, ctx, *, exe):
|
||||||
try:
|
try:
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
|
|
||||||
sys.stdout = io.StringIO()
|
sys.stdout = io.StringIO()
|
||||||
exec(exe)
|
exec(exe)
|
||||||
await self.generate(ctx, exe, sys.stdout.getvalue())
|
await self.generate(ctx, exe, sys.stdout.getvalue())
|
||||||
except Exception:
|
except Exception:
|
||||||
await ctx.send('```\n{}```'.format(tb.format_exc(limit=1)))
|
await ctx.send('```\n{}```'.format(tb.format_exc(limit=1)))
|
||||||
tb.print_exc(limit=1)
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
print('Reset stdout.')
|
print('Reset stdout.')
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@commands.group(aliases=[',db'], hidden=True)
|
@commands.group(aliases=[',db'], hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Utils:
|
||||||
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def prefix(self, ctx):
|
async def prefix(self, ctx):
|
||||||
await ctx.send('**Prefix:** `{}`'.format(u.config['prefix']))
|
await ctx.send('**Prefix:** `{}`'.format('` or `'.join(u.settings['prefixes'][ctx.guild.id] if ctx.guild.id in u.settings['prefixes'] else u.config['prefix'])))
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@commands.group(name=',send', aliases=[',s'], hidden=True)
|
@commands.group(name=',send', aliases=[',s'], hidden=True)
|
||||||
|
@ -67,7 +67,7 @@ class Utils:
|
||||||
|
|
||||||
@send.command(name='guild', aliases=['g', 'server', 's'])
|
@send.command(name='guild', aliases=['g', 'server', 's'])
|
||||||
async def send_guild(self, ctx, guild, channel, *, message):
|
async def send_guild(self, ctx, guild, channel, *, message):
|
||||||
await discord.utils.get(self.bot.get_all_channels(), guild__name=guild, name=channel).send(message)
|
await discord.utils.get(self.bot.get_all_channels(), guild_name=guild, name=channel).send(message)
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@send.command(name='user', aliases=['u', 'member', 'm'])
|
@send.command(name='user', aliases=['u', 'member', 'm'])
|
||||||
|
|
|
@ -5,6 +5,14 @@ async def send_error(ctx, error):
|
||||||
await ctx.send('{}\n```\n{}```'.format(base, error))
|
await ctx.send('{}\n```\n{}```'.format(base, error))
|
||||||
|
|
||||||
|
|
||||||
|
class Execute(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Evaluate(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Left(Exception):
|
class Left(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -18,20 +18,25 @@ from utils import utils as u
|
||||||
|
|
||||||
# log.basicConfig(level=log.INFO)
|
# log.basicConfig(level=log.INFO)
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=u.config['prefix'], description='Experimental miscellaneous bot')
|
|
||||||
|
|
||||||
|
def get_prefix(bot, message):
|
||||||
|
if isinstance(message.guild, d.Guild) and message.guild.id in u.settings['prefixes']:
|
||||||
|
return u.settings['prefixes'][message.guild.id]
|
||||||
|
return u.config['prefix']
|
||||||
|
|
||||||
|
|
||||||
|
bot = commands.Bot(command_prefix=get_prefix, description='Experimental miscellaneous bot')
|
||||||
|
|
||||||
# Send and print ready message to #testing and console after logon
|
# Send and print ready message to #testing and console after logon
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
from cogs import booru, info, management, owner, tools
|
from cogs import booru, info, management, owner, tools
|
||||||
|
|
||||||
bot.add_cog(tools.Utils(bot))
|
for cog in (tools.Utils(bot), owner.Bot(bot), owner.Tools(bot), management.Administration(bot), info.Info(bot), booru.MsG(bot)):
|
||||||
bot.add_cog(owner.Bot(bot))
|
bot.add_cog(cog)
|
||||||
bot.add_cog(owner.Tools(bot))
|
print(f'COG : {type(cog).__name__}')
|
||||||
bot.add_cog(management.Administration(bot))
|
|
||||||
bot.add_cog(info.Info(bot))
|
|
||||||
bot.add_cog(booru.MsG(bot))
|
|
||||||
|
|
||||||
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
||||||
|
|
||||||
|
@ -50,12 +55,25 @@ async def on_ready():
|
||||||
u.temp.clear()
|
u.temp.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_message(message):
|
||||||
|
if message.author.bot or message.author is bot.user:
|
||||||
|
return
|
||||||
|
|
||||||
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_error(error, *args, **kwargs):
|
async def on_error(error, *args, **kwargs):
|
||||||
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
||||||
tb.print_exc()
|
tb.print_exc()
|
||||||
await bot.get_user(u.config['owner_id']).send('**ERROR** ⚠ `{}`'.format(error))
|
await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN} `{}`'.format(error))
|
||||||
await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠ `{}`'.format(error))
|
await bot.get_channel(u.config['info_channel']).send('**ERROR** \N{WARNING SIGN} `{}`'.format(error))
|
||||||
|
if u.temp:
|
||||||
|
channel = bot.get_channel(u.temp['restart_ch'])
|
||||||
|
message = await channel.get_message(u.temp['restart_msg'])
|
||||||
|
await message.add_reaction('\N{WARNING SIGN}')
|
||||||
|
u.temp.clear()
|
||||||
# u.notify('E R R O R')
|
# u.notify('E R R O R')
|
||||||
await bot.logout()
|
await bot.logout()
|
||||||
u.close(bot.loop)
|
u.close(bot.loop)
|
||||||
|
@ -73,10 +91,10 @@ async def on_command_error(ctx, error):
|
||||||
print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format(
|
print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format(
|
||||||
error), file=sys.stderr)
|
error), file=sys.stderr)
|
||||||
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
|
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
|
||||||
await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** ⚠ `{}`'.format(error))
|
await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}`'.format(error))
|
||||||
await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** ⚠ `{}`'.format(error))
|
await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}`'.format(error))
|
||||||
await exc.send_error(ctx, error)
|
await exc.send_error(ctx, error)
|
||||||
await ctx.message.add_reaction('⚠')
|
await ctx.message.add_reaction('\N{WARNING SIGN}')
|
||||||
# u.notify('C O M M A N D E R R O R')
|
# u.notify('C O M M A N D E R R O R')
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,16 +135,8 @@ def after(voice, error):
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def test(ctx):
|
async def test(ctx):
|
||||||
def check(react, user):
|
channel = bot.get_channel(int(cid))
|
||||||
return reaction.emoji == '\N{THUMBS UP SIGN}'
|
voice = await channel.connect()
|
||||||
# channel = bot.get_channel(int(cid))
|
voice.play(d.AudioSource, after=lambda: after(voice))
|
||||||
# voice = await channel.connect()
|
|
||||||
# voice.play(d.AudioSource, after=lambda: after(voice))
|
|
||||||
test = await ctx.send('thumbs up!')
|
|
||||||
while True:
|
|
||||||
done, pending = await asyncio.wait([bot.wait_for('reaction_add', check=check), bot.wait_for('reaction_remove', check=check)], return_when=asyncio.FIRST_COMPLETED)
|
|
||||||
await ctx.send('well doneeee')
|
|
||||||
# bot.add_listener(on_reaction_add)
|
|
||||||
# bot.add_listener(on_reaction_remove)
|
|
||||||
|
|
||||||
bot.run(u.config['token'])
|
bot.run(u.config['token'])
|
||||||
|
|
|
@ -22,23 +22,23 @@ print('\nPID : {}\n'.format(os.getpid()))
|
||||||
try:
|
try:
|
||||||
with open('config.json') as infile:
|
with open('config.json') as infile:
|
||||||
config = jsn.load(infile)
|
config = jsn.load(infile)
|
||||||
print('config.json loaded.')
|
print('LOADED : config.json')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
with open('config.json', 'w') as outfile:
|
with open('config.json', 'w') as outfile:
|
||||||
jsn.dump({'client_id': 0, 'info_channel': 0, 'owner_id': 0, 'permissions': 126016,
|
jsn.dump({'client_id': 0, 'info_channel': 0, 'owner_id': 0, 'permissions': 126016,
|
||||||
'playing': 'a game', 'prefix': [',', 'm,'], 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
'playing': 'a game', 'prefix': [',', 'm,'], 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
||||||
raise FileNotFoundError(
|
raise FileNotFoundError(
|
||||||
'Config file not found: config.json created with abstract values. Restart run.py with correct values.')
|
'FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values')
|
||||||
|
|
||||||
|
|
||||||
def setdefault(filename, default=None):
|
def setdefault(filename, default=None):
|
||||||
try:
|
try:
|
||||||
with open(filename, 'rb') as infile:
|
with open(filename, 'rb') as infile:
|
||||||
print('{} loaded.'.format(filename))
|
print('LOADED : {}'.format(filename))
|
||||||
return pkl.load(infile)
|
return pkl.load(infile)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
with open(filename, 'wb+') as iofile:
|
with open(filename, 'wb+') as iofile:
|
||||||
print('File not found: {} created and loaded with default values.'.format(filename))
|
print('FILE NOT FOUND : {} created and loaded with default values'.format(filename))
|
||||||
pkl.dump(default, iofile)
|
pkl.dump(default, iofile)
|
||||||
iofile.seek(0)
|
iofile.seek(0)
|
||||||
return pkl.load(iofile)
|
return pkl.load(iofile)
|
||||||
|
@ -62,7 +62,7 @@ def dump(obj, filename, *, json=False):
|
||||||
jsn.dump(obj, outfile, indent=4, sort_keys=True)
|
jsn.dump(obj, outfile, indent=4, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
settings = setdefault('settings.pkl', {'del_ctx': []})
|
settings = setdefault('settings.pkl', {'del_ctx': [], 'prefixes': {}})
|
||||||
tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_qual': [], 'auto_rev': []})
|
tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_qual': [], 'auto_rev': []})
|
||||||
temp = setdefault('temp.pkl', {})
|
temp = setdefault('temp.pkl', {})
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ def close(loop):
|
||||||
async def fetch(url, *, params={}, json=False):
|
async def fetch(url, *, params={}, json=False):
|
||||||
global session
|
global session
|
||||||
|
|
||||||
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/0.0.1'}) as r:
|
||||||
if json:
|
if json:
|
||||||
return await r.json()
|
return await r.json()
|
||||||
return await r.read()
|
return await r.read()
|
||||||
|
@ -137,8 +137,7 @@ def get_kwargs(ctx, args, *, limit=False):
|
||||||
|
|
||||||
if limit:
|
if limit:
|
||||||
for arg in remaining:
|
for arg in remaining:
|
||||||
if 1 <= len(arg) <= 2:
|
if arg.isdigit():
|
||||||
with suppress(ValueError):
|
|
||||||
if 1 <= int(arg) <= limit:
|
if 1 <= int(arg) <= limit:
|
||||||
lim = int(arg)
|
lim = int(arg)
|
||||||
remaining.remove(arg)
|
remaining.remove(arg)
|
||||||
|
|
Loading…
Reference in a new issue