Пример #1
0
def get_slimeoid_count(user_id=None, server_id=None):
    if user_id != None and server_id != None:
        count = 0
        slimeoid_data = EwSlimeoid(id_user=user_id, id_server=server_id)
        secondary_user = str(user_id) + "freeze"
        name_list = []
        if slimeoid_data.name != "":
            count += 1

        items = bknd_item.inventory(id_user=user_id,
                                    id_server=server_id,
                                    item_type_filter=ewcfg.it_item)

        bottles = []
        for item in items:
            item_data = EwItem(id_item=item.get('id_item'))
            if item_data.item_props.get(
                    'context') == ewcfg.context_slimeoidbottle:
                count += 1

        try:
            conn_info = bknd_core.databaseConnect()
            conn = conn_info.get('conn')
            cursor = conn.cursor()

            sql = "SELECT {} FROM slimeoids WHERE {} = %s"
            cursor.execute(sql.format(ewcfg.col_name, ewcfg.col_id_user),
                           [secondary_user])

            count += cursor.rowcount
        finally:
            # Clean up the database handles.
            cursor.close()
            bknd_core.databaseClose(conn_info)
            return count
Пример #2
0
def int_is_zine(id_book=None, id_server=None, negative=False):
    direction = '>'
    if negative:
        direction = '<'
    book_list = []
    try:
        conn_info = bknd_core.databaseConnect()
        conn = conn_info.get('conn')
        cursor = conn.cursor()

        cursor.execute(
            ("SELECT b.id_book " + "FROM books AS b " +
             "WHERE b.id_server = %s AND b.book_state {} 0 ".format(direction)
             + "ORDER BY b.id_book"), (id_server, ))

        data = cursor.fetchall()
        if data != None:
            for row in data:
                book_list.append(row[0])
    finally:
        # Clean up the database handles.
        cursor.close()
        bknd_core.databaseClose(conn_info)
    if id_book in book_list:
        return True
    else:
        return False
Пример #3
0
async def toss_squatters(user_id=None, server_id=None, keepKeys=False):
    player_info = EwPlayer(id_user=user_id)
    apt_info = EwApartment(id_user=user_id, id_server=server_id)

    client = ewutils.get_client()
    server = client.get_guild(server_id)

    member_data = server.get_member(player_info.id_user)

    if player_info.id_server != None and member_data != None:
        try:
            conn_info = bknd_core.databaseConnect()
            conn = conn_info.get('conn')
            cursor = conn.cursor()
            client = ewutils.get_client()

            # get all players visiting an evicted apartment and kick them out
            cursor.execute(
                "SELECT {} FROM users WHERE {} = %s AND {} = %s".format(
                    ewcfg.col_id_user,
                    ewcfg.col_visiting,
                    ewcfg.col_id_server,
                ), (
                    member_data.id,
                    server_id,
                ))

            squatters = cursor.fetchall()
            key_1 = EwItem(id_item=apt_info.key_1).id_owner
            key_2 = EwItem(id_item=apt_info.key_2).id_owner
            for squatter in squatters:
                sqt_data = EwUser(id_user=squatter[0],
                                  id_server=player_info.id_server)
                if keepKeys and (sqt_data.id_user == key_1
                                 or sqt_data.id_user == key_2):
                    pass
                else:
                    server = ewcfg.server_list[sqt_data.id_server]
                    member_object = server.get_member(squatter[0])
                    sqt_data.poi = sqt_data.poi[3:] if sqt_data.poi[
                        3:] in poi_static.id_to_poi.keys() else sqt_data.poi
                    sqt_data.visiting = ewcfg.location_id_empty
                    sqt_data.persist()
                    await ewrolemgr.updateRoles(client=client,
                                                member=member_object)
        finally:
            # Clean up the database handles.
            cursor.close()
            bknd_core.databaseClose(conn_info)
