async def _iall(self, ctx: discord.ext.commands.context.Context):
        """marks all text channels as not monitored

        $ignore all

        Parameters:
        no parameters

        Usages:
        $ignore all
            marks all text channels as not monitored
        """
        print(type(ctx.bot), ctx.bot)
        sql_c, database = functions.get_database()
        channels = [[x.id, x.name] for x in ctx.bot.get_all_channels()
                    if x.guild.id == ctx.guild.id
                    and isinstance(x, discord.TextChannel)]
        for channel in channels:
            sql_c.execute(
                'insert or replace into ignored_channel (guild, id) values (?, ?)',
                (
                    ctx.guild.id,
                    channel[0],
                ))
            database.commit()
        await ctx.send(
            f"No longer monitoring the following channels: {', '.join([c[1] for c in channels])}"
        )
    async def _wall(self, ctx: discord.ext.commands.context.Context):
        """marks all text channels as monitored
        $watch all

        Parameters:
        no parameters

        Usages:
        watch all
            marks all text channels as monitored
        """
        sql_c, database = functions.get_database()
        channels = [[x.id, x.name] for x in ctx.bot.get_all_channels()
                    if x.guild.id == ctx.guild.id
                    and isinstance(x, discord.TextChannel)]
        for channel in channels:
            sql_c.execute(
                'delete from ignored_channels where guild=? and id=?', (
                    ctx.guild.id,
                    channel[0],
                ))
            database.commit()
        await ctx.send(
            f"Now monitoring the following channels: {', '.join([c[1] for c in channels])}"
        )
    async def invite(self, ctx, *role):
        """sets the role invited users receive

        $role invite <role>

        Parameters:
        <role>
            required parameter
            the name of the role to be assigned
            all words given are joined to form one role title

        Usages:
        $role invite new user
            will set any invited user to the role new user

        $role invite basic
            will set any invited user to the role basic
        """
        role2 = [r for r in ctx.guild.roles if r.name == ' '.join(role)]

        if role and not role2:
            role = ' '.join(role)
            return await ctx.send(
                f'I do not see {role} in the guild roles, cannot assign it',
                delete_after=bot_message_expire)

        if role2:
            role = role2[0].name

        sql_c, database = functions.get_database()
        saved_roles = sql_c.execute(
            'select * from member_invite_roles where guild=?',
            (ctx.guild.id, )).fetchone()
        if saved_roles:
            saved_roles = list(saved_roles)
        else:
            saved_roles = [ctx.guild.id, '', '', 0]

        if role:
            saved_roles[1] = role
            sql_c.execute(
                'insert or replace into member_invite_roles '
                '(guild, role_new, role_default, accept) values (?, ?, ?, ?)',
                saved_roles)
            database.commit()
            await ctx.send(
                f'Role auto-assigned to newly invited users is {role}')
        else:
            role = role = saved_roles[1] if saved_roles[
                3] == 1 else saved_roles[2]
            role2 = [r for r in ctx.guild.roles if r.name == role]
            if role:
                await ctx.send(
                    f'Role auto-assigned to newly invited users is {role2[0].mention}'
                )
            else:
                await ctx.send(
                    f'Role auto-assigned to newly invited users is not configured'
                )
