
from base import *
import random

import bnw_core.bnw_objects as objs

@require_auth
@defer.inlineCallbacks
def cmd_on(request):
    """ Включение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':False}},safe=True)
    if request.user['off']:
        defer.returnValue(
            dict(ok=True,desc='Welcome back!')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='Welcoooome baaaack, I said.')
        )

@require_auth
@defer.inlineCallbacks
def cmd_off(request):
    """ Выключение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':True}},safe=True)
    if request.user['off']:
        defer.returnValue(
            dict(ok=True,desc='See you later.')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='C u l8r!')
        )


from base import *
import random

import bnw_core.bnw_objects as objs

@require_auth
@defer.inlineCallbacks
def cmd_on(request):
    """ Включение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':False}},safe=True)
    if request.user.get('off',False):
        defer.returnValue(
            dict(ok=True,desc='Welcome back!')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='Welcoooome baaaack, I said.')
        )

@require_auth
@defer.inlineCallbacks
def cmd_off(request):
    """ Выключение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':True}},safe=True)
    if request.user.get('off',False):
        defer.returnValue(
            dict(ok=True,desc='See you later.')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='C u l8r!')
        )

Fix on/off if there is no 'off' field.
Fix on/off if there is no 'off' field.

  
  from base import *
  import random
  
  import bnw_core.bnw_objects as objs
  
  @require_auth
  @defer.inlineCallbacks
  def cmd_on(request):
      """ Включение доставки сообщений """
      _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':False}},safe=True)
-     if request.user['off']:
+     if request.user.get('off',False):
          defer.returnValue(
              dict(ok=True,desc='Welcome back!')
          )
      else:
          defer.returnValue(
              dict(ok=True,desc='Welcoooome baaaack, I said.')
          )
  
  @require_auth
  @defer.inlineCallbacks
  def cmd_off(request):
      """ Выключение доставки сообщений """
      _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':True}},safe=True)
-     if request.user['off']:
+     if request.user.get('off',False):
          defer.returnValue(
              dict(ok=True,desc='See you later.')
          )
      else:
          defer.returnValue(
              dict(ok=True,desc='C u l8r!')
          )
  
Fix on/off if there is no 'off' field.
## Code Before:

from base import *
import random

import bnw_core.bnw_objects as objs

@require_auth
@defer.inlineCallbacks
def cmd_on(request):
    """ Включение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':False}},safe=True)
    if request.user['off']:
        defer.returnValue(
            dict(ok=True,desc='Welcome back!')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='Welcoooome baaaack, I said.')
        )

@require_auth
@defer.inlineCallbacks
def cmd_off(request):
    """ Выключение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':True}},safe=True)
    if request.user['off']:
        defer.returnValue(
            dict(ok=True,desc='See you later.')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='C u l8r!')
        )

## Instruction:
Fix on/off if there is no 'off' field.
## Code After:

from base import *
import random

import bnw_core.bnw_objects as objs

@require_auth
@defer.inlineCallbacks
def cmd_on(request):
    """ Включение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':False}},safe=True)
    if request.user.get('off',False):
        defer.returnValue(
            dict(ok=True,desc='Welcome back!')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='Welcoooome baaaack, I said.')
        )

@require_auth
@defer.inlineCallbacks
def cmd_off(request):
    """ Выключение доставки сообщений """
    _ = yield objs.User.mupdate({'name':request.user['name']},{'$set':{'off':True}},safe=True)
    if request.user.get('off',False):
        defer.returnValue(
            dict(ok=True,desc='See you later.')
        )
    else:
        defer.returnValue(
            dict(ok=True,desc='C u l8r!')
        )
