Esempio n. 1
0
async def greetdmembed(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:
        greet_embed = pld.settings.get('greet_dm_embed') or {}
        embed_data = {
            'active': greet_embed.get('active'),
            'color': greet_embed.get('color'),
            'thumbnail': greet_embed.get('thumbnail'),
            'image': greet_embed.get('image')
        }
        if pld.args:
            queries = ' '.join(pld.args).split()
            qrys = [(f, d, v)
                    for f, d, v in [qry.partition(':') for qry in queries]]
            fields = ['color', 'thumbnail', 'image']
            results = []
            for qry in qrys:
                if qry[1]:
                    field, value = qry[0].lower(), qry[2]
                    if field in fields:
                        if value.lower() == 'remove':
                            embed_data.update({field: None})
                            res = 'Removed'
                        elif check_field(field, value):
                            if field == 'color':
                                value = int(value, 16)
                            embed_data.update({field: value})
                            res = 'Set'
                        else:
                            res = 'Invalid Value'
                    else:
                        res = 'Invalid Field'
                    res_line = f'{field.title()}: {res}'
                    results.append(res_line)
                else:
                    response = error(
                        'Separate fields and values with a colon.')
                    await pld.msg.channel.send(embed=response)
                    return
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'greet_dm_embed',
                                            embed_data)
            response = ok('DM Greeting Embed updated.')
            response.description = '\n'.join(results)
        else:
            if greet_embed.get('active'):
                state, ender = False, 'disabled'
            else:
                state, ender = True, 'enabled'
            embed_data.update({'active': state})
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'greet_dm_embed',
                                            embed_data)
            response = ok(f'DM Greeting Embed {ender}.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
async def wfnewschannel(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_channels:
        if pld.msg.channel_mentions:
            target_channel = pld.msg.channel_mentions[0]
        else:
            if pld.args:
                if pld.args[0].lower() == 'disable':
                    await cmd.db.set_guild_settings(pld.msg.guild.id,
                                                    'warframe_news_channel',
                                                    None)
                    response = ok('Warframe News Channel disabled.')
                    await pld.msg.channel.send(embed=response)
                return
            else:
                target_channel = pld.msg.channel
        await cmd.db.set_guild_settings(pld.msg.guild.id,
                                        'warframe_news_channel',
                                        target_channel.id)
        response = ok(f'Warframe News Channel set to #{target_channel.name}')
    else:
        response = denied('Access Denied. Manage Channels needed.')
    await pld.msg.channel.send(embed=response)
async def filterignore(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 pld.args:
            if len(pld.args) >= 3:
                filter_name = pld.args[1].lower()
                target_type = get_target_type(pld.args[0].lower())
                if target_type:
                    if filter_name in filter_names:
                        targets, valid = get_targets(pld.msg, pld.args, target_type)
                        if valid:
                            overrides = pld.settings.get('filter_overrides') or {}
                            override_data = overrides.get(filter_name)
                            if not override_data:
                                override_data = {'users': [], 'channels': [], 'roles': []}
                            override = override_data.get(target_type) or []
                            error_response = None
                            for target in targets:
                                if target.id not in override:
                                    override.append(target.id)
                                else:
                                    error_response = error(f'{target.name} already has an override for that filter.')
                                    break
                            if not error_response:
                                override_data.update({target_type: override})
                                overrides.update({filter_name: override_data})
                                await cmd.db.set_guild_settings(pld.msg.guild.id, 'filter_overrides', overrides)
                                if len(targets) > 1:
                                    starter = f'{len(targets)} {target_type}'
                                    response = ok(f'{starter} are no longer affected by `blocked{filter_name}`.')
                                else:
                                    pnd = '#' if target_type == 'channels' else ''
                                    starter = f'{pnd}{targets[0].name}'
                                    response = ok(f'{starter} is no longer affected by `blocked{filter_name}`.')
                            else:
                                await pld.msg.channel.send(embed=error_response)
                                return
                        else:
                            if targets:
                                response = not_found(f'{targets} not found.')
                            else:
                                ender = 'specified' if target_type == 'roles' else 'targeted'
                                response = not_found(f'No {target_type} {ender}.')
                    else:
                        response = error('Invalid filter.')
                else:
                    response = error('Invalid target type.')
            else:
                response = error('Not enough arguments.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
async def approvesuggestion(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:
        token, title, description = parse_approval(pld.args)
        suggestion = await cmd.db[cmd.db.db_nam].Suggestions.find_one(
            {'suggestion.id': token})
        if suggestion:
            await react_to_suggestion(cmd.bot, suggestion, '✅', False)
            make_issue = False if title.lower().startswith('noissue') else True
            title = title if make_issue else title.partition(' ')[2]
            gl_desc = make_gl_suggestion(token, description, suggestion)
            gl_issue_url = None
            if cmd.cfg.token and cmd.cfg.project and make_issue:
                gl_issue_url = await submit_gl_issue(cmd.cfg.token,
                                                     cmd.cfg.project, title,
                                                     gl_desc)
            athr = await cmd.bot.get_user(suggestion.get('user', {}).get('id'))
            if athr:
                to_user = ok(
                    f'Suggestion {token} approved by {pld.msg.author.display_name}.'
                )
                if gl_issue_url:
                    to_user_desc = 'Your suggestion was approved, you can view its status and details [here]'
                    to_user_desc += f'({gl_issue_url}). If you need info, the support server is in the help command.'
                else:
                    to_user_desc = f'```md\n{gl_desc}\n```'
                to_user.description = to_user_desc
                try:
                    await athr.send(embed=to_user)
                    response = ok(f'Suggestion {token} approved.')
                except (discord.Forbidden, discord.NotFound):
                    response = ok(
                        f'Suggestion {token} approved, but delivery to author failed.'
                    )
            else:
                response = ok(
                    f'Suggestion {token} approved, but the author was not found.'
                )
        else:
            response = error('No suggestion entry with that ID was found.')
    else:
        response = error('Not enough arguments.')
    await pld.msg.channel.send(embed=response)
Esempio n. 5
0
async def unban(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).ban_members:
        if pld.args:
            lookup = ' '.join(pld.args)
            target = None
            banlist = await pld.msg.guild.bans()
            for entry in banlist:
                if entry.user.name.lower() == lookup.lower():
                    target = entry.user
                    break
            if target:
                await pld.msg.guild.unban(
                    target,
                    reason=
                    f'By {pld.msg.author.name}#{pld.msg.author.discriminator}.'
                )
                log_embed = generate_log_embed(pld.msg, target)
                await log_event(cmd.bot, pld.settings, log_embed, 'log_bans')
                response = ok(f'{target.name} has been unbanned.')
            else:
                response = discord.Embed(
                    title=f'🔍 {lookup} not found in the ban list.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Ban permissions needed.')
    await pld.msg.channel.send(embed=response)
async def autoroletimeout(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 pld.args:
            try:
                timeout = abs(int(pld.args[0]))
            except ValueError:
                timeout = None
            if timeout is not None:
                await cmd.db.set_guild_settings(pld.msg.guild.id,
                                                'auto_role_timeout', timeout)
                response = ok(f'Timeout set to {timeout} seconds.')
            else:
                response = error('This role is above my highest role.')
        else:
            timeout = pld.settings.get('auto_role_timeout', 0)
            response = discord.Embed(
                color=0x696969,
                title=f'🕙 The current timeout is {timeout} seconds.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
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)
Esempio n. 8
0
async def warmachinename(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:
        lookup = pld.args[0]
        new_name = ' '.join(pld.args[1:])
        machines = await SigmaMachine.get_machines(cmd.db, pld.msg.author)
        machine: SigmaMachine = find_machine(lookup, machines)
        if machine:
            sumarum = await cmd.db.get_resource(pld.msg.author.id, 'sumarum')
            if sumarum.current >= price:
                machine.name = new_name
                await machine.update()
                response = ok(f'Machine {machine.id} renamed.')
            else:
                response = error('Not enough sumarum.')
        else:
            response = not_found('No warmachine found.')
    else:
        response = error('Invalid number of arguments.')
    await pld.msg.channel.send(embed=response)
Esempio n. 9
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)
Esempio n. 10
0
async def permissions(_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
    """
    allowed_list = []
    disallowed_list = []
    if pld.msg.mentions:
        user_q = pld.msg.mentions[0]
    else:
        user_q = pld.msg.author
    response = info(f'{user_q.name}\'s Permissions')
    for permission in user_q.guild_permissions:
        if permission[1]:
            allowed_list.append(permission[0].replace('_', ' ').title())
        else:
            disallowed_list.append(permission[0].replace('_', ' ').title())
    if len(allowed_list) == 0:
        allowed_list = ['None']
    if len(disallowed_list) == 0:
        disallowed_list = ['None']
    response.add_field(name='Allowed',
                       value='```yml\n - ' +
                       '\n - '.join(sorted(allowed_list)) + '\n```')
    response.add_field(name='Disallowed',
                       value='```yml\n - ' +
                       '\n - '.join(sorted(disallowed_list)) + '\n```')
    in_ch = ok('Permission list sent to you.')
    await pld.msg.author.send(embed=response)
    await pld.msg.channel.send(embed=in_ch)
Esempio n. 11
0
async def logmodule(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.manage_guild:
        if pld.args:
            module_name = pld.args[0].lower()
            if module_name in cmd.bot.modules.categories:
                logged_modules = pld.settings.get('logged_modules') or []
                if module_name in logged_modules:
                    result = 'disabled'
                    logged_modules.remove(module_name)
                else:
                    result = 'enabled'
                    logged_modules.append(module_name)
                await cmd.db.set_guild_settings(pld.msg.guild.id,
                                                'logged_modules',
                                                logged_modules)
                response = ok(f'{module_name.upper()} logging {result}.')
            else:
                response = not_found('Module not found.')
        else:
            response = error('No module given.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    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)
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)
Esempio n. 14
0
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)
Esempio n. 15
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)
Esempio n. 16
0
async def blockwords(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 pld.args:
            blocked_words = pld.settings.get('blocked_words', [])
            added_words = []
            for word in pld.args:
                if word.lower() not in blocked_words:
                    blocked_words.append(word.lower())
                    added_words.append(word.lower())
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'blocked_words',
                                            blocked_words)
            if added_words:
                response = ok(
                    f'I have added {len(added_words)} words to the blacklist.')
            else:
                response = info('No new words were added.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
Esempio n. 17
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)
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)
Esempio n. 19
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)
async def addselfrole(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.manage_roles:
        if pld.args:
            lookup = ' '.join(pld.args)
            target_role = discord.utils.find(lambda x: x.name.lower() == lookup.lower(), pld.msg.guild.roles)
            if target_role:
                role_below = bool(target_role.position < pld.msg.guild.me.top_role.position)
                if role_below:
                    selfroles = pld.settings.get('self_roles', [])
                    if target_role.id in selfroles:
                        response = error('This role is already self assignable.')
                    else:
                        selfroles.append(target_role.id)
                        await cmd.db.set_guild_settings(pld.msg.guild.id, 'self_roles', selfroles)
                        response = ok(f'{target_role.name} added.')
                else:
                    response = error('This role is above my highest role.')
            else:
                response = not_found(f'I can\'t find {lookup} on this server.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Manage Roles needed.')
    await pld.msg.channel.send(embed=response)
Esempio n. 21
0
async def quick_buy(cmd: SigmaCommand, pld: CommandPayload, choice: dict):
    """

    :param cmd:
    :type cmd:
    :param pld:
    :type pld:
    :param choice:
    :type choice:
    """
    currency = cmd.bot.cfg.pref.currency
    user_upgrades = await cmd.bot.db.get_profile(pld.msg.author.id,
                                                 'upgrades') or {}
    upgrade_level = user_upgrades.get(choice.get('id'), 0)
    upgrade_price = get_price(choice.get("cost"), upgrade_level)
    current_kud = await cmd.db.get_resource(pld.msg.author.id, 'currency')
    current_kud = current_kud.current
    if current_kud >= upgrade_price:
        user_upgrades.update({choice.get('id'): upgrade_level + 1})
        await cmd.db.set_profile(pld.msg.author.id, 'upgrades', user_upgrades)
        await cmd.db.del_resource(pld.msg.author.id, 'currency', upgrade_price,
                                  cmd.name, pld.msg)
        response = ok(
            f'Upgraded your {choice.get("name")} to Level {upgrade_level + 1}.'
        )
    else:
        response = discord.Embed(color=0xa7d28b,
                                 title=f'💸 You don\'t have enough {currency}.')
    await pld.msg.channel.send(embed=response)
Esempio n. 22
0
async def greetdmmessage(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 pld.args:
            greeting_text = ' '.join(pld.args)
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'greet_dm_message', greeting_text)
            response = ok('New DM Greeting Message set.')
        else:
            current_greeting = pld.settings.get('greet_dm_message')
            if not current_greeting:
                current_greeting = 'Hello {user_mention}, welcome to {server_name}.'
            greet_embed = pld.settings.get('greet_dm_embed') or {}
            if greet_embed.get('active'):
                response = await make_greet_embed(greet_embed, current_greeting, pld.msg.guild)
            else:
                response = info('Current DM Greeting Message')
                response.description = current_greeting
    else:
        response = denied('Access Denied. Manage Server needed.')
    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)
Esempio n. 24
0
async def byemessage(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 pld.args:
            goodbye_text = ' '.join(pld.args)
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'bye_message',
                                            goodbye_text)
            response = ok('New Goodbye Message set.')
        else:
            current_goodbye = pld.settings.get('bye_message')
            if not current_goodbye:
                current_goodbye = '{user_name} has left {server_name}.'
            bye_embed = pld.settings.get('bye_embed') or {}
            if bye_embed.get('active'):
                response = await make_bye_embed(bye_embed, current_goodbye,
                                                pld.msg.guild)
            else:
                response = info('Current Goodbye Message')
                response.description = current_goodbye
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
async def unblocknames(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 pld.args:
            blocked_names = pld.settings.get('blocked_names') or []
            removed_names = []
            if pld.args[-1].lower() == '--all':
                removed_names = blocked_names
                blocked_names = []
            else:
                for name in pld.args:
                    if name.lower() in blocked_names:
                        blocked_names.remove(name.lower())
                        removed_names.append(name.lower())
            await cmd.db.set_guild_settings(pld.msg.guild.id, 'blocked_names', blocked_names)
            if removed_names:
                ender = 's' if len(removed_names) > 1 else ''
                response = ok(f'I have removed {len(removed_names)} name{ender} from the blacklist.')
            else:
                response = info('No name were removed.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
async def syncinvites(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
    """
    try:
        invites = await pld.msg.guild.invites()
    except discord.Forbidden:
        invites = []
    await update_invites(pld.msg.guild, invites)
    bound_invites = pld.settings.get('bound_invites') or {}
    keys_to_remove = []
    for invite_code in bound_invites.keys():
        find_code = discord.utils.find(lambda x: x.id == invite_code, invites)
        if not find_code:
            keys_to_remove.append(invite_code)
    if keys_to_remove:
        for key_to_remove in keys_to_remove:
            bound_invites.pop(key_to_remove)
    await cmd.db.set_guild_settings(pld.msg.guild.id, 'bound_invites',
                                    bound_invites)
    noresp = False
    if pld.args:
        if pld.args[0] == 'noresp':
            noresp = True
    if not noresp:
        inv_count = len(invites)
        response = ok(f'Synced {inv_count} invites.')
        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)
async def unhardblockwords(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 pld.args:
            blocked_words = pld.settings.get('hardblocked_words')
            if blocked_words is None:
                blocked_words = []
            removed_words = []
            if pld.args[-1].lower() == '--all':
                removed_words = blocked_words
                blocked_words = []
            else:
                for word in pld.args:
                    if word.lower() in blocked_words:
                        blocked_words.remove(word.lower())
                        removed_words.append(word.lower())
            await cmd.db.set_guild_settings(pld.msg.guild.id,
                                            'hardblocked_words', blocked_words)
            if removed_words:
                response = ok(
                    f'I have removed {len(removed_words)} words from the heavy blacklist.'
                )
            else:
                response = info('No words were removed.')
        else:
            response = error('Nothing inputted.')
    else:
        response = denied('Access Denied. Manage Server needed.')
    await pld.msg.channel.send(embed=response)
Esempio n. 29
0
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)
Esempio n. 30
0
async def temproom(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
    """
    room_name = ' '.join(pld.args) or f'{pld.msg.author.display_name}\'s Room'
    room_name = f'[Σ] {room_name}'
    reason = f'Temporary voice channel by {pld.msg.author.name}#{pld.msg.author.discriminator}.'
    temp_vc_cat = await get_category(cmd, pld.msg.guild)
    if pld.msg.guild.me.permissions_in(temp_vc_cat).manage_channels:
        perms = {
            'manage_channels': True,
            'manage_roles': True,
            'read_messages': True,
            'connect': True,
            'speak': True
        }
        overwrites = {pld.msg.author: discord.PermissionOverwrite(**perms)}
        await pld.msg.guild.create_voice_channel(room_name,
                                                 reason=reason,
                                                 overwrites=overwrites,
                                                 category=temp_vc_cat)
        response = ok(f'{room_name} created.')
    else:
        response = error('I can\'t create channels in that category.')
    await pld.msg.channel.send(embed=response)