Esempio n. 4
0
def main():
    os.system("clear")
    print(welcome)
    score = 100
    score_flag = 1
    words_db = get_database()  # words database read

    #  Random word selection based on the database length
    word_number = random.randint(1, len(words_db))
    word_select = words_db[word_number]
    word_select = word_select[:-1]  # Remove the last character "\n"
    word_select_list = [i_letter for i_letter in word_select
                        ]  # Word selected as list mode
    word_select_list_orig = [i_letter for i_letter in word_select
                             ]  # Word selected as list mode without normalize

    # Normalize each character, remove the accents
    n = 0
    for i_character in word_select_list:
        if i_character != "ñ":
            word_select_list[n] = normalize_character(i_character)
        else:
            word_select_list[n] = i_character
        n += 1

    # Word to user complete "_ _ _ _ _ _ _"
    word_building = []
    for j in range(1, len(word_select) + 1):
        word_building.insert(j, "_")

    print(*word_building)  # First print

    while True:
        n_input = input("Enter a letter: ")
        assert len(n_input) == 1, "Press just one character."
        os.system("clear")
        i = 0

        for n_letter in range(0, len(word_select)):
            if n_input == word_select_list[n_letter]:
                word_building[n_letter] = word_select_list_orig[n_letter]
                score_flag = 0

        if score_flag:
            score -= 1

        if word_building.count("_") == 0:
            break

        print(welcome)
        print(*word_building)
        print("Score: ", score)
        i += 1
        score_flag = 1
    print(welcome)
    print(won)
    print("The word was: ", word_select)
    print("Your score is: ", score)
    async def force_accept(self, ctx, parameter=None):
        """sets whether users must $acccept the rules
        if enabled, users are given the invite role first
            when they $accept, they are given the default role

        if disabled, they are given the default role.

        $role force_accept <setting>

        Parameters:
        <setting>
            required parameter
            on is one of 'yes', 'y', 'true', 't', '1', 'enable', 'on', 'affirmative'
            off is on of 'no', 'n', 'false', 'f', '0', 'disable', 'off', 'negative'
            case insensitive

        Usages:
        $role force_accept 1
            will force new users to $accept before being given the default role

        $role force_accept n
            will default new users to the default role without $accept-ing first
        """
        sql_c, database = functions.get_database()
        saved_roles = sql_c.execute(
            'select * from member_invite_roles where guild=?',
            (ctx.guild.id, )).fetchone()
        if saved_roles:
            saved_roles = list(saved_roles)
        else:
            saved_roles = [ctx.guild.id, '', '', 0]
        setting = functions.boolean(parameter)
        if setting:
            saved_roles[3] = 1
        elif setting is not None:
            saved_roles = 0
        else:
            on, off = functions.boolean(show=True)
            await ctx.send(
                f"{parameter} is not recognised.  "
                f"\n\tTo enable, use one of [{', '.join(on)}]"
                f"\n\tTo disable, use one of [{', '.join(off)}]"
                "\n\n\tparameter is not case sensitive",
                delete_after=bot_message_expire)

        if parameter and setting:  # gave a setting and it is recognised boolean
            saved_roles[3] = 1 if setting else 0
            sql_c.execute(
                'insert or replace into member_invite_roles '
                '(guild, role_new, role_default, accept) values (?, ?, ?, ?)',
                saved_roles)
            database.commit()
 async def ignored(self, ctx):
     """outputs a list of the text channels that are not being monitored"""
     sql_c, database = functions.get_database()
     ignoring_channels = sql_c.execute(
         'select * from ignored_channels where guild=?',
         (ctx.guild.id, )).fetchall()
     ignoring_roles = sql_c.execute(
         'select * from ignored_roles where guild=?',
         (ctx.guild.id, )).fetchall()
     ignoring_users = sql_c.execute(
         'select * from ignored_users where guild=?',
         (ctx.guild.id, )).fetchall()
     channels = [(self.bot.get_channel(x[1])).name
                 for x in ignoring_channels]
     roles = [
         discord.utils.get(ctx.guild.roles, id=x[1]).name
         for x in ignoring_roles
     ]
     users = [(self.bot.get_user(x[1])).name for x in ignoring_users]
     ignoring = channels + roles + users
     m = [
         'The guild owner, admin privileged users, and this bot\'s commands are ignored by default\n'
         'The following are also not monitored:'
     ]
     if channels:
         m += [f'Channels:        {", ".join(channels)}']
     if roles:
         m += [f'Roles:        {", ".join(roles)}']
     if users:
         m += [f'Users:        {", ".join(users)}']
     if not ignoring:
         m += [
             'Nothing, all other roles/channels/users are being monitored.'
         ]
     m = '\n'.join(m)
     await ctx.send(m)
    async def watch(self, ctx):
        """marks a channel, or channels, monitored
        if no channels are mentioned, the current channel is assumed

        watch [all command] [#channel...] [@role...] [@user...]

        Parameters:
        [all command]
            optional sub-command
            [#channel...] is not used if [all] is provided
            invokes the all sub-command:
                sets watch for all channels on the server
        [#channel...]
            optional parameter
            zero or more channel mentions
            defaults to current channel if no other mentions are given

        [@role...]
            optional parameter
            zero or more role mentions
            ignored if not given

        [@user...]
            optional parameter
            zero or more user mentions
            ignored if not given

        Usages:
        $watch
            watches the current channel

        $watch all
            calls the all sub-command, watches all text channels

        $watch #channel1 #channel2
            watches channel1 and channel2

        $watch #channel1 @everyone
            watches channel1 and every member of the everyone role

        $watch #channel1 @user
            watches channel1 and @user
            """
        if ctx.invoked_subcommand:
            return
        sql_c, database = functions.get_database()
        channels = ctx.message.channel_mentions
        users = ctx.message.mentions
        roles = ctx.message.role_mentions
        mentions = channels + users + roles
        if not mentions:
            content = re.sub(
                f'.*\{str(ctx.bot.command_prefix)}{str(ctx.command)}[ ]*', '',
                ctx.message.content)
            if content:
                return await ctx.send(
                    f'"{content}" is neither a valid channel/user/role mention nor sub-command, '
                    f'aborting\n if this were an attempt to mention a role, it is necessary to '
                    f'first enable mentioning this role.',
                    delete_after=bot_message_expire)
            channels = [ctx.message.channel]
        for channel in channels:
            sql_c.execute(
                'delete from ignored_channels where guild=? and id=?', (
                    ctx.guild.id,
                    channel.id,
                ))
        for role in roles:
            sql_c.execute('delete from ignored_roles where guild=? and id=?', (
                ctx.guild.id,
                role.id,
            ))
        for user in users:
            sql_c.execute('delete from ignored_users where guild=? and id=?', (
                ctx.guild.id,
                user.id,
            ))
        database.commit()
        m = ['Now monitoring the following']
        if channels:
            m += [f'Channels:        {", ".join([c.name for c in channels])}']
        if roles:
            m += [f'Roles:        {", ".join([c.name for c in roles])}']
        if users:
            m += [f'Users:        {", ".join([c.name for c in users])}']
        m = '\n'.join(m)
        await ctx.send(m)
    async def messages(self, ctx, member: discord.Member = None):
        """$messages [@user]

        prints the given user's recent messages
        shows oldest first
        splits across several messages if necessary

        Parameters:
        [@user]
            optional parameter, maximum of one user mention

        Usages:
        $messages
            will show your recent messages

        $messages @user
            will show @user's recent messages
        """

        if not member:
            member = ctx.message.author
        sql_c, database = functions.get_database()
        query = 'select m5, m4, m3, m2, m1 from messages where channel=? and id=?;'
        recent = sql_c.execute(query, (
            ctx.channel.id,
            member.mention,
        )).fetchall()
        if recent:
            recent = recent[0]  # drop the outer array layer
        title = f'{member.display_name}\'s recent messages'
        embed = discord.Embed()
        embed1 = None
        embed2 = None
        embed3 = None
        length = 0
        for i, message in enumerate([m.split(':', 1) for m in recent]):
            if len(message) == 2 and isinstance(message, list):
                message = message[1]
            if message != '':
                if len(message) + length > 5500:
                    if embed1 and embed2:
                        embed3 = embed
                    elif embed1:
                        embed2 = embed
                    else:
                        embed1 = embed
                    embed = discord.Embed()
                    length = 0

                if len(message) > 1012:
                    embed.add_field(name=str(i - len(recent)) + '.1',
                                    inline=False,
                                    value=message[:1012])
                    embed.add_field(name=str(i - len(recent)) + '.2',
                                    inline=False,
                                    value=message[1012:])
                else:
                    embed.add_field(name=str(i - len(recent)),
                                    inline=False,
                                    value=message)
                length += len(message)

        if embed1 and embed2:
            embed3 = embed
        elif embed1:
            embed2 = embed
        else:
            embed1 = embed

        if embed3:
            embed1.title = title + ', part 1'
            embed2.title = title + ', part 2'
            embed3.title = title + ', part 3'
        elif embed2:
            embed1.title = title + ', part 1'
            embed2.title = title + ', part 2'
        else:
            embed1.title = title

        await ctx.send(embed=embed1, delete_after=bot_message_expire)
        if embed2:
            await ctx.send(embed=embed2, delete_after=bot_message_expire)
        if embed3:
            await ctx.send(embed=embed3, delete_after=bot_message_expire)