async def editincident(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        icore = get_incident_core(cmd.db)
        if len(pld.args) >= 2:
            lookup = pld.args[0]
            reason = ' '.join(pld.args[1:])
            incident = await icore.get_by_token(pld.msg.guild.id, lookup)
            if incident:
                if not len(reason) > 1000:
                    incident.edit(pld.msg.author, reason)
                    await icore.save(incident)
                    response = ok(f'Incident {incident.id} updated.')
                else:
                    response = error(
                        'Reasons have a limit of 1000 characters.')
            else:
                response = error('No incident with that ID was found.')
        else:
            response = error('Invalid number of arguments.')
    else:
        response = denied('Access Denied. Manage Messages needed.')
    await pld.msg.channel.send(embed=response)
async def starboardlimit(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_guild:
        starboard_doc = pld.settings.get('starboard') or {}
        if pld.args:
            try:
                new_limit = abs(int(pld.args[0]))
            except ValueError:
                new_limit = None
            if new_limit is not None:
                starboard_doc.update({'limit': int(new_limit)})
                await cmd.db.set_guild_settings(pld.msg.guild.id, 'starboard', starboard_doc)
                response = ok(f'Starboard limit set to {new_limit}.')
            else:
                response = error('Limit must be a number.')
        else:
            limit = starboard_doc.get('limit')
            if limit:
                response = discord.Embed(color=0xFFAC33, title=f'🌟 The current limit is {limit}')
            else:
                response = error('A limit has not been set.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
Beispiel #3
0
async def generateitem(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    item_core = await get_item_core(cmd.db)
    if pld.args:
        if pld.msg.mentions:
            if len(pld.args) >= 2:
                target = pld.msg.mentions[0]
                lookup = ' '.join(pld.args[1:])
                item = item_core.get_item_by_name(lookup)
                if item:
                    connector = 'a'
                    if item.name[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                        connector = 'an'
                    data_for_inv = item.generate_inventory_item()
                    await cmd.db.add_to_inventory(target.id, data_for_inv)
                    success_text = f'{item.icon} I have given {connector} {item.name} to {target.display_name}.'
                    response = discord.Embed(color=item.color,
                                             title=success_text)
                else:
                    response = not_found(f'{lookup} not found.')
            else:
                response = error('Not enough arguments.')
        else:
            response = error('No user targeted.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response)
async def foodrecipe(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if cmd.cfg.api_key:
        if pld.args:
            search = ' '.join(pld.args)
            url = f'http://food2fork.com/api/search?key={cmd.cfg.api_key}&q={search}'
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as data:
                    search_data = await data.read()
                    search_data = json.loads(search_data)
            count = search_data['count']
            if count == 0:
                response = not_found('No results.')
            else:
                info = search_data['recipes'][0]
                title = info['title']
                source = info['publisher']
                source_url = info['source_url']
                image_url = info['image_url']
                publisher_url = info['publisher_url']
                response = discord.Embed(color=0xee5b2f)
                response.set_author(name=source, url=publisher_url, icon_url='https://i.imgur.com/RH8LNdQ.png')
                response.add_field(name=title, value='[Recipe Here](' + source_url + ')')
                response.set_thumbnail(url=image_url)
        else:
            response = error('Nothing inputted.')
    else:
        response = error('The API Key is missing.')
    await pld.msg.channel.send(embed=response)
Beispiel #5
0
async def wolframalpha(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    init_message = None
    if cmd.cfg.app_id:
        if not is_ongoing('mathgame', pld.msg.channel.id):
            if pld.args:
                query = make_safe_query(pld.args)
                url = f'{api_url}{query}&appid={cmd.cfg.app_id}'
                init_response = discord.Embed(color=0xff7e00)
                init_response.set_author(name='Processing request...', icon_url=wolfram_icon)
                init_message = await pld.msg.channel.send(embed=init_response)
                results = await get_results(url)
                if results:
                    if len(results) <= 2000:
                        response = discord.Embed(color=0xff7e00, description=f'```\n{results}\n```')
                        response.set_author(name='Wolfram Alpha', icon_url=wolfram_icon, url=wolfram_url + query)
                        response.set_footer(text='View the full results by clicking the embed title.')
                    else:
                        response = error('Results too long to display.')
                        response.description = f'You can view them directly [here]({wolfram_url + query}).'
                else:
                    response = not_found('No results.')
            else:
                response = error('Nothing inputted.')
        else:
            response = error('Wolfram can\'t be used during an ongoing math game.')
    else:
        response = error('The API Key is missing.')
    await send_response(pld.msg, init_message, response)
async def addline(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if len(pld.args) >= 2:
        add_line = ' '.join(pld.args[1:])
        list_coll = cmd.db[cmd.db.db_nam].CustomLists
        lookup_data = {
            'server_id': pld.msg.guild.id,
            'list_id': pld.args[0].lower()
        }
        list_file = await list_coll.find_one(lookup_data)
        if list_file:
            if user_auth(pld.msg, list_file):
                list_file.get('contents').append(add_line)
                await list_coll.update_one(lookup_data, {'$set': list_file})
                response = discord.Embed(
                    color=0xF9F9F9,
                    title='📝 Your line was written to the list.')
            else:
                mode = 'private' if list_file.get(
                    'mode') == 'private' else 'locked'
                response = discord.Embed(color=0xFFAC33,
                                         title=f'🔏 This list is {mode}.')
        else:
            response = error('Missing or invalid list ID.')
    else:
        response = error('Not enough arguments.')
    await pld.msg.channel.send(embed=response)
Beispiel #7
0
async def busplus(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        line_number = " ".join(pld.args)
        current_time = arrow.utcnow().to('Europe/Belgrade')
        current_day = current_time.format('d')
        data_pool = 'sun' if current_day == '7' else 'sat' if current_day == '6' else 'reg'
        data = await get_line_data(cmd.db, line_number)
        if isinstance(data, list):
            response = discord.Embed(color=0x003050)
            response.set_author(
                name=f'BusPlus: Line {" ".join(pld.args)} Departures',
                icon_url=bp_logo)
            for terminus in data:
                terminus_name = terminus.get('terminus').title()
                terminus_times = terminus.get('times')
                time_list = make_time_list(terminus_times, current_time,
                                           data_pool)
                response.add_field(name=terminus_name,
                                   value=" | ".join(time_list),
                                   inline=False)
        else:
            response = error('Line not found or bad data.')
    else:
        response = error('Missing line number.')
    await pld.msg.channel.send(embed=response)
async def removeinactivewarning(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author == pld.msg.guild.owner:
        if pld.msg.mentions:
            if len(pld.args) == 2:
                target = pld.msg.mentions[0]
                warn_id = pld.args[1].lower()
                lookup = {
                    'guild': pld.msg.guild.id,
                    'target.id': target.id,
                    'warning.id': warn_id,
                    'warning.active': False
                }
                warn_data = await cmd.db[cmd.db.db_nam
                                         ].Warnings.find_one(lookup)
                if warn_data:
                    warn_iden = warn_data.get('warning').get('id')
                    await cmd.db[cmd.db.db_nam].Warnings.delete_one(lookup)
                    response = ok(f'Warning {warn_iden} deleted.')
                else:
                    response = not_found('Inactive warning not found.')
            else:
                response = error('Both user tag and warning ID are needed.')
        else:
            response = error('No user targeted.')
    else:
        response = denied('Access Denied. Server Owner needed.')
    await pld.msg.channel.send(embed=response)
Beispiel #9
0
async def osu(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        osu_input = '%20'.join(pld.args)
        profile_url = f'https://osu.ppy.sh/users/{osu_input.lower()}'
        user_data = await find_user_data(cmd.db, profile_url)
        username = user_data.get('username')
        if username:
            user_color = str(pld.msg.author.color)[1:]
            sig_url = f'https://lemmmy.pw/osusig/sig.php?colour=hex{user_color}&uname={osu_input}'
            response = discord.Embed(color=pld.msg.author.color)
            response.set_image(url=sig_url)
            response.set_author(name=f'{username}\'s osu! Profile',
                                url=profile_url,
                                icon_url=osu_logo)
        else:
            response = error('Unable to retrieve profile.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response)
Beispiel #10
0
async def givevirginity(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.mentions:
        target = pld.msg.mentions[0]
        if pld.msg.author.id != target.id:
            adoc = await cmd.db.get_profile(pld.msg.author.id, 'virginity')
            av = UserVirginity(adoc)
            if av.empty:
                av.user_id = pld.msg.author.id
            if av.virgin:
                tdoc = await cmd.db.get_profile(target.id, 'virginity')
                tv = UserVirginity(tdoc)
                if tv.empty:
                    tv.user_id = target.id
                question = f'Do you accept {pld.msg.author.display_name}\'s virginity?'
                if tv.virgin:
                    question = f'Do you accept {pld.msg.author.display_name}\'s virginity in exchange for your own?'
                question = discord.Embed(color=0xF9F9F9, title=f'❔ {question}')
                fake_msg = copy.copy(pld.msg)
                fake_msg.author = target
                success, timeout = await bool_dialogue(cmd.bot, fake_msg,
                                                       question)
                if success:
                    av.virgin = False
                    av.first = target.id
                    tv.virginities.append(pld.msg.author.id)
                    congrats_title = '🎉 Congrats, you are no longer a child!'
                    if tv.virgin:
                        tv.virgin = False
                        tv.first = pld.msg.author.id
                        av.virginities.append(target.id)
                        congrats_title = '🎉 Congrats, you are no longer children!'
                    await cmd.db.set_profile(pld.msg.author.id, 'virginity',
                                             av.to_dict())
                    await cmd.db.set_profile(target.id, 'virginity',
                                             tv.to_dict())
                    response = discord.Embed(color=0x66CC66,
                                             title=congrats_title)
                else:
                    if timeout:
                        response = discord.Embed(
                            color=0x696969,
                            title=f'🕙 {target.display_name} didn\'t respond.')
                    else:
                        response = discord.Embed(
                            color=0xBE1931,
                            title=f'❌ {target.display_name} rejected you.')
            else:
                response = error('You are not a virgin.')
        else:
            response = error(
                f'Now that\'s just sad, {pld.msg.author.display_name}...')
    else:
        response = error('No user mentioned.')
    await pld.msg.channel.send(embed=response)
async def blacklistuser(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        try:
            target_id = abs(int(pld.args[0]))
        except ValueError:
            target_id = None
        if target_id:
            if target_id not in cmd.bot.cfg.dsc.owners:
                target = await cmd.bot.get_user(target_id)
                if target:
                    target_id = target.id
                    target_name = target.name
                else:
                    target_name = target_id
                black_user_collection = cmd.db[
                    cmd.bot.cfg.db.database].BlacklistedUsers
                black_user_file = await black_user_collection.find_one(
                    {'user_id': target_id})
                if black_user_file:
                    if black_user_file.get('total'):
                        update_data = {
                            '$set': {
                                'user_id': target_id,
                                'total': False
                            }
                        }
                        icon, result = '🔓', 'un-blacklisted'
                    else:
                        update_data = {
                            '$set': {
                                'user_id': target_id,
                                'total': True
                            }
                        }
                        icon, result = '🔒', 'blacklisted'
                    await black_user_collection.update_one(
                        {'user_id': target_id}, update_data)
                else:
                    await black_user_collection.insert_one({
                        'user_id': target_id,
                        'total': True
                    })
                    icon, result = '🔒', 'blacklisted'
                await cmd.db.cache.del_cache(target_id)
                await cmd.db.cache.del_cache(f'{target_id}_checked')
                title = f'{icon} {target_name} has been {result}.'
                response = discord.Embed(color=0xFFCC4D, title=title)
            else:
                response = error('That target is immune.')
        else:
            response = error('Invalid user ID.')
    else:
        response = error('Missing user ID.')
    await pld.msg.channel.send(embed=response)
async def botsuggest(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    coll = cmd.db[cmd.db.db_nam].Suggestions
    if cmd.cfg.channel:
        if pld.args:
            sugg_text = ' '.join(pld.args)
            exmp_text = ' '.join(cmd.usage.split(' ')[1:])
            if sugg_text.lower() != exmp_text.lower():
                sugg_token = secrets.token_hex(4)
                await coll.insert_one(
                    make_sugg_data(pld.msg, pld.args, sugg_token))
                response = ok(f'Suggestion {sugg_token} submitted.')
            else:
                response = error(
                    'Please do not use this command to submit the usage example.'
                )
        else:
            response = error('Nothing inputted.')
    else:
        response = error('Missing suggestion channel configuration.')
    await pld.msg.channel.send(embed=response)
Beispiel #13
0
async def serversuggestion(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    sugg_channel = await cmd.db.get_guild_settings(pld.msg.guild.id,
                                                   'suggestion_channel')
    if pld.args:
        if sugg_channel:
            channel = pld.msg.guild.get_channel(int(sugg_channel))
            if channel:
                sugg_token = secrets.token_hex(4)
                sugg_msg = await channel.send(
                    embed=make_sugg_embed(pld.msg, pld.args, sugg_token))
                [await sugg_msg.add_reaction(r) for r in ['⬆', '⬇']]
                response = ok(f'Suggestion {sugg_token} submitted.')
            else:
                response = error('Cannot find suggestion channel.')
        else:
            response = error('Suggestion channel not set.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response)
Beispiel #14
0
async def shadowpollexpires(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        if len(pld.args) == 2:
            poll_id = pld.args[0].lower()
            time_input = pld.args[1]
            try:
                exp_in = convert_to_seconds(time_input)
                poll_file = await cmd.db[cmd.db.db_nam].ShadowPolls.find_one({'id': poll_id})
                if poll_file:
                    if poll_file['origin']['author'] == pld.msg.author.id:
                        end_stamp = arrow.utcnow().float_timestamp + exp_in
                        end_human = arrow.get(end_stamp).humanize()
                        end_datet = arrow.get(end_stamp).datetime
                        poll_file['settings'].update({'expires': end_stamp})
                        poll_coll = cmd.db[cmd.db.db_nam].ShadowPolls
                        await poll_coll.update_one({'id': poll_id}, {'$set': poll_file})
                        title = f'⏰ Poll set to expire {end_human}.'
                        response = discord.Embed(color=0xff3333, title=title, timestamp=end_datet)
                    else:
                        response = denied('You didn\'t make this poll.')
                else:
                    response = not_found('Poll not found.')
            except (LookupError, ValueError):
                response = error('Please use the format HH:MM:SS.')
        else:
            response = error('Missing arguments.')
    else:
        response = error('Missing poll ID and expiration time.')
    await pld.msg.channel.send(embed=response)
Beispiel #15
0
async def shadowpollinvisible(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        poll_id = pld.args[0].lower()
        poll_file = await cmd.db[cmd.db.db_nam].ShadowPolls.find_one({'id': poll_id})
        if poll_file:
            author = poll_file['origin']['author']
            if author == pld.msg.author.id:
                visible = poll_file['settings']['visible']
                if visible:
                    poll_file['settings'].update({'visible': False})
                    await cmd.db[cmd.db.db_nam].ShadowPolls.update_one({'id': poll_id}, {'$set': poll_file})
                    response = discord.Embed(color=0x161616, title=f'🕶 Poll {poll_file["id"]} is now invisible.')
                else:
                    response = error(f'Poll {poll_file["id"]} is already invisible.')
            else:
                response = denied('You didn\'t make this poll.')
        else:
            response = not_found('Poll not found.')
    else:
        response = error('Missing poll ID.')
    await pld.msg.channel.send(embed=response)
Beispiel #16
0
async def rps(_cmd, pld):
    """
    :param _cmd: The command object referenced in the command.
    :type _cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        their_choice, counter = None, None
        sign_list = ['rock', 'paper', 'scissors']
        if pld.args[0].lower().startswith('r'):
            their_choice, counter = 'rock', 'paper'
        elif pld.args[0].lower().startswith('p'):
            their_choice, counter = 'paper', 'scissors'
        elif pld.args[0].lower().startswith('s'):
            their_choice, counter = 'scissors', 'rock'
        if their_choice:
            my_choice = secrets.choice(sign_list)
            if my_choice == their_choice:
                color, icon, resp = 0xFFCC4D, '🔥', 'It\'s a draw'
            elif my_choice == counter:
                color, icon, resp = 0x292929, '💣', 'You lose'
            else:
                color, icon, resp = 0x3B88C3, '💎', 'You win'
            response = discord.Embed(
                color=color, title=f'{icon} {my_choice.title()}! {resp}!')
        else:
            response = error('Invalid sign.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response)
Beispiel #17
0
async def disconnect(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.voice:
        same_bound = True
        if pld.msg.guild.voice_client:
            if pld.msg.guild.voice_client.channel.id != pld.msg.author.voice.channel.id:
                same_bound = False
        if same_bound:
            if pld.msg.guild.voice_client:
                await pld.msg.guild.voice_client.disconnect()
                if pld.msg.guild.id in cmd.bot.music.queues:
                    del cmd.bot.music.queues[pld.msg.guild.id]
                response = ok('Disconnected and purged.')
                requester = f'{pld.msg.author.name}#{pld.msg.author.discriminator}'
                response.set_author(name=requester, icon_url=user_avatar(pld.msg.author))
            else:
                response = error('I am not connected to any channel.')
        else:
            response = error('You are not in my voice channel.')
    else:
        response = error('You are not in a voice channel.')
    await pld.msg.channel.send(embed=response)
async def notify_failure(ath, tgt_usr, tgt_chn):
    """

    :param ath:
    :type ath:
    :param tgt_usr:
    :type tgt_usr:
    :param tgt_chn:
    :type tgt_chn:
    """
    desc = "This usually happens if there isn't enough data."
    desc += " Try targetting a channel where you talk frequently or have sent a lot of messages recently."
    req_usr = (
        'you' if ath.id == tgt_usr.id else ath.name) if ath else 'Unknown User'
    footer = f'Chain requested by {req_usr} in #{tgt_chn.name} on {tgt_chn.guild.name}.'
    guild_icon = str(
        tgt_chn.guild.icon_url
    ) if tgt_chn.guild.icon_url else 'https://i.imgur.com/xpDpHqz.png'
    response = error('Failed to parse entries for your chain.')
    response.set_footer(text=footer, icon_url=guild_icon)
    # noinspection PyBroadException
    try:
        await tgt_usr.send(embed=response)
    except Exception:
        pass
    if ath.id != tgt_usr.id:
        req_resp = error(
            f'Failed to parse entries for {tgt_usr.name}\'s chain.')
        req_resp.set_footer(text=footer, icon_url=guild_icon)
        # noinspection PyBroadException
        try:
            await ath.send(embed=req_resp)
        except Exception:
            pass
async def resetserver(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.id == pld.msg.guild.owner.id:
        settings, perms, valid = True, True, True
        perms_coll = cmd.db[cmd.db.db_nam].Permissions
        settings_coll = cmd.db[cmd.db.db_nam].ServerSettings
        if pld.args:
            if pld.args[-1].lower() == '--permsonly':
                settings = False
            elif pld.args[-1].lower() == '--settingsonly':
                perms = False
            else:
                valid = False
        if valid:
            if perms:
                await perms_coll.delete_one({'server_id': pld.msg.guild.id})
            if settings:
                await settings_coll.delete_one({'server_id': pld.msg.guild.id})
            title = f'Wiped all server {"permissions" if perms else ""}'
            title += " and " if perms and settings else ""
            title += 'settings' if settings else ''
            response = ok(f'{title}.')
        else:
            response = error('Invalid arguments, see usage example.')
    else:
        response = error('Settings can only be reset by the server owner.')
    await pld.msg.channel.send(embed=response)
async def choosemany(_cmd, pld):
    """
    :param _cmd: The command object referenced in the command.
    :type _cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if len(pld.args) >= 2:
        if pld.args[0].isdigit():
            choices = ' '.join(pld.args[1:]).split('; ')
            limit = int(pld.args[0])
            if 0 < limit < len(choices):
                results = []
                for _ in range(limit):
                    choice = choices.pop(secrets.randbelow(len(choices)))
                    results.append(choice)
                response = discord.Embed(color=0x1ABC9C, title='🤔 I choose...')
                results = list(map(lambda x: x if len(x) < 25 else x[:25] + '...', results))
                response.description = '\n'.join(results)
            else:
                response = error('Limit must be lower than the number of choices.')
        else:
            response = error('Limit must be a number.')
    else:
        response = error('Invalid number of arguments.')
    await pld.msg.channel.send(embed=response)
Beispiel #21
0
async def starboardemote(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_guild:
        starboard_doc = pld.settings.get('starboard') or {}
        if pld.args:
            new_emote = pld.args[0][0]
            if category(new_emote) == 'So':
                starboard_doc.update({'emote': new_emote})
                await cmd.db.set_guild_settings(pld.msg.guild.id, 'starboard', starboard_doc)
                response = ok(f'Starboard emote set to {new_emote}')
            else:
                response = error('Emote must be native to Discord.')
        else:
            emote = starboard_doc.get('emote')
            if emote:
                response = discord.Embed(color=0xFFAC33, title=f'🌟 The current emote is {emote}')
            else:
                response = error('An emote has not been set.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
async def editline(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if len(pld.args) >= 3:
        edit_line = ' '.join(pld.args[2:])
        list_coll = cmd.db[cmd.db.db_nam].CustomLists
        lookup_data = {'server_id': pld.msg.guild.id, 'list_id': pld.args[0].lower()}
        list_file = await list_coll.find_one(lookup_data)
        if list_file:
            if user_auth(pld.msg, list_file):
                line = pld.args[1]
                if line.isdigit():
                    try:
                        line_num = max(1, int(line))
                        list_file.get('contents', [])[line_num - 1] = edit_line
                        await list_coll.update_one(lookup_data, {'$set': list_file})
                        response = discord.Embed(color=0xF9F9F9, title=f'📝 Line {line_num} was edited.')
                    except IndexError:
                        response = not_found('Line not found.')
                else:
                    response = error('Invalid line number.')
            else:
                mode = 'private' if list_file.get('mode') == 'private' else 'locked'
                response = discord.Embed(color=0xFFAC33, title=f'🔏 This list is {mode}.')
        else:
            response = error('Missing or invalid list ID.')
    else:
        response = error('Not enough arguments.')
    await pld.msg.channel.send(embed=response)
async def unbindinvite(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.guild_permissions.create_instant_invite:
        if pld.args:
            invite_id = pld.args[0]
            forced = pld.args[-1] == ':f'
            invites = await pld.msg.guild.invites()
            target_inv = discord.utils.find(lambda inv: inv.id.lower() == invite_id.lower(), invites)
            if target_inv or forced:
                if forced:
                    inv_id = invite_id
                else:
                    inv_id = target_inv.id
                bindings = pld.settings.get('bound_invites')
                if bindings is None:
                    bindings = {}
                if inv_id in bindings:
                    bindings.pop(inv_id)
                    await cmd.db.set_guild_settings(pld.msg.guild.id, 'bound_invites', bindings)
                    response = ok(f'Invite {inv_id} has been unbound.')
                else:
                    response = error(f'Invite {inv_id} not bound.')
            else:
                response = error('No invite with that ID was found.')
        else:
            response = error('Not enough arguments. Invite and role name needed.')
    else:
        response = denied('Access Denied. Create Instant Invites needed.')
    await pld.msg.channel.send(embed=response)
Beispiel #24
0
async def destroyitem(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    item_core = await get_item_core(cmd.db)
    if pld.args:
        id_lookup = pld.args[0]
        inv_item = await cmd.db[cmd.db.db_nam].Inventory.find_one({'items.item_id': id_lookup})
        if inv_item:
            target = await cmd.bot.get_user(inv_item.get('user_id'))
            item_data = None
            for item in inv_item.get('items', []):
                if item.get('item_id') == id_lookup:
                    item_data = item
                    break
            item_id = item_data.get('item_id')
            item_file_id = item_data.get('item_file_id')
            await cmd.db.del_from_inventory(target, item_id)
            item_o = item_core.get_item_by_file_id(item_file_id)
            connector = 'a'
            if item_o.name[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                connector = 'an'
            success_text = f'{item_o.icon} I have removed {connector} {item_o.name} from {target.display_name}.'
            response = discord.Embed(color=item_o.color, title=success_text)
        else:
            response = error('No item with that ID was found.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response)
async def generateresource(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.mentions:
        if len(pld.args) >= 3:
            target = pld.msg.mentions[0]
            if not target.bot:
                try:
                    amount = abs(int(pld.args[-1]))
                    currency = cmd.bot.cfg.pref.currency.lower()
                    res_nam = 'currency' if pld.args[0].lower(
                    ) == currency else pld.args[0].lower()
                    await cmd.db.add_resource(target.id, res_nam, amount,
                                              cmd.name, pld.msg, False)
                    response = ok(
                        f'Ok, I\'ve given {amount} {res_nam} to {target.display_name}.'
                    )
                except ValueError:
                    response = error('Invalid amount.')
            else:
                response = error('You can\'t give resources to bots.')
        else:
            response = error('Resource name, amount and target needed.')
    else:
        response = error('No user targeted.')
    await pld.msg.channel.send(embed=response)
async def repeat(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.guild.voice_client:
        if pld.msg.author.voice:
            if pld.msg.guild.voice_client.channel.id == pld.msg.author.voice.channel.id:
                if pld.msg.guild.id in cmd.bot.music.repeaters:
                    cmd.bot.music.repeaters.remove(pld.msg.guild.id)
                    response = discord.Embed(
                        color=0x3B88C3,
                        title='➡ The queue will no longer repeat.')
                else:
                    cmd.bot.music.repeaters.append(pld.msg.guild.id)
                    response = discord.Embed(
                        color=0x3B88C3, title='🔁 The queue will now repeat.')
            else:
                response = error('You are not in my channel.')
        else:
            response = error('You are not in a voice channel.')
    else:
        response = error('I am not playing anything.')
    await pld.msg.channel.send(embed=response)
Beispiel #27
0
async def giphy(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if cmd.cfg.api_key:
        if pld.args:
            qry = ' '.join(pld.args)
            url = f'https://api.giphy.com/v1/gifs/search?q={qry}&api_key={cmd.cfg.api_key}'
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as data_response:
                    search_data = await data_response.read()
                    search_data = json.loads(search_data)
            data = search_data.get('data')
            if data:
                data = secrets.choice(data)
                gif_id = data.get('id')
                gif_url = f'https://media.giphy.com/media/{gif_id}/giphy.gif'
                response = discord.Embed(color=0x262626)
                response.set_image(url=gif_url)
                response.set_footer(icon_url=giphy_icon,
                                    text='Powered By GIPHY.')
            else:
                response = not_found('No results')
        else:
            response = error('Nothing inputted.')
    else:
        response = error('The API Key is missing.')
    await pld.msg.channel.send(embed=response)
Beispiel #28
0
async def pause(_cmd, pld):
    """
    :param _cmd: The command object referenced in the command.
    :type _cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.voice:
        same_bound = True
        if pld.msg.guild.voice_client:
            if pld.msg.guild.voice_client.channel.id != pld.msg.author.voice.channel.id:
                same_bound = False
        if same_bound:
            if pld.msg.guild.voice_client:
                if pld.msg.guild.voice_client.is_playing():
                    pld.msg.guild.voice_client.pause()
                    response = discord.Embed(color=0x3B88C3,
                                             title='⏸ Music player paused.')
                else:
                    response = error('The player is not active.')
            else:
                response = error('I am not connected to a voice channel.')
        else:
            response = error('You are not in my voice channel.')
    else:
        response = error('You are not in a voice channel.')
    await pld.msg.channel.send(embed=response)
async def addreactor(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_guild:
        if len(pld.args) >= 2:
            trigger = ' '.join(pld.args[:-1]).lower().strip()
            if len(trigger) <= 200:
                if '.' not in trigger:
                    reaction = pld.args[-1].strip('<> ')
                    auto_reactions = pld.settings.get('reactor_triggers', {})
                    res_text = 'updated' if trigger in auto_reactions else 'added'
                    auto_reactions.update({trigger: reaction})
                    await cmd.db.set_guild_settings(pld.msg.guild.id,
                                                    'reactor_triggers',
                                                    auto_reactions)
                    response = ok(f'{trigger} has been {res_text}')
                else:
                    response = error('The trigger can\'t have a dot in it.')
            else:
                response = error('The trigger has a limit of 200 characters.')
        else:
            response = error('Invalid number of arguments.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
Beispiel #30
0
async def removereaction(_cmd, pld):
    """
    :param _cmd: The command object referenced in the command.
    :type _cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.msg.author.permissions_in(pld.msg.channel).manage_messages:
        if len(pld.args) == 2:
            mid, emote = pld.args
            if mid.isdigit():
                message = await message_search(mid, pld.msg)
                if message:
                    if pld.msg.guild.me.permissions_in(message.channel).manage_messages:
                        removed = await remove_emote(message, emote)
                        if removed:
                            response = ok('Reaction removed.')
                        else:
                            response = not_found('Emote not found on that message.')
                    else:
                        response = error('I can\'t remove reactions in that channel.')
                else:
                    response = not_found('Message not found.')
            else:
                response = error('Invalid message ID.')
        else:
            response = error('Invalid number of arguments.')
    else:
        response = denied('Access Denied. Manage Messages needed.')
    await pld.msg.channel.send(embed=response)