1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2025-02-01 02:25:19 +00:00
modufur/src/cogs/tools.py

78 lines
2.9 KiB
Python
Raw Normal View History

2017-09-24 11:05:28 -04:00
import asyncio
2017-11-19 23:10:48 -05:00
from datetime import datetime as dt
import mimetypes
import os
import tempfile
2017-10-12 22:27:21 -04:00
import traceback as tb
import webbrowser
2017-10-12 22:27:21 -04:00
2017-10-30 00:21:00 -04:00
import discord as d
from discord.ext import commands as cmds
2017-10-12 22:27:21 -04:00
2017-10-11 03:01:13 -04:00
#from run import config
2017-09-24 11:05:28 -04:00
from cogs import booru
from misc import exceptions as exc
2017-10-12 22:27:21 -04:00
from misc import checks
from utils import utils as u
2017-09-24 11:05:28 -04:00
from utils import formatter
2017-10-11 03:01:13 -04:00
youtube = None
2017-10-11 03:01:13 -04:00
tempfile.tempdir = os.getcwd()
2017-10-12 22:27:21 -04:00
2017-09-24 11:05:28 -04:00
class Utils:
2017-10-20 16:26:13 -04:00
def __init__(self, bot):
self.bot = bot
2017-10-17 19:04:45 -04:00
@cmds.command(name='lastcommand', aliases=['last', 'l', ','], brief='Reinvokes last successful command', description='Executes last successfully executed command')
async def last_command(self, ctx, arg='None'):
try:
context = u.last_commands[ctx.author.id]
if arg == 'show' or arg == 'sh' or arg == 's':
await ctx.send(f'`{context.prefix}{context.invoked_with} {" ".join(context.args[2:])}`', delete_after=7)
else:
await ctx.invoke(context.command, *context.args[2:], **context.kwargs)
2017-10-17 19:04:45 -04:00
except KeyError:
await ctx.send('**No last command**', delete_after=7)
await ctx.message.add_reaction('\N{CROSS MARK}')
2017-10-17 19:04:45 -04:00
2017-10-20 16:26:13 -04:00
# Displays latency
@cmds.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user')
2017-10-20 16:26:13 -04:00
async def ping(self, ctx):
await ctx.message.add_reaction('\N{TABLE TENNIS PADDLE AND BALL}')
await ctx.send(ctx.author.mention + ' \N{TABLE TENNIS PADDLE AND BALL} `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5)
2017-10-17 19:04:45 -04:00
@cmds.command(aliases=['pre', 'prefixes'], brief='List bot prefixes', description='Shows all used prefixes')
2017-10-20 16:26:13 -04:00
async def prefix(self, ctx):
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'])))
2017-10-20 16:26:13 -04:00
@cmds.group(name=',send', aliases=[',s'], hidden=True)
@cmds.is_owner()
2017-10-20 16:26:13 -04:00
async def send(self, ctx):
pass
@send.command(name='guild', aliases=['g', 'server', 's'])
async def send_guild(self, ctx, guild, channel, *, message):
try:
tempchannel = d.utils.find(lambda m: m.name == channel, d.utils.find(
lambda m: m.name == guild, self.bot.guilds).channels)
try:
await tempchannel.send(message)
except AttributeError:
await ctx.send('**Invalid channel**', delete_after=7)
await ctx.message.add_reaction('\N{CROSS MARK}')
except AttributeError:
await ctx.send('**Invalid guild**', delete_after=7)
await ctx.message.add_reaction('\N{CROSS MARK}')
2017-10-20 16:26:13 -04:00
@send.command(name='user', aliases=['u', 'member', 'm'])
async def send_user(self, ctx, user, *, message):
await d.utils.get(self.bot.get_all_members(), id=int(user)).send(message)