Ejemplo n.º 1
0
 def get_member(self, **kwargs):
     logging.info("getting member for kwargs: %s" % kwargs)
     message_object = get_key_from_kwargs('message_object',
                                          kwargs)  # type: discord.Message
     user_id = get_key_from_kwargs(
         'user', kwargs,
         get_key_from_kwargs('message_object', kwargs).author.id)
     user_id = re.sub(r'<@(\d+)\>', '\\1', user_id)
     member = discord.utils.get(message_object.server.members, id=user_id)
     logging.info("got member: %s" % member)
     return member
Ejemplo n.º 2
0
 async def deafen(self, *args, **kwargs):
     message_object = get_key_from_kwargs('message_object',
                                          kwargs)  # type: discord.Message
     member = self.get_member(**kwargs)
     await self.api.server_voice_state(member, deafen=True)
     return "%s: told me to deafen %s" % (message_object.author.name,
                                          member.name)
Ejemplo n.º 3
0
    async def afk(self, *args, **kwargs):
        logging.info("afk somebody they say: %s, %s" % (args, kwargs))

        message_object = get_key_from_kwargs('message_object',
                                             kwargs)  # type: discord.Message

        try:
            # try get user is passed, else default back to the author
            user_id = get_key_from_kwargs(
                'user', kwargs,
                get_key_from_kwargs('message_object', kwargs).author.id)

            user_id = re.sub(r'<@(\d+)\>', '\\1', user_id)

            member = self.get_user_by_id(message_object, user_id)
            logging.info("member move for: %s " % member)

            # get target channel
            default_channel_name = "Afk"
            # default_channel = get_key_from_kwargs('message_object', kwargs).server.get_channel(default_channel_name) # type:discord.Channel

            # see if channel kwarg specified
            channel_name = get_key_from_kwargs(
                'channel', kwargs,
                default_channel_name)  # type: discord.Channel

            # channel = get_key_from_kwargs('message_object', kwargs).server.get_channel(channel_name) # type:discord.Channel

            channel = self.get_channel_by_name(message_object, channel_name)

            logging.info("moving %s to %s" % (member, channel))
            logging.info("moving id: %s to name:%s" %
                         (member.name, getattr(channel, 'type')))
            logging.info("moving %s to %s" % (type(member), type(channel)))
            # channel_obj = self.api.get_channel(channel)

            # self.api.get_user_info(used_id)

            await self.api.move_member(member, channel)
            return "moved %s to %s" % (member.name, channel.name)

            # return result

        except Exception as e:
            logging.error("error moving member: %s" % e)
            return "%s: I'm afraid I can't do that Dave..." % self.plugin_name
Ejemplo n.º 4
0
    def test_order_pizza_cancel(self, order_pizza=True, cancel=True):
        # check if this is a cancelation
        if get_key_from_kwargs("cancel", self.kwargs, is_optional=True):
            self.requirements.requirements["cancel"].set("false")

        if self.requirements.get_requirement("cancel").value:
            return self.requirements.get_requirement("cancel").set_msg

        self.assertEqual("never get here", None)
Ejemplo n.º 5
0
    def begin_session(self, *args, **kwargs):
        logging.info("begin_session")

        message_object = get_key_from_kwargs('message_object',
                                             kwargs)  # type: discord.Message
        user = message_object.author.id  # type: discord.User

        if not user in self.dialog_sessions:
            logging.info("new dialog session starting for user: %s" % user)

            dialog_session = DialogSession()
            dialog_session.set_user(user)
            dialog_session.set_plugin(self)

            # requirements holders
            requirements = Requirements()  # type:Requirements

            # first we set all the requirements to with thier value to None
            requirements.new_requirement(
                "menu",
                "The available pizza's are: {options}",
                "You have selected pizza: {value}",
                None,
                auto_prompt=False,
                options=["Cacciatore", "Mexican", "Taco", "Fish"])
            requirements.new_requirement(
                "pizza_name", "Which pizza would you like to order?",
                "You have selected {value}", None)
            requirements.new_requirement("address", "What is the address?",
                                         "Address set to: {value}", None)
            requirements.new_requirement("payment_method",
                                         "How would you like to pay",
                                         "Payment method: {value}",
                                         None,
                                         options=["Cash", "Card"])
            requirements.new_requirement("confirm",
                                         "Please confirm your order.",
                                         "Order confirmed", None)
            requirements.new_requirement("cancel",
                                         "Would you like to cancel?",
                                         "Order cancelled",
                                         None,
                                         auto_prompt=False)

            # put requirements into the session
            dialog_session.set_data(requirements)
            self.dialog_sessions[user] = dialog_session
            return self.dialog_sessions[user]

        else:
            logging.info("continuing session for user: %s" % user)
            return self.dialog_sessions[user]
Ejemplo n.º 6
0
    async def channel(self, *args, **kwargs):
        logging.info("about this channel they say: %s, %s" % (args, kwargs))
        message_object = get_key_from_kwargs('message_object',
                                             kwargs)  # type: discord.Message
        channel = message_object.channel  # type:discord.Channel

        if channel.is_private:
            return "This is a private channel, just between us, feel free to say anything. Nothing is logged"

        rename = get_key_from_kwargs("rename", kwargs, None, is_optional=True)
        if rename:
            await self.api.edit_channel(channel, name=rename)

        retopic = get_key_from_kwargs("retopic",
                                      kwargs,
                                      None,
                                      is_optional=True)
        if retopic:
            await self.api.edit_channel(channel, topic=retopic)

        return "This channel is called: '%s', and the topic is: '%s'" % (
            channel.name, channel.topic)
Ejemplo n.º 7
0
    async def order_pizza_real(self, *args, **kwargs):

        if self.is_context_locking() and not self.is_locking_session():
            self.set_locking_session(True)
            return "%s, I am pizzabot, may I take your order?" % self.get_header(
            )

        data = self.get_data(*args, **kwargs)
        logging.info("data: %s" % data)

        response = ""

        # check if this is a help request
        if get_key_from_kwargs("help", kwargs, default=False,
                               is_optional=True):
            return self.help(*args, **kwargs)

        # check if this is a cancelation
        if get_key_from_kwargs("cancel",
                               kwargs,
                               default=False,
                               is_optional=True):
            logging.info("cancelling order per user's requrest")
            data.get_requirement("cancel").set(True)

        # if cancelling, we cancel and return the cancellation set response
        if data.get_requirement("cancel").value:
            logging.info("cancelling order")
            self.set_locking_session(False)
            response = self.build_response(
                data.get_requirement("cancel").set_msg)
            data = None
            self.destroy_session(*args, **kwargs)
            return response

        # call on the data to handle the request
        return data.process_request(*args, **kwargs)
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     logging.info("Instantiating %s" % self)
     self.somekey = get_key_from_kwargs('somekey', kwargs)
     kwargs.pop('api')
     self.args = args
     self.kwargs = kwargs
Ejemplo n.º 9
0
    def test_get_key_from_kwargs(self):
        with self.assertRaises(MissingProperty):
            get_key_from_kwargs("test", {})

        a = get_key_from_kwargs("test", {}, "default")
        self.assertEqual(a, "default")