from typing import Any, Dict
from django.utils.translation import ugettext as _

from zerver.models import UserProfile
from zerver.lib.actions import do_set_user_display_setting
from zerver.lib.exceptions import JsonableError

def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]:
    if not content.startswith('/'):
        raise JsonableError(_('There should be a leading slash in the zcommand.'))
    command = content[1:]

    if command == 'ping':
        ret = dict()  # type: Dict[str, Any]
        return ret

    night_commands = ['night', 'dark']
    day_commands = ['day', 'light']

    if command in night_commands:
        if user_profile.night_mode:
            msg = 'You are still in night mode.'
        else:
            msg = 'Changed to night mode! To revert night mode, type `%s`.' % (content,)
            do_set_user_display_setting(user_profile, 'night_mode', True)
        ret = dict(msg=msg)
        return ret

    if command in day_commands:
        if user_profile.night_mode:
            msg = 'Changed to day mode! To revert day mode, type `%s`.' % (content,)
            do_set_user_display_setting(user_profile, 'night_mode', False)
        else:
            msg = 'You are still in day mode.'
        ret = dict(msg=msg)
        return ret

    raise JsonableError(_('No such command: %s') % (command,))

@@ -740,32 +740,105 @@
 '%0A        else:%0A
+            switch_command = day_commands%5Bnight_commands.index(command)%5D%0A
             msg 
@@ -883,32 +883,33 @@
 ght mode, type %60
+/
 %25s%60.' %25 (content
@@ -893,39 +893,46 @@
 type %60/%25s%60.' %25 (
-content
+switch_command
 ,)%0A            d
@@ -1100,32 +1100,105 @@
 ile.night_mode:%0A
+            switch_command = night_commands%5Bday_commands.index(command)%5D%0A
             msg 
@@ -1247,16 +1247,17 @@
 , type %60
+/
 %25s%60.' %25 
@@ -1257,23 +1257,30 @@
 s%60.' %25 (
-content
+switch_command
 ,)%0A     

Fix broken switch mode message.