1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 14:27:27 +00:00

Merge branch 'dev'

This commit is contained in:
Myned 2017-10-13 01:25:11 -04:00
commit fe2587a71f
4 changed files with 30 additions and 34 deletions

View file

@ -154,7 +154,7 @@ class MsG:
await paginator.add_reaction('') await paginator.add_reaction('')
await asyncio.sleep(1) await asyncio.sleep(1)
while True: while not self.bot.is_closed():
try: try:
await self.bot.wait_for('reaction_add', check=on_react, timeout=10 * 60) await self.bot.wait_for('reaction_add', check=on_react, timeout=10 * 60)
@ -328,7 +328,7 @@ class MsG:
await paginator.add_reaction('') await paginator.add_reaction('')
await asyncio.sleep(1) await asyncio.sleep(1)
while True: while not self.bot.is_closed():
try: try:
await self.bot.wait_for('reaction_add', check=on_react, timeout=10 * 60) await self.bot.wait_for('reaction_add', check=on_react, timeout=10 * 60)

View file

@ -8,22 +8,19 @@ 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
RATE_LIMIT = 2.1
class Administration: class Administration:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.RATE_LIMIT = 2.1
self.queue = asyncio.Queue() self.queue = asyncio.Queue()
if u.background.get('management', {}): for channel in u.tasks.get('management', {}).get('auto_delete', []):
if u.background['management'].get('auto_delete', {}): temp = self.bot.get_channel(channel)
for channel in u.background['management']['auto_delete']: self.bot.loop.create_task(self.on_message(temp))
temp = self.bot.get_channel(channel) self.bot.loop.create_task(self.delete())
self.bot.loop.create_task(self.on_message(temp)) print('Looping #{}'.format(temp.name))
self.bot.loop.create_task(self.delete())
print('Looping {}'.format(temp.id))
# @commands.group(aliases=['pr', 'clear', 'cl']) # @commands.group(aliases=['pr', 'clear', 'cl'])
# @commands.is_owner() # @commands.is_owner()
@ -45,12 +42,12 @@ class Administration:
# for channel in channels: # for channel in channels:
# bulk_history[channel] = await channel.history(limit=None, after=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten() # bulk_history[channel] = await channel.history(limit=None, after=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten()
# await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**') # await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**')
# await asyncio.sleep(RATE_LIMIT) # await asyncio.sleep(self.RATE_LIMIT)
# for channel, messages in bulk_history.items(): # for channel, messages in bulk_history.items():
# bulk[channel] = [message for message in messages if message.author.id == int(uid)] # bulk[channel] = [message for message in messages if message.author.id == int(uid)]
# for channel, messages in bulk_history.items(): # for channel, messages in bulk_history.items():
# bulk[channel] = [bulk[channel][i:i+100] for i in range(0, len(bulk[channel]), 100)] # bulk[channel] = [bulk[channel][i:i+100] for i in range(0, len(bulk[channel]), 100)]
# await ctx.send('⏱ **Estimated time to delete `bulk-history`:** `' + str(int(RATE_LIMIT * sum([len(v) for v in bulk.values()]) / 60)) + ' mins ' + str(int(RATE_LIMIT * sum([len(v) for v in bulk.values()]) % 60)) + ' secs`') # await ctx.send('⏱ **Estimated time to delete `bulk-history`:** `' + str(int(self.RATE_LIMIT * sum([len(v) for v in bulk.values()]) / 60)) + ' mins ' + str(int(self.RATE_LIMIT * sum([len(v) for v in bulk.values()]) % 60)) + ' secs`')
# check = await ctx.send(ctx.author.mention + ' **Continue?** `Y` or `N`') # check = await ctx.send(ctx.author.mention + ' **Continue?** `Y` or `N`')
# await self.bot.wait_for('message', check=yes, timeout=60) # await self.bot.wait_for('message', check=yes, timeout=60)
# del_sent = await ctx.send('🗑 **Deleting messages...**') # del_sent = await ctx.send('🗑 **Deleting messages...**')
@ -64,14 +61,12 @@ class Administration:
# for channel in channels: # for channel in channels:
# history.extend(await channel.history(limit=None, before=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten()) # history.extend(await channel.history(limit=None, before=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten())
# await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**') # await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**')
# await asyncio.sleep(RATE_LIMIT) # await asyncio.sleep(self.RATE_LIMIT)
@commands.command(name=',prunefromguild', aliases=[',pfg', ',prunefromserver', ',pfs'], brief='Prune a user\'s messages from the guild', description='about flag centers on message 50 of 101 messages\n\npfg \{user id\} [before|after|about] [\{message id\}]\n\nExample:\npfg \{user id\} before \{message id\}') @commands.command(name=',prunefromguild', aliases=[',pfg', ',prunefromserver', ',pfs'], brief='Prune a user\'s messages from the guild', description='about flag centers on message 50 of 101 messages\n\npfg \{user id\} [before|after|about] [\{message id\}]\n\nExample:\npfg \{user id\} before \{message id\}')
@commands.is_owner() @commands.is_owner()
@checks.del_ctx() @checks.del_ctx()
async def prune_all_user(self, ctx, uid, when=None, reference=None): async def prune_all_user(self, ctx, uid, when=None, reference=None):
global RATE_LIMIT
def yes(msg): def yes(msg):
if msg.content.lower() == 'y' and msg.channel is ctx.message.channel and msg.author is ctx.message.author: if msg.content.lower() == 'y' and msg.channel is ctx.message.channel and msg.author is ctx.message.author:
return True return True
@ -96,25 +91,25 @@ class Administration:
for channel in channels: for channel in channels:
history.extend(await channel.history(limit=None).flatten()) history.extend(await channel.history(limit=None).flatten())
await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'before': elif when == 'before':
for channel in channels: for channel in channels:
history.extend(await channel.history(limit=None, before=ref.created_at).flatten()) history.extend(await channel.history(limit=None, before=ref.created_at).flatten())
await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'after': elif when == 'after':
for channel in channels: for channel in channels:
history.extend(await channel.history(limit=None, after=ref.created_at).flatten()) history.extend(await channel.history(limit=None, after=ref.created_at).flatten())
await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'about': elif when == 'about':
for channel in channels: for channel in channels:
history.extend(await channel.history(limit=101, about=ref.created_at).flatten()) history.extend(await channel.history(limit=101, about=ref.created_at).flatten())
await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
history = [message for message in history if message.author.id == int(uid)] history = [message for message in history if message.author.id == int(uid)]
est_sent = await ctx.send('⏱ **Estimated time to delete history:** `{}m {}s`'.format(int(RATE_LIMIT * len(history) / 60), int(RATE_LIMIT * len(history) % 60))) est_sent = await ctx.send('⏱ **Estimated time to delete history:** `{}m {}s`'.format(int(self.RATE_LIMIT * len(history) / 60), int(self.RATE_LIMIT * len(history) % 60)))
cont_sent = await ctx.send('{} **Continue?** `Y` or `N`'.format(ctx.author.mention)) cont_sent = await ctx.send('{} **Continue?** `Y` or `N`'.format(ctx.author.mention))
await self.bot.wait_for('message', check=yes, timeout=60) await self.bot.wait_for('message', check=yes, timeout=60)
await cont_sent.delete() await cont_sent.delete()
@ -126,7 +121,7 @@ class Administration:
pass pass
# print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history))) # print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history)))
await del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history))) await del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history)))
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.message.guild.name)) await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.message.guild.name))
except exc.CheckFail: except exc.CheckFail:
await ctx.send('❌ **Deletion aborted.**', delete_after=10) await ctx.send('❌ **Deletion aborted.**', delete_after=10)
@ -134,11 +129,12 @@ class Administration:
await ctx.send('❌ **Deletion timed out.**', delete_after=10) await ctx.send('❌ **Deletion timed out.**', delete_after=10)
async def delete(self): async def delete(self):
while True: while not self.bot.is_closed():
message = await self.queue.get() message = await self.queue.get()
await asyncio.sleep(RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
try: try:
await message.delete() if not message.pinned:
await message.delete()
except d.errors.NotFound: except d.errors.NotFound:
pass pass
@ -152,12 +148,12 @@ class Administration:
return False return False
try: try:
while True: 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.queue.put(message)
except exc.Abort: except exc.Abort:
u.background['management']['auto_delete'].remove(channel.id) u.tasks['management']['auto_delete'].remove(channel.id)
u.dump(u.background, 'background.pkl') u.dump(u.tasks, './cogs/tasks.pkl')
print('Stopped looping {}'.format(channel.id)) print('Stopped looping {}'.format(channel.id))
await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5) await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5)
except AttributeError: except AttributeError:
@ -170,12 +166,12 @@ class Administration:
channel = ctx.message.channel channel = ctx.message.channel
try: try:
if channel.id not in u.background.setdefault('management', {}).setdefault('auto_delete', []): if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []):
u.background['management']['auto_delete'].append(channel.id) u.tasks['management']['auto_delete'].append(channel.id)
u.dump(u.background, 'background.pkl') u.dump(u.tasks, './cogs/tasks.pkl')
self.bot.loop.create_task(self.on_message(channel)) self.bot.loop.create_task(self.on_message(channel))
self.bot.loop.create_task(self.delete()) self.bot.loop.create_task(self.delete())
print('Looping {}'.format(channel.id)) print('Looping #{}'.format(channel.name))
await ctx.send('✅ **Auto-deleting all messages in this channel.**', delete_after=5) await ctx.send('✅ **Auto-deleting all messages in this channel.**', delete_after=5)
else: else:
raise exc.Exists raise exc.Exists

View file

@ -106,7 +106,7 @@ class Tools:
try: try:
console = await self.generate(ctx) console = await self.generate(ctx)
exception = await self.generate_err(ctx) exception = await self.generate_err(ctx)
while True: while not self.bot.is_closed():
exe = await self.bot.wait_for('message', check=execute) exe = await self.bot.wait_for('message', check=execute)
await exe.delete() await exe.delete()
sys.stdout = io.StringIO() sys.stdout = io.StringIO()

View file

@ -28,7 +28,7 @@ def dump(obj, filename):
pkl.dump(obj, outfile) pkl.dump(obj, outfile)
background = setdefault('./cogs/background.pkl', {}) tasks = setdefault('./cogs/tasks.pkl', {})
with open('config.json') as infile: with open('config.json') as infile:
config = json.load(infile) config = json.load(infile)