Пример #4
0
async def rent_time(id_server=None):
    try:
        conn_info = bknd_core.databaseConnect()
        conn = conn_info.get('conn')
        cursor = conn.cursor()
        client = ewutils.get_client()
        if id_server != None:
            # get all players with apartments. If a player is evicted, thir rent is 0, so this will not affect any bystanders.
            cursor.execute(
                "SELECT apartment.rent, users.id_user FROM users INNER JOIN apartment ON users.id_user=apartment.id_user WHERE users.id_server = %s AND apartment.id_server = %s AND apartment.rent > 0"
                .format(), (
                    id_server,
                    id_server,
                ))

            landowners = cursor.fetchall()

            for landowner in landowners:
                owner_id_user = int(landowner[1])
                owner_rent_price = landowner[0]

                user_data = EwUser(id_user=owner_id_user, id_server=id_server)
                user_poi = poi_static.id_to_poi.get(user_data.poi)
                poi = poi_static.id_to_poi.get(user_data.apt_zone)

                if owner_rent_price > user_data.slimecoin:

                    if (user_poi.is_apartment
                            and user_data.visiting == ewcfg.location_id_empty):
                        user_data.poi = user_data.apt_zone  # toss out player
                        user_data.persist()
                        server = ewcfg.server_list[user_data.id_server]
                        member_object = server.get_member(owner_id_user)

                        await ewrolemgr.updateRoles(client=client,
                                                    member=member_object)
                        player = EwPlayer(id_user=owner_id_user)
                        response = "{} just got evicted. Point and laugh, everyone.".format(
                            player.display_name)
                        await fe_utils.send_message(
                            client, fe_utils.get_channel(server, poi.channel),
                            response)

                    user_data = EwUser(id_user=owner_id_user,
                                       id_server=id_server)
                    user_apt = EwApartment(id_user=owner_id_user,
                                           id_server=id_server)
                    poi = poi_static.id_to_poi.get(user_data.apt_zone)

                    toss_items(id_user=str(user_data.id_user) + 'closet',
                               id_server=user_data.id_server,
                               poi=poi)
                    toss_items(id_user=str(user_data.id_user) + 'fridge',
                               id_server=user_data.id_server,
                               poi=poi)
                    toss_items(id_user=str(user_data.id_user) + 'decorate',
                               id_server=user_data.id_server,
                               poi=poi)

                    user_data.apt_zone = ewcfg.location_id_empty
                    user_data.persist()
                    user_apt.rent = 0
                    user_apt.poi = " "
                    user_apt.persist()

                    await toss_squatters(user_id=user_data.id_user,
                                         server_id=id_server)

                else:
                    user_data.change_slimecoin(
                        n=-owner_rent_price,
                        coinsource=ewcfg.coinsource_spending)
                    user_data.persist()
    finally:
        cursor.close()
        bknd_core.databaseClose(conn_info)
