Example #1
0
    async def delete_item(self, ctx, item_id):
        """
        Delete an item from the shop
        :param item_id: id of the item to delete
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            item_msg = await shop_channel.fetch_message(item_id)

            await item_msg.delete()

            delete_shop_item(item_id, shop_id, self.cursor, self.cnx)
            await ctx.send("Successfully deleted item " + item_results[2] +
                           "!")
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return
Example #2
0
    async def shop(self, ctx, status):
        """
        Set the status of the shop to open / close
        :param status: the status of the shop (open / close)
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        status = status.lower()

        if not (status == 'open'
                or status == 'close'):  # check for valid response
            await ctx.send(
                "Error: Must provide a valid status for your shop! (eg. open / close)"
            )
            return

        status = 0 if status == 'close' else 1
        shop_id = get_user_shop(user.id, self.cursor)

        cur_status = get_shop_status(shop_id, self.cursor)

        if status == cur_status:
            await ctx.send("Error: The shop is already " +
                           ('open' if cur_status == 1 else 'closed') +
                           " for business!")
            return

        guild = ctx.guild
        shop_channel = self.bot.get_channel(shop_id)

        if status == 1:  # if the user is opening their shop
            await shop_channel.set_permissions(guild.default_role,
                                               read_messages=True)
            await ctx.send("You have successfully opened up shop!")
        else:  # if the user is closing their shop
            await shop_channel.set_permissions(guild.default_role,
                                               read_messages=False)
            await ctx.send("You have successfully closed down shop!")

        set_shop_status(shop_id, status, self.cursor, self.cnx)

        # Begin Shop Sign Update

        shop_results = get_shop(shop_id, self.cursor)

        new_sign = await shop_channel.send(
            create_shop_sign(self.bot.get_user(int(shop_results[1])),
                             shop_results, self.cursor))

        old_msg = await shop_channel.fetch_message(
            get_shop_sign(shop_id, self.cursor))

        set_shop_sign(shop_id, new_sign.id, self.cursor, self.cnx)
        await old_msg.delete()
