Adding help to the debug prompt
[theonering] / src / channel / debug_prompt.py
index a491212..97a3ab2 100644 (file)
@@ -6,33 +6,29 @@ import logging
 
 import telepathy
 
+import tp
 import gtk_toolbox
 
 
 _moduleLogger = logging.getLogger("channel.text")
 
 
-class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
+class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
        """
        Look into implementing ChannelInterfaceMessages for rich text formatting
        """
 
        def __init__(self, connection, manager, props, contactHandle):
-               self._manager = manager
-               self._props = props
+               self.__manager = manager
+               self.__props = props
 
                cmd.Cmd.__init__(self, "Debug Prompt")
                self.use_rawinput = False
-               try:
-                       # HACK Older python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, contactHandle)
-               except TypeError:
-                       # HACK Newer python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, manager, props)
-               self._nextRecievedId = 0
-               self._lastMessageTimestamp = datetime.datetime(1, 1, 1)
+               tp.ChannelTypeText.__init__(self, connection, manager, props)
+               self.__nextRecievedId = 0
+               self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
 
-               self._otherHandle = contactHandle
+               self.__otherHandle = contactHandle
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def Send(self, messageType, text):
@@ -56,21 +52,19 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                self.close()
 
        def close(self):
-               telepathy.server.ChannelTypeText.Close(self)
-               if self._manager.channel_exists(self._props):
-                       # HACK Older python-telepathy requires doing this manually
-                       self._manager.remove_channel(self)
+               _moduleLogger.debug("Closing debug")
+               tp.ChannelTypeText.Close(self)
                self.remove_from_connection()
 
        def _report_new_message(self, message):
-               currentReceivedId = self._nextRecievedId
+               currentReceivedId = self.__nextRecievedId
 
                timestamp = int(time.time())
                type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
 
-               self.Received(currentReceivedId, timestamp, self._otherHandle, type, 0, message.strip())
+               self.Received(currentReceivedId, timestamp, self.__otherHandle, type, 0, message.strip())
 
-               self._nextRecievedId += 1
+               self.__nextRecievedId += 1
 
        def do_reset_state_machine(self, args):
                if args:
@@ -83,6 +77,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_reset_state_machine(self):
+               self._report_new_message("Reset the refreshing state machine")
+
        def do_get_state(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -94,6 +91,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_state(self):
+               self._report_new_message("Print the current state the refreshing state machine is in")
+
        def do_is_authed(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -105,6 +105,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_is_authed(self):
+               self._report_new_message("Print whether logged in to Google Voice")
+
        def do_is_dnd(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -116,6 +119,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_is_dnd(self):
+               self._report_new_message("Print whether Do-Not-Disturb mode enabled on the Google Voice account")
+
        def do_get_account_number(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -127,6 +133,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_account_number(self):
+               self._report_new_message("Print the Google Voice account number")
+
        def do_get_callback_numbers(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -142,6 +151,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_callback_numbers(self):
+               self._report_new_message("Print a list of all configured callback numbers")
+
        def do_get_callback_number(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -153,6 +165,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_callback_number(self):
+               self._report_new_message("Print the callback number currently enabled")
+
        def do_call(self, args):
                if len(args) != 1:
                        self._report_new_message("Must specify the phone number and only the phone nunber")
@@ -164,6 +179,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_call(self):
+               self._report_new_message("\n".join(["call NUMBER", "Initiate a callback, Google forwarding the call to the callback number"]))
+
        def do_send_sms(self, args):
                if 1 < len(args):
                        self._report_new_message("Must specify the phone number and then message")
@@ -175,3 +193,6 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                        self._conn.session.backend.send_sms(number, message)
                except Exception, e:
                        self._report_new_message(str(e))
+
+       def help_send_sms(self):
+               self._report_new_message("\n".join(["send_sms NUMBER MESSAGE0 MESSAGE1 ...", "Send an sms to number NUMBER"]))