Пример #5
0
async def writhe(cmd):
    resp = await cmd_utils.start(cmd=cmd)
    response = ""
    user_data = EwUser(member=cmd.message.author)

    if user_data.life_state != ewcfg.life_state_grandfoe:
        response = "Only the NEGASLIME {} can do that.".format(
            ewcfg.emote_negaslime)
        await fe_utils.send_message(
            cmd.client, cmd.message.channel,
            fe_utils.formatMessage(cmd.message.author, response))
    else:
        # play animation
        he = ewcfg.emote_he
        s_ = ewcfg.emote_s_
        ve = ewcfg.emote_ve
        vt = ewcfg.emote_vt
        v_ = ewcfg.emote_v_
        h_ = ewcfg.emote_h_
        va = ewcfg.emote_va
        ht = ewcfg.emote_ht
        hs = ewcfg.emote_hs
        blank = ewcfg.emote_blank

        writhing1 = he
        writhing2 = s_ + he + "\n" + ve
        writhing3 = s_ + h_ + he + "\n" + vt + he
        writhing4 = s_ + h_ + ht + "\n" + vt + he + ve
        writhing5 = s_ + h_ + ht + "\n" + va + he + vt + he + "\n" + ve
        writhing6 = s_ + h_ + ht + "\n" + va + ht + va + ht + "\n" + v_ + ve + ve + ve + "\n" + ve
        writhing7 = s_ + h_ + ht + "\n" + va + ht + va + hs + he + "\n" + v_ + ve + v_ + vt + he + "\n" + ve + blank + ve
        writhing8 = s_ + h_ + ht + "\n" + va + ht + va + hs + he + "\n" + v_ + ve + v_ + vt + h_ + he + "\n" + vt + he + vt + he
        writhing9 = s_ + h_ + ht + "\n" + va + ht + va + hs + h_ + he + "\n" + v_ + ve + v_ + vt + h_ + ht + "\n" + vt + ht + vt + ht + blank + ve + "\n" + blank + ve + blank + ve
        writhing10 = s_ + h_ + ht + "\n" + va + ht + va + hs + h_ + he + "\n" + v_ + ve + v_ + vt + h_ + ht + "\n" + vt + ht + vt + ht + blank + vt + he + "\n" + blank + ve + blank + vt + he

        writhings = [
            writhing1, writhing2, writhing3, writhing4, writhing5, writhing6,
            writhing7, writhing8, writhing9, writhing10
        ]

        for writhing in writhings:
            cur_time = time.time()
            await fe_utils.edit_message(cmd.client, resp, writhing)
            elapsed = time.time() - cur_time
            await asyncio.sleep(2.0 - elapsed)

        id_server = cmd.guild.id
        targets = []

        # search for players in the negaslime's location in database and put them in a list
        if id_server != None:
            try:
                conn_info = bknd_core.databaseConnect()
                conn = conn_info.get('conn')
                cursor = conn.cursor()

                cursor.execute(
                    "SELECT id_user FROM users WHERE id_server = %s AND poi = '{}' AND life_state IN (1, 2);"
                    .format(user_data.poi), (id_server, ))

                # convert pulled IDs into member objects
                target_ids = cursor.fetchall()
                for target_id in target_ids:
                    target = cmd.guild.get_member(target_id[0])
                    targets.append(target)

                conn.commit()
            finally:
                # Clean up the database handles.
                cursor.close()
                bknd_core.databaseClose(conn_info)

        victim_list = []

        # kill everyone in the negaslime's poi and remember their names
        for target in targets:
            if target != None:
                user_data_target = EwUser(member=target)

                user_data_target.id_killer = cmd.message.author.id
                user_data_target.die(cause=ewcfg.cause_grandfoe)
                user_data_target.persist()
                await ewrolemgr.updateRoles(client=cmd.client, member=target)
                sewerchannel = fe_utils.get_channel(cmd.guild,
                                                    ewcfg.channel_sewers)
                await fe_utils.send_message(
                    cmd.client, sewerchannel,
                    "{} ".format(ewcfg.emote_slimeskull) +
                    fe_utils.formatMessage(
                        target, "You have been crushed by tendrils. {}".format(
                            ewcfg.emote_slimeskull)))

                victim_list.append(target)

        # display result of the writhing
        if len(victim_list) > 0:
            victims_string = ewutils.userListToNameString(victim_list)
            response = "Your tendrils have successfully killed {}.".format(
                victims_string)
        else:
            response = "Your tendrils didn't kill anyone :("

        await fe_utils.send_message(
            cmd.client, cmd.message.channel,
            fe_utils.formatMessage(cmd.message.author, response))