Example #3
0
    async def set_item_desc(self, ctx, item_id, item_desc):
        """
        Sets an items description
        :param item_id: id for the item to update
        :param item_desc: description of the item to update
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        if not isinstance(item_desc, str):
            await ctx.send(
                "Error: The item description must have a valid description text!"
            )
            return

        if len(item_desc) >= 512:
            await ctx.send(
                "Error: The item description must be less than 512 characters long!"
            )
            return

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        item_msg = await shop_channel.fetch_message(item_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_results[2], item_desc,
                                      item_results[4], item_results[5],
                                      item_results[6], item_results[7])

            set_shop_item_desc(item_id, shop_id, item_desc, self.cursor,
                               self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        await ctx.send("Successfully updated the item description for " +
                       item_results[2] + " to " + item_desc + "!")
Example #4
0
    async def set_item_quantity(self, ctx, item_id, item_qty):
        """
        Sets an items available quantity
        :param item_id: id for the item to update
        :param item_qty: available quantity of item to update
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        try:
            item_qty = int(item_qty)
        except ValueError:
            await ctx.send(
                "Error: The item quantity must have a valid amount! (eg. 1)")
            return

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        item_msg = await shop_channel.fetch_message(item_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_results[2], item_results[3],
                                      item_results[4], item_qty,
                                      item_results[6], item_results[7])

            set_shop_item_qty(item_id, shop_id, item_qty, self.cursor,
                              self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        formatted_qty = "INF" if item_qty < 0 else str(item_qty)

        await ctx.send("Successfully updated the item quantity for " +
                       item_results[2] + " to " + formatted_qty + "!")
Example #5
0
    async def set_item_price(self, ctx, item_id, item_price):
        """
        Sets an items price
        :param item_id: id for the item to update
        :param item_price: price of the item to update
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        try:
            item_price = float(item_price)
        except ValueError:
            await ctx.send(
                "Error: The item price must have a valid price! (eg. 00.00)")
            return

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        item_msg = await shop_channel.fetch_message(item_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_results[2], item_results[3],
                                      item_price, item_results[5],
                                      item_results[6], item_results[7])

            set_shop_item_price(item_id, shop_id, item_price, self.cursor,
                                self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        formatted_price = "${:,.2f}".format(item_price)

        await ctx.send("Successfully updated the item price for " +
                       item_results[2] + " to " + formatted_price + "!")
Example #6
0
    async def set_item_image(self, ctx, item_id, item_image):
        """
        Sets an items image
        :param item_id: id for the item to update
        :param item_image: image url to update
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        if len(item_image) >= 128:
            await ctx.send(
                "Error: The item image must be less than 128 characters long!")
            return

        if item_image.lower() == 'none':
            item_image = item_image.lower()

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        item_msg = await shop_channel.fetch_message(item_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_results[2], item_results[3],
                                      item_results[4], item_results[5],
                                      item_results[6], item_image)

            set_shop_item_image(item_id, shop_id, item_image, self.cursor,
                                self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        await ctx.send("Successfully updated the item image for " +
                       item_results[2] + " to " + item_image + "!")
Example #7
0
    async def set_item_type(self, ctx, item_id, item_type):
        """
        Sets an items type
        :param item_id: id for the item to update
        :param item_type: type of item to update (digital / service)
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        item_type = item_type.upper()

        if not (item_type == 'DIGITAL' or item_type == 'SERVICE'):
            await ctx.send(
                "Error: The item type must have a valid type! (eg. digital / service)"
            )
            return

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        item_msg = await shop_channel.fetch_message(item_id)

        try:
            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_results[2], item_results[3],
                                      item_results[4], item_results[5],
                                      item_type, item_results[7])

            set_shop_item_type(item_id, shop_id, item_type, self.cursor,
                               self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        await ctx.send("Successfully updated the item type for " +
                       item_results[2] + " to " + item_type + "!")
Example #8
0
    async def set_item_name(self, ctx, item_id, item_name):
        """
        Sets an items name
        :param item_id: id for the item to update
        :param item_name: name of the item to update
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        if not isinstance(item_name, str):
            await ctx.send(
                "Error: The item name must have a valid name! (Use quotes to include spaces)"
            )
            return

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        try:
            item_msg = await shop_channel.fetch_message(item_id)

            item_results = get_shop_item(item_id, shop_id, self.cursor)
            embed = create_item_embed(user, item_name, item_results[3],
                                      item_results[4], item_results[5],
                                      item_results[6], item_results[7])

            set_shop_item_name(item_id, shop_id, item_name, self.cursor,
                               self.cnx)
            await item_msg.edit(embed=embed)
        except ItemNotFoundError:
            await ctx.send(
                "Error: The item id was not found! Be sure to copy the correct id of your shop item message."
            )
            return

        await ctx.send("Successfully updated the item name from " +
                       item_results[2] + " to " + item_name + "!")
Example #9
0
    async def add_item(self, ctx, item_name, item_price, item_qty, item_type,
                       item_image, item_desc):
        """
        Add an item to the shop
        :param item_name: name of the item
        :param item_price: price of the item (0.00)
        :param item_qty: available quantity for the item (negative value for INF)
        :param item_type: type of the item (digital / service)
        :param item_image: image url of the item (less than 128 characters)
        :param item_desc: description of the item (less than 256 characters)
        """
        user = ctx.author

        try:
            in_control_panel(user.id, ctx.message.channel.id, self.cursor)
        except CommandNotControlPanelError:
            return  # do nothing in current channel

        if not isinstance(item_name, str):
            await ctx.send(
                "Error: The item name must have a valid name! (Use quotes to include spaces)"
            )
            return

        try:
            item_price = float(item_price)
        except ValueError:
            await ctx.send(
                "Error: The item price must have a valid price! (eg. 00.00)")
            return

        try:
            item_qty = int(item_qty)
        except ValueError:
            await ctx.send(
                "Error: The item quantity must have a valid amount! (eg. 1)")
            return

        if not isinstance(item_type, str):
            await ctx.send(
                "Error: The item type must have a valid type! (eg. digital / service)"
            )
            return

        item_type = item_type.upper()

        if not (item_type == 'DIGITAL' or item_type == 'SERVICE'):
            await ctx.send(
                "Error: The item type must have a valid type! (eg. digital / service)"
            )
            return

        if not isinstance(item_desc, str):
            await ctx.send(
                "Error: The item description must have a valid description text!"
            )
            return

        if len(item_desc) >= 512:
            await ctx.send(
                "Error: The item description must be less than 512 characters long!"
            )
            return

        if len(item_image) >= 128:
            await ctx.send(
                "Error: The item image must be less than 128 characters long!")
            return

        if item_image.lower() == 'none':
            item_image = item_image.lower()

        shop_id = get_user_shop(user.id, self.cursor)
        shop_channel = self.bot.get_channel(shop_id)

        embed = create_item_embed(user, item_name, item_desc, item_price,
                                  item_qty, item_type, item_image)
        msg = await shop_channel.send(embed=embed)
        add_shop_item(msg.id, shop_id, item_name, item_desc, item_price,
                      item_qty, item_type, item_image, self.cursor, self.cnx)

        await ctx.send("You have successfully added a new item to your shop!")