# Path: twistedbot/plugins/base.py
# class PluginChatBase(PluginBase):
# 
#     def send_chat_message(self, msg):
#         self.world.chat.send_chat_message(msg)
# 
#     @abc.abstractproperty
#     def command_verb(self):
#         pass
# 
#     @property
#     def aliases(self):
#         return []
# 
#     @abc.abstractproperty
#     def help(self):
#         pass
# 
#     @abc.abstractmethod
#     def command(self, sender, command, args):
#         pass
# 
# Path: twistedbot/behavior_tree.py
# class InventorySelectActive(BTAction):
#     def __init__(self, itemstack=None, **kwargs):
#         super(InventorySelectActive, self).__init__(**kwargs)
#         self.itemstack = itemstack
#         self.name = "hold item %s" % self.itemstack
# 
#     @classmethod
#     def parse_parameters(cls, itemname):
#         try:
#             istack = items.item_db.item_by_name(itemname)
#         except KeyError:
#             istack = None
#         return istack
# 
#     def on_start(self):
#         self.inventory_man = InventoryManipulation(inventory=self.blackboard.inventory_player, blackboard=self.blackboard)
# 
#     @inlineCallbacks
#     def action(self):
#         if not self.inventory_man.has_item(self.itemstack):
#             self.status = Status.failure
#             self.blackboard.send_chat_message("don't have %s in my inventory" % self.itemstack.name)
#             return
#         if self.inventory_man.item_active(self.itemstack):
#             self.status = Status.success
#             return
#         active_slot = self.inventory_man.item_at_active_slot(self.itemstack)
#         if active_slot is not None:
#             self.inventory_man.set_active_slot(active_slot)
#             self.status = Status.success
#             return
#         slot_position = self.inventory_man.slot_at_item(self.itemstack)
#         confirmed = yield self.inventory_man.click_slot(slot_position)
#         if not confirmed:
#             log.msg("bad news, inventory transaction not confirmed by the server")
#             self.status = Status.failure
#             return
#         active_slot = self.inventory_man.choose_active_slot()
#         confirmed = yield self.inventory_man.click_active_slot(active_slot)
#         if not confirmed:
#             log.msg("bad news, inventory transaction not confirmed by the server")
#             self.status = Status.failure
#             return
#         if not self.inventory_man.is_cursor_empty:
#             confirmed = yield self.inventory_man.click_slot(slot_position)
#             if not confirmed:
#                 log.msg("bad news, inventory transaction not confirmed by the server")
#                 self.status = Status.failure
#                 return
#         self.inventory_man.set_active_slot(active_slot)
#         self.status = Status.success
# 
#     def on_end(self):
#         """ make sure the item is on active slot and close the inventory """
#         if self.status == Status.success:
#             self.blackboard.send_chat_message("holding %s" % self.itemstack.name)
#         self.inventory_man.close()


from twistedbot.plugins.base import PluginChatBase
from twistedbot.behavior_tree import InventorySelectActive



class Debug(PluginChatBase):
    @property
    def command_verb(self):
        return "debug"

    @property
    def help(self):
        return "help for debug"

    def command(self, sender, command, args):
        if subject:
            what = subject[0]
            if what == "inventoryselect":
                item_name = " ".join(subject[1:])
                if not item_name:
                    self.send_chat_message("specify item")
                    return
                itemstack = InventorySelectActive.parse_parameters(item_name)
                if itemstack is not None:

# Path: twistedbot/plugins/base.py
# class PluginChatBase(PluginBase):
# 
#     def send_chat_message(self, msg):
#         self.world.chat.send_chat_message(msg)
# 
#     @abc.abstractproperty
#     def command_verb(self):
#         pass
# 
#     @property
#     def aliases(self):
#         return []
# 
#     @abc.abstractproperty
#     def help(self):
#         pass
# 
#     @abc.abstractmethod
#     def command(self, sender, command, args):
#         pass
# 
# Path: twistedbot/behavior_tree.py
# class InventorySelectActive(BTAction):
#     def __init__(self, itemstack=None, **kwargs):
#         super(InventorySelectActive, self).__init__(**kwargs)
#         self.itemstack = itemstack
#         self.name = "hold item %s" % self.itemstack
# 
#     @classmethod
#     def parse_parameters(cls, itemname):
#         try:
#             istack = items.item_db.item_by_name(itemname)
#         except KeyError:
#             istack = None
#         return istack
# 
#     def on_start(self):
#         self.inventory_man = InventoryManipulation(inventory=self.blackboard.inventory_player, blackboard=self.blackboard)
# 
#     @inlineCallbacks
#     def action(self):
#         if not self.inventory_man.has_item(self.itemstack):
#             self.status = Status.failure
#             self.blackboard.send_chat_message("don't have %s in my inventory" % self.itemstack.name)
#             return
#         if self.inventory_man.item_active(self.itemstack):
#             self.status = Status.success
#             return
#         active_slot = self.inventory_man.item_at_active_slot(self.itemstack)
#         if active_slot is not None:
#             self.inventory_man.set_active_slot(active_slot)
#             self.status = Status.success
#             return
#         slot_position = self.inventory_man.slot_at_item(self.itemstack)
#         confirmed = yield self.inventory_man.click_slot(slot_position)
#         if not confirmed:
#             log.msg("bad news, inventory transaction not confirmed by the server")
#             self.status = Status.failure
#             return
#         active_slot = self.inventory_man.choose_active_slot()
#         confirmed = yield self.inventory_man.click_active_slot(active_slot)
#         if not confirmed:
#             log.msg("bad news, inventory transaction not confirmed by the server")
#             self.status = Status.failure
#             return
#         if not self.inventory_man.is_cursor_empty:
#             confirmed = yield self.inventory_man.click_slot(slot_position)
#             if not confirmed:
#                 log.msg("bad news, inventory transaction not confirmed by the server")
#                 self.status = Status.failure
#                 return
#         self.inventory_man.set_active_slot(active_slot)
#         self.status = Status.success
# 
#     def on_end(self):
#         """ make sure the item is on active slot and close the inventory """
#         if self.status == Status.success:
#             self.blackboard.send_chat_message("holding %s" % self.itemstack.name)
#         self.inventory_man.close()


# Path: twistedbot/plugins/core/chat_debug.py
from twistedbot.plugins.base import PluginChatBase
from twistedbot.behavior_tree import InventorySelectActive




class Debug(PluginChatBase):
    @property
    def command_verb(self):
        return "debug"

    @property
    def help(self):
        return "help for debug"

    def command(self, sender, command, args):
        if subject:
            what = subject[0]
            if what == "inventoryselect":
                item_name = " ".join(subject[1:])
                if not item_name:
                    self.send_chat_message("specify item")
                    return
                itemstack = InventorySelectActive.parse_parameters(item_name)
                if itemstack is not None:

                    self.world.bot.behavior_tree.new_command(InventorySelectActive, itemstack=itemstack)