Пример #6
0
async def rate_zine(cmd):
    if len(cmd.tokens) < 2:
        response = "What zine do you want to rate?"

    else:
        if len(cmd.tokens) >= 3:
            rating = ewutils.getIntToken(cmd.tokens)
            book_title = ewutils.flattenTokenListToString(cmd.tokens[1:len(cmd.tokens) - 1])

            if rating == None:
                response = "How many f***s do you want to give the zine? (1-5)"

            elif rating not in range(1, 6):
                response = "Easy now, keep your f***s between 1 and 5."

            else:
                book_sought = bknd_item.find_item(item_search=book_title, id_user=cmd.message.author.id, id_server=cmd.guild.id if cmd.guild is not None else None)

                if book_sought:
                    book_item = EwItem(id_item=book_sought.get('id_item'))
                    id_book = book_item.item_props.get("id_book")
                    book = EwBook(id_book=id_book)
                    sale = EwBookSale(id_book=id_book, member=cmd.message.author)

                    if sale.bought == 1:
                        if sale.rating == 0:
                            book.rates += 1
                        sale.rating = rating
                        sale.persist()
                        try:
                            conn_info = bknd_core.databaseConnect()
                            conn = conn_info.get('conn')
                            cursor = conn.cursor()

                            cursor.execute((
                                "SELECT {} FROM book_sales WHERE {} = %s AND {} = %s AND {} != 0".format(
                                    ewcfg.col_rating,
                                    ewcfg.col_id_server,
                                    ewcfg.col_id_user,
                                    ewcfg.col_rating,
                                )
                            ), (
                                cmd.guild.id,
                                cmd.message.author.id,
                            ))

                            data = cursor.fetchall()
                            ratings = []
                            total_rating = 0

                            if data != None:
                                for row in data:
                                    ratings.append(row)
                                    total_rating += row[0]

                        finally:
                            # Clean up the database handles.
                            cursor.close()
                            bknd_core.databaseClose(conn_info)

                        book.rating = str(total_rating / len(ratings))[:4]

                        # zine is excluded from normal browsing
                        if book.book_state == 1:
                            if book.rates >= 10 and float(book.rating) <= 2.0:
                                book.book_state = 2
                            elif book.rates >= 4 and float(book.rating) <= 1.5:
                                book.book_state = 2

                        # zine is included back into normal browsing
                        elif book.book_state == 2:
                            if float(book.rating) > 2.0 and book.rates > 10:
                                book.book_state = 1
                            elif float(book.rating) > 1.5 and book.rates > 5:
                                book.book_state = 1

                        book.persist()

                        response = "{}, you carve a {} into the back of the zine in order to indicate how many f***s you give about it.".format(ewcfg.rating_flavor[rating], rating)

                    else:
                        response = "You've never bought this book."

                else:
                    response = "You don't have that zine on you."
        else:
            response = "How many f***s do you want to give the zine? (1-5)"

    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #7
