Beispiel #1
0
def msg_monitor(bot: Client, m: Message):
    """
    Сохраняет в БД все сообщения кроме API и Secret ключей
    Полезно для анализа взаимодействия с ботом
    """
    with db.atomic():
        Msg.create(tg_id=m.from_user.id, text=m.text)
Beispiel #2
0
async def message_handler(message: Message):
    mode = message.chat.type
    Chat.save_chat(message)
    user = User.get_by_message(message)
    Msg.create(text=message.text, user=user, mode=mode)

    if mode == 'private':
        for chat in Chat.select():
            sender_title = translator.translate(
                f"Unidentified {user.animal} writes:", dest='ru',
                src='en').text
            msg_text = f"*{sender_title}* \n{message.text}"

            inline_keyboard = InlineKeyboardMarkup()
            inline_button = InlineKeyboardButton(
                'Ответить в боте',
                switch_inline_query=f'Ответить {user.animal}:')
            inline_keyboard.add(inline_button)
            await bot.send_message(chat_id=chat.id,
                                   text=msg_text,
                                   parse_mode='Markdown',
                                   reply_markup=inline_keyboard)
            await sleep(1)
Beispiel #3
0
	def get(self):
		uid = self.request.get('uid')
		action = self.request.get('action')
		
		if(action=="load"):
			msglist = Msg.get_last_msg(self.user.key.id(),uid)
			if msglist:
				msglist.reverse()
				msgs= []
				for msg in msglist:
					msgs.append({'txt': msg.msgcontent, 'd': msg.direction})
				
				self.response.out.write(json.dumps(msgs))
		
			else:
				self.response.out.write("none")
		else:
			nmsg = self.request.get('nmsg')
			bool= Msg.send_msg(self.user.key.id(), uid, nmsg)
			if bool:
				self.response.out.write("1")
			else:
				self.response.out.write("error")
def main(request):
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = MsgForm(request.POST)
        if form.is_valid():
            msg = form.cleaned_data['msg']
            if len(msg) > 0:
                Msg(body=msg).save()
        return HttpResponseRedirect('/thanks/')
    else:
        form = MsgForm()

        return render(request, 'index.html', {
            "stories": Msg.objects.all(),
            'form': form
        })
Beispiel #5
0
def init():
    Chat.create_table(fail_silently=True)
    User.create_table(fail_silently=True)
    Msg.create_table(fail_silently=True)
    UserHashMatching.create_table(fail_silently=True)
Beispiel #6
0
    msg_items = sorted(msg_items, key = msg_key, reverse = False)
    for msg_item in msg_items:
        if msg_item['type'] == 1 and msg_item['id'] > last_msg_id:
            #weixin.get_user_icon(fakeid = int(msg_item['fakeid']), uri = 'media/wxuserimg')
            fu = get_user(weixin,wxwall, int(msg_item['fakeid']),msg_item['nick_name'])
            item = {
                    'nick_name':msg_item['nick_name'],
                    'content':msg_item['content'],
                    'msg_type':1,
                    'msg_id':msg_item['id'],
                    'icon':fu.icon
                    }
            data['msg'].append(item)
            wxwall.last_msg_id = msg_item['id']
            wxwall.msg_count = wxwall.msg_count + 1
            m = Msg()
            m.wxwall = wxwall
            m.msg_id = msg_item['id']
            m.fake_id = fu
            m.msg_type = 1
            m.date_time = msg_item['date_time']
            m.content = msg_item['content']
            m.save()

    wxwall.save()

    return render_to_response('msg_item.html',data)

#@require_POST
#@csrf_exempt
def get_msg_count(request, wxwall_id):
Beispiel #7
0
from models import Msg


def waiting():
    input()


if __name__ == '__main__':
    msgs = Msg()
    """
    print("Nombre Total : ", msgs.nb())
    print("[Kajun] Nombre msgs : ", msgs.nb_by_name('Kajun'))
    print("[JC] Nombre msgs : ", msgs.nb_by_name('JC'))
    d = msgs.find(10)
    print('\tMsg: 10 is: \n', 'id: {0}\ttime: {1}\tname: {2}\tmsg: {3}'.format(d.id, d.time, d.name, d.msg),'\n')

    print('\tAll Messages from [Kajun] : ')
    for d in msgs.by_name('Kajun'):
        print('id: {0}\ttime: {1}\tname: {2}\tmsg: {3}'.format(d.id,d.time,d.name,d.msg))

    print('\tAll Messages from [JC] : ')
    for d in msgs.by_name('JC'):
        print('id: {0}\ttime: {1}\tname: {2}\tmsg: {3}'.format(d.id, d.time, d.name, d.msg))
    
    """

    #print('\tAfficher tout les noms {}: '.format(len(msgs.get_all_names())))
    #for name in msgs.get_all_names():
    #print(' - ', name, '-')

    for d in msgs.all():
Beispiel #8
0
    msg_items = sorted(msg_items, key=msg_key, reverse=False)
    for msg_item in msg_items:
        if msg_item["type"] == 1 and msg_item["id"] > last_msg_id:
            # weixin.get_user_icon(fakeid = int(msg_item['fakeid']), uri = 'media/wxuserimg')
            fu = get_user(weixin, wxwall, int(msg_item["fakeid"]), msg_item["nick_name"])
            item = {
                "nick_name": msg_item["nick_name"],
                "content": msg_item["content"],
                "msg_type": 1,
                "msg_id": msg_item["id"],
                "icon": fu.icon,
            }
            data["msg"].append(item)
            wxwall.last_msg_id = msg_item["id"]
            wxwall.msg_count = wxwall.msg_count + 1
            m = Msg()
            m.wxwall = wxwall
            m.msg_id = msg_item["id"]
            m.fake_id = fu
            m.msg_type = 1
            m.date_time = msg_item["date_time"]
            m.content = msg_item["content"]
            m.save()

    wxwall.save()

    return render_to_response("msg_item.html", data)


# @require_POST
# @csrf_exempt
Beispiel #9
0
locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')

bot = telebot.TeleBot(cfg.token)
db = SqliteDatabase('db.sqlite3')

morph = pymorphy2.MorphAnalyzer() # объект для морфологического преобразования слов

sid = lambda m: m.chat.id # лямбды для определения адреса ответа
uid = lambda m: m.from_user.id
cid = lambda c: c.message.chat.id

version = 2
block_io = BlockIo(cfg.key, cfg.pin, version)

msg = Msg() # это для строк. Сообщения и Кнопки.
# r = Routing()
btn = Btn()





class BaseModel(Model):
	class Meta:
		database = db



class User(BaseModel):
	user_id 	 = IntegerField(primary_key = True)