Esempio n. 1
0
    async def unlink(self, ctx, user: discord.Member):
        guild = ctx.guild

        with open("config/ValidGuilds.json", "r") as config:
            validated = ctx.guild.id in json.load(config)

        if not validated: raise GuildNotValidated

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(
                    "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                )
                await cursor.execute(
                    f'SELECT ic_id FROM accounts WHERE discord_id = ?',
                    (user.id, ))
                id = await cursor.fetchone()
                await cursor.execute(
                    f"DELETE FROM accounts WHERE discord_id = ?", (user.id, ))

                await conn.commit()

        if not id:
            await ctx.reply(f"{user.mention}'s account is not linked!",
                            mention_author=False,
                            allowed_mentions=discord.AllowedMentions.none())
            return

        logs = discord.utils.get(ctx.guild.channels, name="verification-logs")

        logged = discord.Embed(description=f"{user.mention} {user}",
                               timestamp=ctx.message.created_at,
                               color=discord.Color.red())

        logged.set_author(name="Account Unlinked", icon_url=user.avatar_url)
        logged.add_field(name="ID", value=id[0])
        logged.add_field(name="Unlinked By", value=str(ctx.author))

        await ctx.reply(
            f"Successfully unlinked an account from {user.mention}!",
            mention_author=False,
            allowed_mentions=discord.AllowedMentions.none())
        await logs.send(embed=logged)

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(f'SELECT * FROM accounts')
                amount_of_users = await cursor.fetchall()

        activity = discord.Activity(
            name=f"{len(amount_of_users)} Linked Accounts",
            type=discord.ActivityType.watching)
        await self.client.change_presence(status=discord.Status.online,
                                          activity=activity)
Esempio n. 2
0
    async def id(self, ctx, id):
        account = intersection.user.get_details_for_user(userId=int(id))
        userid = id

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(
                    "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                )

                await cursor.execute(
                    f'SELECT discord_id FROM accounts WHERE ic_id = {int(id)}')
                id = await cursor.fetchone()

        embed = discord.Embed(timestamp=ctx.message.created_at,
                              color=discord.Color.blue())

        if id:
            user = self.client.get_user(id[0])
            if user:
                embed.set_author(name=user, icon_url=user.avatar_url)
            else:
                embed.title = f"Searching for `{userid}`:"

        embed.add_field(
            name="Intersection Controller",
            value=
            f"**Nickname:** {account.name}\n**ID:** {account.objectId}\n**Followers:** {account.followers}\n**Last login:** <t:{round(account.lastLogin / 1000.0)}:R>\n**Maps:** {account.maps}"
        )
        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 3
0
    async def trending(self, ctx, gamemode, time, pos=1):
        dislike = self.client.get_emoji(759060520455766036)
        like = self.client.get_emoji(759059895424909380)
        pos -= 1

        if gamemode.lower() in ['sim', 'simulation', '1']: gamemode = 1
        elif gamemode.lower() in ['tc', 'trafficcontroller', '2']: gamemode = 2
        #elif gamemode.lower() in ['misc' 'miscellaneous' '3']: gamemode = 3

        map = intersection.map.find_top_maps(gameMode=gamemode,
                                             time=time,
                                             result=1,
                                             page=pos,
                                             offset=0)[0]

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(
                    "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                )

                await cursor.execute(
                    f'SELECT discord_id FROM accounts WHERE ic_id = {map.author}'
                )
                account = await cursor.fetchone()

        if account:
            discordid = account[0]

        else:
            discordid = None

        embed = discord.Embed(
            title=
            f"{map.name} {like} {map.votesUp} {dislike} {map.votesDown} :white_heart: {map.favorites}",
            description=map.desc,
            color=discord.Color.blue(),
            timestamp=ctx.message.created_at)
        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        if map.gameModeGroup == 1: mode = "Simulation"
        elif map.gameModeGroup == 2: mode = "Traffic Controller"
        elif map.gameModeGroup == 3: mode = "Miscellaneous"

        embed.add_field(name="Game Mode", value=mode)
        embed.add_field(name="Author", value=map.authorName)
        embed.add_field(name="Discord",
                        value=str(self.client.get_user(discordid)))

        embed.add_field(name="Created",
                        value=datetime.datetime.fromtimestamp(
                            round(map.created / 1000.0)))
        embed.add_field(name="Updated",
                        value=datetime.datetime.fromtimestamp(
                            round(map.updated / 1000.0)))
        embed.add_field(name="Version", value=map.mapVersion)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 4
0
    async def link(self, ctx, user : discord.User, object_id):

        with open("config/ValidGuilds.json", "r") as config:
            validated  = ctx.guild.id in json.load(config)

        if not validated: raise GuildNotValidated

        ic_user = intersection.user.get_details_for_user(userId = object_id)

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute("CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)")
                await cursor.execute(f"SELECT ic_id FROM accounts WHERE discord_id = {user.id}")
                data = await cursor.fetchone()
            
                if not data:
                    await cursor.execute(f"INSERT INTO accounts(discord_id, ic_id) VALUES({user.id}, {ic_user.objectId})")
                else:
                    await cursor.execute(f"UPDATE accounts SET ic_id = {ic_user.objectId} WHERE discord_id = {user.id}")

                await conn.commit()

        await ctx.reply(f"Successfully linked an account to {user.mention}!", mention_author = False, allowed_mentions = discord.AllowedMentions.none())   

        logs = discord.utils.get(ctx.guild.channels, name="verification-logs")

        logged = discord.Embed(
            description = f"{user.mention} {user}",
            timestamp = ctx.message.created_at,
            color = discord.Color.green()
        )

        logged.set_author(name="Account Linked", icon_url=user.avatar_url)
        logged.add_field(name="ID", value=object_id)
        logged.add_field(name="Linked By", value=str(ctx.author))

        await logs.send(embed = logged)       

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(f'SELECT * FROM accounts')
                amount_of_users = await cursor.fetchall()

        activity = discord.Activity(name=f"{len(amount_of_users)} Linked Accounts", type=discord.ActivityType.watching)
        await self.client.change_presence(status=discord.Status.online, activity=activity)
Esempio n. 5
0
    async def all(self, ctx, _round: int = -2):
        data_stream = io.BytesIO()

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:

                await cursor.execute("SELECT * FROM accounts")
                accounts = await cursor.fetchall()

        raw_followers = []

        async with ctx.channel.typing():
            for item in accounts:
                raw_followers.append(
                    round(
                        intersection.user.get_details_for_user(
                            userId=item[1]).followers, _round))

            raw_followers.sort()

            amount_of_followers = list(dict.fromkeys(raw_followers))

            counter = Counter(raw_followers)
            amount_of_users = []

            for item in amount_of_followers:
                amount_of_users.append(counter[item])

            y = amount_of_users  # amount of USERS
            x = amount_of_followers  # amount of FOLLOWERS

            plt.plot(x, y)

            plt.title("Followers")
            plt.ylabel("Amount of Users")
            plt.xlabel("Amount of Followers")

            plt.savefig(data_stream, format='png', bbox_inches="tight", dpi=80)
            plt.close()

            data_stream.seek(0)
            chart = discord.File(data_stream, filename="follower_chart.png")

            embed = discord.Embed(
                timestamp=ctx.message.created_at,
                color=discord.Color.blue(),
                title="Follower chart based on raw follower data")
            embed.set_footer(icon_url=ctx.author.avatar_url, text=ctx.author)
            embed.set_image(url="attachment://follower_chart.png")

            await ctx.reply(embed=embed, file=chart, mention_author=False)
Esempio n. 6
0
    async def name(self, ctx, *, name):
        account = None
        users = intersection.user.search_for_users(result=10, query=name)

        for user in users:
            if user.name == name:
                account = user

        if not account:
            embed = discord.Embed(
                description=f"<:error:905485648373370890> User not found!",
                color=discord.Color.from_rgb(237, 50, 31))

            await ctx.reply(embed=embed, mention_author=False)
            return

        account = intersection.user.get_details_for_user(
            userId=account.objectId)

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(
                    "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                )

                await cursor.execute(
                    f'SELECT discord_id FROM accounts WHERE ic_id = {account.objectId}'
                )
                id = await cursor.fetchone()

        embed = discord.Embed(timestamp=ctx.message.created_at,
                              color=discord.Color.blue())

        if id:
            user = self.client.get_user(id[0])
            if user:
                embed.set_author(name=user, icon_url=user.avatar_url)
            else:
                embed.title = f"Searching for `{name}`:"

        embed.add_field(
            name="Intersection Controller",
            value=
            f"**Nickname:** {account.name}\n**ID:** {account.objectId}\n**Followers:** {account.followers}\n**Last login:** <t:{round(account.lastLogin / 1000.0)}:R>\n**Maps:** {account.maps}"
        )
        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 7
0
    async def search(self, ctx, gamemode, *, query):
        if gamemode.lower() in ['sim', 'simulation', '1']: gamemode = 1
        elif gamemode.lower() in ['tc', 'trafficcontroller', '2']: gamemode = 2

        maps = intersection.map.search_for_maps(gameMode=gamemode,
                                                result=10,
                                                query=query)

        if not len(maps):
            embed = discord.Embed(
                description=
                f"<:error:905485648373370890> No maps with such a name found!",
                color=discord.Color.from_rgb(237, 50, 31))

            await ctx.reply(embed=embed, mention_author=False)
            return

        embed = discord.Embed(title=f"Searching for `{query}`:",
                              timestamp=ctx.message.created_at,
                              color=discord.Color.blue())

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                for map in maps:
                    linked = "Not linked"

                    await cursor.execute(
                        f'SELECT discord_id FROM accounts WHERE ic_id = {map.author}'
                    )
                    account = await cursor.fetchone()

                    if account:
                        linked = self.client.get_user(account[0])

                    embed.add_field(
                        name=
                        f"{map.name} <:IC_like:759059895424909380> {map.votesUp} <:IC_dislike:759060520455766036> {map.votesDown} :white_heart: {map.favorites}",
                        value=
                        f"**Author:** {map.authorName} | **Discord:** {linked}",
                        inline=False)

        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 8
0
    async def on_ready(self):
        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:

                await cursor.execute(f'SELECT * FROM accounts')
                amount_of_users =  await cursor.fetchall()

        login_info = f">> Logged in as {self.client.user}"
        status = f"{len(amount_of_users)} Linked Accounts"

        if DEBUG:   
            login_info += " DEBUG MODE IS ENABLED"
            status += " | DEBUG"

        print(login_info)

        activity = discord.Activity(name=status, type=discord.ActivityType.watching)
        await self.client.change_presence(status=discord.Status.online, activity=activity)

        follower_roles.start()
Esempio n. 9
0
async def update_follower_roles(member: discord.Member, guild: discord.Guild):
    async with asqlite.connect("database.sqlite") as conn:
        async with conn.cursor() as cursor:

            await cursor.execute(
                f'SELECT ic_id FROM accounts WHERE discord_id = {member.id}')
            id = await cursor.fetchone()

    if id:
        ic_user_object = intersection.user.get_details_for_user(userId=id[0])
        followers = ic_user_object.followers

        await member.add_roles(*roles(member, followers, guild)[0],
                               reason="Updating follower roles.")
        await member.remove_roles(*roles(member, followers, guild)[1],
                                  reason="Updating follower roles.")

    else:
        await member.add_roles(*roles(member, None, guild)[0],
                               reason="Updating follower roles.")
        await member.remove_roles(*roles(member, None, guild)[1],
                                  reason="Updating follower roles.")
Esempio n. 10
0
    async def profile(self, ctx, *, user: discord.User = None):
        if not user: user = ctx.author
        await ctx.trigger_typing()

        async with asqlite.connect("database.sqlite") as conn:
            async with conn.cursor() as cursor:
                await cursor.execute(
                    "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                )

                await cursor.execute(
                    f'SELECT ic_id FROM accounts WHERE discord_id = {user.id}')
                id = await cursor.fetchone()

        if not id:
            embed = discord.Embed(
                description=
                f"<:error:905485648373370890> This user's account isn't linked!",
                color=discord.Color.from_rgb(237, 50, 31))

            await ctx.reply(embed=embed, mention_author=False)
            return

        account = intersection.user.get_details_for_user(userId=id[0])

        embed = discord.Embed(timestamp=ctx.message.created_at,
                              color=discord.Color.blue())

        embed.set_author(name=user, icon_url=user.avatar_url)
        embed.add_field(
            name="Intersection Controller",
            value=
            f"**Nickname:** {account.name}\n**ID:** {account.objectId}\n**Followers:** {account.followers}\n**Last login:** <t:{round(account.lastLogin / 1000.0)}:R>\n**Maps:** {account.maps}"
        )
        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 11
0
    async def search(self, ctx, *, name):
        users = intersection.user.search_for_users(result=10, query=name)

        if not len(users):
            embed = discord.Embed(
                description=
                f"<:error:905485648373370890> No users with such a name found!",
                color=discord.Color.from_rgb(237, 50, 31))

            await ctx.reply(embed=embed, mention_author=False)
            return

        embed = discord.Embed(title=f"Searching for `{name}`:",
                              timestamp=ctx.message.created_at,
                              color=discord.Color.blue())

        for user in users:
            linked = "Not linked"

            async with asqlite.connect("database.sqlite") as conn:
                async with conn.cursor() as cursor:
                    await cursor.execute(
                        f'SELECT discord_id FROM accounts WHERE ic_id = {user.objectId}'
                    )
                    account = await cursor.fetchone()

            if account:
                linked = self.client.get_user(account[0])

            embed.add_field(
                name=user.name,
                value=f"**ID:** {user.objectId} | **Discord:** {linked}",
                inline=False)

        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        await ctx.reply(embed=embed, mention_author=False)
Esempio n. 12
0
    async def verify(self, ctx: commands.Context, member: discord.User = None):
        if not member: member = ctx.author
        elif not ctx.author.guild_permissions.manage_messages and not member == ctx.author:
            raise commands.errors.MissingPermissions(["manage_roles"])

        if ctx.channel != member.dm_channel:

            with open("config/ValidGuilds.json", "r") as config:
                validated = ctx.guild.id in json.load(config)

            if not validated: raise GuildNotValidated

        await ctx.message.add_reaction('📬')

        guild = self.client.get_guild(guild_id)
        member = guild.get_member(member.id)

        logs = discord.utils.get(guild.channels, name="verification-logs")

        logged = discord.Embed(description=f"{member.mention} {member}", )

        chars = [
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e',
            'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h',
            'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E',
            'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H',
            'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'
        ]
        name = ""

        for i in range(6):
            name = name + random.choice(chars)

        embed = discord.Embed(
            title=":link: Account Verification",
            description=
            "I'm **Intersection Controller**, a Discord bot responsible for connecting people's Discord and IC accounts to allow them to view IC information on Discord. If you run into any problems please contact our administrator team in <#709891493737005157>. The **#numbers** thing under your profile is your ID (without the hashtag)\n\nIn order to see the rest of our server you will need to go through the verification process. To do so first send me your **Intersection Controller account ID** (It's visible on your profile page in the game, the one other people can view through comments/maps)\n\n:warning: **Do not share any of my messages unless you're sure what you're doing!**\nAnyone with this information will be able to link your account.",
            color=discord.Color.blue(),
            timestamp=datetime.now()  #ctx.message.created_at
        )

        embed.set_footer(text=member.name, icon_url=member.avatar_url)
        embed.set_image(
            url=
            "https://media.discordapp.net/attachments/879324217462632478/919997649439055882/Untitled.png"
        )

        await member.send(embed=embed)

        def check(message):
            return message.author == member and message.channel == member.dm_channel

        try:
            msg = await self.client.wait_for("message",
                                             timeout=5 * 60.0,
                                             check=check)

        except asyncio.TimeoutError:
            await member.send(
                "You didn't respond in time so I have stopped the process. To restart verification type `ic verify`"
            )
            logged.set_author(name="Verification Timed Out",
                              icon_url=member.avatar_url)
            logged.color = discord.Color.red()
            logged.timestamp = datetime.now()

            await logs.send(embed=logged)
            return

        try:
            id = int(msg.content)

        except:
            await member.send("Invalid ID format!")
            logged.set_author(name="Verification Failed - Invalid ID",
                              icon_url=member.avatar_url)
            logged.color = discord.Color.red()

            logged.add_field(name="Presumed ID", value=msg.content)
            logged.add_field(name="Code", value=name)
            logged.timestamp = datetime.now()

            await logs.send(embed=logged)
            return

        logged.set_author(name="Verification Started",
                          icon_url=member.avatar_url)
        logged.color = discord.Color.green()

        logged.add_field(name="Presumed ID", value=id)
        logged.add_field(name="Code", value=name)
        logged.timestamp = datetime.now()

        await logs.send(embed=logged)

        user = intersection.user.get_details_for_user(userId=id)

        if (not user.maps):
            embed = discord.Embed(
                title=f":link: Account Verification - {user.name}",
                description=
                "Now, in order to be verified, you'll need to **upload a new map** with the name I'll send you in my next message (just copy and paste it).\n\nRemember that you need to upload the map on the account you have previously posted the ID of or otherwise I will be unable to verify you! If you don't do so within 5 minutes I will automatically stop the process. Make sure not to delete the map until I verify you!\n\n:warning: **Do not share any of my messages unless you're sure what you're doing!**\nAnyone with this information will be able to link your account.",
                color=discord.Color.blue(),
                timestamp=datetime.now())

            embed.set_footer(text=member.name, icon_url=member.avatar_url)

            await member.send(embed=embed)
            await member.send(name)

            for i in range(15):
                await asyncio.sleep(20)
                try:
                    map = intersection.map.list_maps_by_user(userId=id,
                                                             result=1)[0]

                    if map.name == name: break
                except:
                    pass

            if (map.name == name):
                embed = discord.Embed(
                    title=f":link: Account Verification - {user.name}",
                    description=
                    "You have been successfully verified. Now, go visit our server and try out a bunch of awesome commands! You can type `ic profile @member` to view their IC user information or just run `ic profile` to view yours.\n\nIf you want to delete the map you can do it now.\n\nThe verification map name I sent you isn't going to be used again so you can freely post it wherever you want now.",
                    color=discord.Color.blue(),
                    timestamp=datetime.now())

                embed.set_footer(text=member.name, icon_url=member.avatar_url)

                player = discord.utils.get(guild.roles, name="IC player")

                async with asqlite.connect("database.sqlite") as conn:
                    async with conn.cursor() as cursor:

                        await cursor.execute(
                            "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                        )
                        await cursor.execute(
                            f"SELECT ic_id FROM accounts WHERE discord_id = {member.id}"
                        )
                        data = await cursor.fetchone()

                        if not data:
                            await cursor.execute(
                                f"INSERT INTO accounts(discord_id, ic_id) VALUES({member.id}, {id})"
                            )
                        else:
                            await cursor.execute(
                                f"UPDATE accounts SET ic_id = {id} WHERE discord_id = {member.id}"
                            )

                        await conn.commit()

                await member.add_roles(
                    player,
                    reason=f"an IC account was linked to the user. ID: {id}")

                await member.send(embed=embed)

                logged.set_author(name="Verification Succeeded - Map",
                                  icon_url=member.avatar_url)
                logged.color = discord.Color.green()
                logged.timestamp = datetime.now()

                await logs.send(embed=logged)

                async with asqlite.connect("database.sqlite") as conn:
                    async with conn.cursor() as cursor:
                        await cursor.execute(f'SELECT * FROM accounts')
                        amount_of_users = await cursor.fetchall()

                activity = discord.Activity(
                    name=f"{len(amount_of_users)} Linked Accounts",
                    type=discord.ActivityType.watching)
                await self.client.change_presence(status=discord.Status.online,
                                                  activity=activity)

            else:
                logged.set_author(name="Verification Failed - Map",
                                  icon_url=member.avatar_url)
                logged.color = discord.Color.red()
                logged.timestamp = datetime.now()

                await logs.send(embed=logged)
                await member.send(
                    f"Your latest map's name ({map.name}) doesn't match the verification name ({name})! I have stopped the verification process. Type `ic verify` if you wish to restart."
                )

        else:
            embed = discord.Embed(
                title=f":link: Account Verification - {user.name}",
                description=
                f"Now, in order to be verified, you'll need to **post a new comment** under your **latest map** ({intersection.map.list_maps_by_user(userId = id, result = 1)[0].name}) with just the content of my next message (just copy and paste it).\n\nRemember that you need to post the comment with the account you have previously posted the ID of or otherwise I will be unable to verify you! If you don't do so within 5 minutes I will automatically stop the process. Make sure not to delete the comment until I verify you!\n\n:warning: **Do not share any of my messages unless you're sure what you're doing!**\nAnyone with this information will be able to link your account.",
                color=discord.Color.blue(),
                timestamp=ctx.message.created_at)

            embed.set_footer(text=member.name, icon_url=member.avatar_url)

            await member.send(embed=embed)
            await member.send(name)

            for i in range(15):
                await asyncio.sleep(20)
                try:
                    comment = intersection.map.list_maps_by_user(
                        userId=id, result=1)[0].get_comments(limit=1)[0]

                    if comment.comment == name and comment.user == id: break
                except:
                    pass

            if (comment.comment == name and comment.user == id):
                embed = discord.Embed(
                    title=f":link: Account Verification - {user.name}",
                    description=
                    "You have been successfully verified. Now, go visit our server and try out a bunch of awesome commands! You can type `ic profile @member` to view someone's IC user information or just run `ic profile` with no arguments to view yours.\n\nIf you want to delete the comment you can do it now.\n\nThe verification code I sent you isn't going to be used again so you can freely post it wherever you want now.",
                    color=discord.Color.blue(),
                    timestamp=ctx.message.created_at)

                embed.set_footer(text=member.name, icon_url=member.avatar_url)

                player = discord.utils.get(guild.roles, name="IC player")

                async with asqlite.connect("database.sqlite") as conn:
                    async with conn.cursor() as cursor:

                        await cursor.execute(
                            "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                        )
                        await cursor.execute(
                            f"SELECT ic_id FROM accounts WHERE discord_id = {member.id}"
                        )
                        data = await cursor.fetchone()

                        if not data:
                            await cursor.execute(
                                f"INSERT INTO accounts(discord_id, ic_id) VALUES({member.id}, {id})"
                            )
                        else:
                            await cursor.execute(
                                f"UPDATE accounts SET ic_id = {id} WHERE discord_id = {member.id}"
                            )

                        await conn.commit()

                await member.add_roles(
                    player,
                    reason=f"an IC account was linked to the user. ID: {id}")

                await member.send(embed=embed)

                logged.set_author(name="Verification Succeeded- Comment",
                                  icon_url=member.avatar_url)
                logged.color = discord.Color.green()
                logged.timestamp = datetime.now()

                await logs.send(embed=logged)

                async with asqlite.connect("database.sqlite") as conn:
                    async with conn.cursor() as cursor:
                        await cursor.execute(f'SELECT * FROM accounts')
                        amount_of_users = await cursor.fetchall()

                activity = discord.Activity(
                    name=f"{len(amount_of_users)} Linked Accounts",
                    type=discord.ActivityType.watching)
                await self.client.change_presence(status=discord.Status.online,
                                                  activity=activity)

            else:
                logged.set_author(name="Verification Failed- Comment",
                                  icon_url=member.avatar_url)
                logged.color = discord.Color.red()
                logged.timestamp = datetime.now()

                await logs.send(embed=logged)
                await member.send(
                    f"The latest comment under **{intersection.map.list_maps_by_user(userId = id, result = 1)[0].name}** ({intersection.map.list_maps_by_user(userId = id, result = 1)[0].get_comments(limit=1)[0]}) doesn't match the verification code ({name})! I have stopped the verification process. Type `ic verify` if you wish to restart."
                )
Esempio n. 13
0
    async def map(self, ctx, index: int, where=None):
        dislike = self.client.get_emoji(759060520455766036)
        like = self.client.get_emoji(759059895424909380)
        index -= 1
        if index < 0:
            raise IndexError("Map index must be greater than or equal to 1!")
        discord_id, ic_id = None, None

        if not where: discord_id = ctx.author.id
        elif where.startswith("<"):
            discord_id = int(
                where.replace("<",
                              "").replace("@",
                                          "").replace("!",
                                                      "").replace(">", ""))
        elif len(where) > 10:
            discord_id = int(where)

        else:
            ic_id = int(where)

        if discord_id:
            async with asqlite.connect("database.sqlite") as conn:
                async with conn.cursor() as cursor:
                    await cursor.execute(
                        "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                    )

                    await cursor.execute(
                        f'SELECT ic_id FROM accounts WHERE discord_id = {discord_id}'
                    )
                    id = await cursor.fetchone()

            if not id:
                embed = discord.Embed(
                    description=
                    f"<:error:905485648373370890> This user's account isn't linked!",
                    color=discord.Color.from_rgb(237, 50, 31))

                await ctx.reply(embed=embed, mention_author=False)
                return

            account = intersection.user.get_details_for_user(userId=id[0])

            discordid = discord_id

        elif ic_id:
            async with asqlite.connect("database.sqlite") as conn:
                async with conn.cursor() as cursor:
                    await cursor.execute(
                        "CREATE TABLE IF NOT EXISTS accounts (discord_id INTEGER, ic_id INTEGER)"
                    )

                    await cursor.execute(
                        f'SELECT discord_id FROM accounts WHERE ic_id = {ic_id}'
                    )
                    account = await cursor.fetchone()

            if account:
                discordid = account[0]

            else:
                discordid = None

            account = intersection.user.get_details_for_user(userId=ic_id)

        maps = account.get_user_maps()
        map = maps[index]

        embed = discord.Embed(
            title=
            f"{map.name} {like} {map.votesUp} {dislike} {map.votesDown} :white_heart: {map.favorites}",
            description=map.desc,
            color=discord.Color.blue(),
            timestamp=ctx.message.created_at)
        embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)

        if map.gameModeGroup == 1: mode = "Simulation"
        elif map.gameModeGroup == 2: mode = "Traffic Controller"
        elif map.gameModeGroup == 3: mode = "Miscellaneous"

        embed.add_field(name="Game Mode", value=mode)
        embed.add_field(name="Author", value=map.authorName)
        embed.add_field(name="Discord",
                        value=str(self.client.get_user(discordid)))

        embed.add_field(name="Created",
                        value=datetime.datetime.fromtimestamp(
                            round(map.created / 1000.0)))
        embed.add_field(name="Updated",
                        value=datetime.datetime.fromtimestamp(
                            round(map.updated / 1000.0)))
        embed.add_field(name="Version", value=map.mapVersion)

        await ctx.reply(embed=embed, mention_author=False)