0
async def browse_zines(cmd):
    if len(cmd.tokens) > 1:
        sort_token = cmd.tokens[1].replace("_", "")

    else:
        sort_token = "null"

    user_data = EwUser(member=cmd.message.author)
    poi = poi_static.id_to_poi.get(user_data.poi)

    if poi.is_apartment:
        return await apt_cmds.browse(cmd)

    if not poi.write_manuscript:
        response = "You can't browse for zines here! Try going to the cafe. If you're looking for educational zines, try the colleges. If you can't read, then you might want to try the comic shop."

        await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    else:
        if not sort_token.isdigit():
            book_list = []
            resp_cont = EwResponseContainer(id_server=cmd.guild.id)
            query_suffix = ""
            query_sort = "id_book"
            more_selects = ""
            quality = "= 1"

            if user_data.poi in ["nlac-university", "neo-milwaukee-state"]:
                query_suffix = "AND b.genre = 1 "

            elif user_data.poi in ["glocksbury-comics"]:
                query_suffix = "AND b.genre = 2 "

            elif user_data.poi in [ewcfg.poi_id_clinicofslimoplasty]:
                query_suffix = "AND b.genre = 10 "

            if sort_token in ("bookname", "name", "title", "booktitle", "zinename", "zinetitle"):
                query_sort = "title"

            elif sort_token in ("author", "authorname", "artist", "artistname", "illustrator"):
                query_sort = "author"

            elif sort_token in ("date", "datepublished", "day", "time", "published", "publish", "publishdate"):
                query_sort = "date_published"
                more_selects = ", b.date_published"

            elif sort_token in ewcfg.book_genres:
                genre = ""

                for i in [i for i, x in enumerate(ewcfg.book_genres) if x == sort_token]:
                    genre = i

                query_suffix = "AND b.genre = {} ".format(genre)

            elif sort_token in ('reverse', 'inverse', 'descend', 'desc', 'descending', 'backwards'):
                query_sort += " DESC"

            elif sort_token in ('length', 'len', 'pages', 'long', 'longest'):
                query_sort = "length DESC"
                more_selects = ", b.length"

            elif sort_token in ('sales', 'sale', 'sell', 'bestsellers', 'topsellers', 'bestselling'):
                query_sort = "sales DESC"
                more_selects = ", b.sales"

            elif sort_token in ('rating', 'quality', 'ratings', 'rate', 'f***s', 'rate', 'f**k', 'toprated', 'best', 'highestrated'):
                query_sort = "rating DESC, rates DESC"
                more_selects = ", b.rating, b.rates"

            elif sort_token in ('bad', 'terrible', 'shit', 'shitty', 'worst', 'worstrated', 'bottom'):
                quality = "= 2"

            elif sort_token in ('all', 'every'):
                quality = "> 0"
                query_suffix = ""
                query_sort = "id_book"
                more_selects = ""

            if len(cmd.tokens) > 2:
                if cmd.tokens[2] in ('reverse', 'inverse', 'descend', 'desc', 'descending', 'backwards'):
                    if not query_sort.endswith(" DESC"):
                        query_sort += " DESC"

                    else:
                        query_sort = query_sort[:len(query_sort) - 5] + " ASC"
            try:
                conn_info = bknd_core.databaseConnect()
                conn = conn_info.get('conn')
                cursor = conn.cursor()

                cursor.execute((
                        "SELECT b.id_book, b.title, b.author{} ".format(more_selects) +
                        "FROM books AS b " +
                        "WHERE b.id_server = %s AND b.book_state {} {}".format(quality, query_suffix) +
                        "ORDER BY b.{}".format(query_sort)
                ), (
                    cmd.guild.id,
                ))

                data = cursor.fetchall()
                if data != None:
                    for row in data:
                        more_info = ""

                        if query_sort.startswith("date_published"):
                            more_info = " (Published on day {})".format(row[3])

                        elif query_sort.startswith("length"):
                            more_info = " (Length: {} characters)".format(row[3])

                        elif query_sort.startswith("sales"):
                            more_info = " (Sales: {} copies)".format(row[3])

                        elif query_sort.startswith("rating"):
                            if row[3] == '0' and row[4] == 0:
                                more_info = " (Rating: No f***s given yet)"

                            else:
                                more_info = " (Rating: {} f***s across {} ratings)".format(row[3], row[4])

                        book_list.append("\n{}: {} by {}{}".format(
                            row[0],
                            row[1].replace("`", "").replace("\n", ""),
                            row[2].replace("`", "").replace("\n", ""),
                            more_info,
                        ))

            finally:
                # Clean up the database handles.
                cursor.close()
                bknd_core.databaseClose(conn_info)

            if len(book_list) != 0:
                resp_num = 0
                resp_count = 0
                resp_list = []

                # weird looking loop (i assure you it works tho)
                for book in book_list:
                    resp_count += 1

                    if len(resp_list) != resp_num + 1:
                        resp_list.append("")
                    resp_list[resp_num] += book

                    if resp_count == 10:
                        resp_count = 0
                        resp_num += 1

                for resp_block in resp_list:
                    resp_cont.add_channel_response(cmd.message.channel.name, resp_block)

                # Send the response to the player.
                resp_cont.format_channel_response(cmd.message.channel.name, cmd.message.author)

                await resp_cont.post(channel=cmd.message.channel)
            else:
                response = "There aren't any zines in circulation at the moment."

                await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
        else:
            id_book = int(sort_token)

            if int_is_zine(id_book, cmd.guild.id):
                book = EwBook(id_book=id_book)
                title = book.title
                author = book.author
                genre = ewcfg.book_genres[book.genre]

                response = "\n{} is a {} zine by {}.\n".format(title, genre, author)

                cover = book.book_pages.get(0, "")
                pages = book.pages
                length = book.length
                date = book.date_published

                response += "It is {} pages and {:,} characters long and was published on Day {}. ".format(pages, length, date)

                sales = book.sales
                rating = book.rating
                rates = book.rates

                if sales == 0:
                    response += "It has not yet been bought by anyone.\n"

                else:
                    response += "It has sold {:,} copies.\n".format(sales)

                if rates == 0:
                    response += "Nobody has given it any f***s.\n"

                else:
                    response += "It has received {} ratings with an average of {} f***s given out of 5.\n".format(rates, rating)

                if cover != "":
                    if genre == "p**n":
                        response += "The cover looks like this: ||{}||".format(cover)
                    else:
                        response += "The cover looks like this: {}".format(cover)

            else:
                response = "That's not a valid zine ID."

            await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))