示例#1
0
def triggers_list(bot, update):
    from utils.utils import is_valid
    if not is_valid(update, admin=True):
        return

    text = 'Список существующих триггеров: \n'
    for enabled_trigger in Trigger.get_all_enabled():
        text += '{} - номер: {}\n'.format(enabled_trigger.request,
                                          enabled_trigger.id)

    update.message.reply_text(text)
示例#2
0
 def post(self,request,*args,**kwargs):
     data = request.body.decode('utf-8')
     valid_json = is_valid(data)
     if not valid_json:
         json_data = json.dumps({"msg" : "Please give valid data"})
         return self.render_to_http_response(json_data,status = 412)
     emp_data = json.loads(data)
     form = EmployeeForm(emp_data)
     if form.is_valid():
         form.save(commit=True)
         json_data = json.dumps({"msg": " Created Successfully"})
         return self.render_to_http_response(json_data, status=201)
     if form.errors:
         json_data = json.dumps(form.errors)
         return self.render_to_http_response(json_data, status=412)
示例#3
0
def trigger_add_step_one(bot, update, args):
    from utils.utils import is_valid
    from main import Bot
    if not is_valid(update, admin=True):
        return

    request = ' '.join(args)
    if not request:
        update.message.reply_text('/tda <текст триггера>')
        return

    Bot.addition_process.update(
        {update.message.from_user.id: Trigger(request=request)})

    update.message.reply_text(
        '/tdc - отмена создания\n\nОтправьте ответ на триггер:')
示例#4
0
def trigger_delete(bot, update, args):
    from utils.utils import is_valid
    if not is_valid(update, admin=True):
        return

    if not args:
        update.message.reply_text("/trd <номер триггера>")
        return

    trigger = Trigger.get_by_id(args[0])
    if not trigger:
        update.message.reply_text('Не могу найти триггер с номером {}'.format(
            args[0]))
    else:
        trigger.enable = False
        trigger.save()

        update.message.reply_text('Триггер удалён')
示例#5
0
def trigger_parse(bot, update):
    print(update)

    from utils.utils import is_valid
    if not is_valid(update):
        return

    action = update.message.reply_text
    request = update.message.text.lower()
    for trigger in Trigger.get_by_request(request):
        if trigger.type == Type.TEXT:
            action = update.message.reply_text
        elif trigger.type == Type.PHOTO:
            action = update.message.reply_photo
        elif trigger.type == Type.STICKER:
            action = update.message.reply_sticker

        action(trigger.response)
示例#6
0
 def put(self,request,id,*args,**kwargs):
     emp = self.get_obejct_by_id(id)
     if emp is None:
         return self.render_to_http_response(json.dumps({"msg" : "requested resource does not exist"}),status = 404)
     data = request.body.decode('utf-8')
     valid_json = is_valid(data)
     if not valid_json:
         return self.render_to_http_response(json.dumps({"msg" : "Please Provide Valid json"}),status = 417)
     provided_data = json.loads(data)
     original_data = {
         "eno" : emp.eno,
         "ename" : emp.ename,
         "esal" : emp.esal,
         "eaddr":emp.eaddr
     }
     original_data.update(provided_data)
     form = EmployeeForm(original_data,instance=emp)
     if form.is_valid():
         form.save(commit=True)
         return self.render_to_http_response(json.dumps({"msg" : "Updated Successfully"}),status = 202)
     if form.errors:
         json_data = json.dumps(form.errors)
         return self.render_to_http_response(json_data,status=417)