示例#1
0
    def get(self):
        group_member_id = []
        group_list = []
        group_member_id_text = ""
        group_member = self.get_argument("group_member")
        group_member_name = group_member.split(',')
        group_name = self.get_argument("group_name")

        for one in group_member_name:
            group_member_id_text += str(db.get_user_id_from_name(one)) + ","
        db.insert_group(group_name,
                        group_member_id_text[0:len(group_member_id_text) - 1])
        print(group_name)
        print(group_member_id)
        face_pics = ['cat.gif', 'fere.gif', 'lion.gif']
        img_name = random.choice(face_pics)
        user = db.get_user_id_from_name(self.get_current_user())
        for group in db.get_group_list():
            user_list = db.get_group_user_list(
                db.get_group_id_from_name(group[0]))
            if user in user_list:
                group_list.append(group)
        user_list = db.get_user_list()
        user_list.remove(self.get_current_user())
        self.render('index.html',
                    img_path=self.static_url('images/' + img_name),
                    user_name=str(self.get_current_user()),
                    user_list=user_list,
                    group_list=group_list,
                    my_name=self.get_current_user(),
                    my_active_time=db.get_my_active_time(
                        self.get_current_user()),
                    all_active_time=db.get_all_active_time())
示例#2
0
    def on_message(self, message):  #メーッセージ受信およびブロードキャスト
        global to_user
        global group_flag
        global waiters

        message = json.loads(message)
        print("on_message")
        print(message)
        print(self.get_current_user())
        # if(group_flag==False):
        db.insert_message(db.get_user_id_from_name(message["to_user"]),
                          db.get_user_id_from_name("bot"), db.get_now_time(),
                          message['message'], 0)
        #self.messages.append(message)
        # else:
        #     db.insert_message(db.get_group_id_from_name(message["to_user"]), db.get_user_id_from_name("bot"), db.get_now_time(),message['message'], 0)

        # print(to_user)
        # print(group_flag)
        # print(waiters)
        for waiter in waiters:
            print(waiter)

            # if group_flag == False:
            # print(db.get_user_id_from_name(to_user))
            if self.check_active_time(message["to_user"], message):
                if waiter[1] != db.get_user_id_from_name(message["to_user"]):
                    continue
                else:
                    waiter[0].write_message({
                        'img_path': message['img_path'],
                        'message': message['message'],
                        'to_user': message["to_user"],
                        'from_user': "******",
                        'my_name': "bot",
                        'is_group': 'False'
                    })
            else:
                break
            # else:
            #     group_user_list = db.get_group_user_list(db.get_group_id_from_name(message["to_user"]))
            #     for number in group_user_list:
            #         if waiter[1] == number:
            #             if waiter[0] == self:
            #                 continue
            #             waiter[0].write_message({'img_path': message['img_path'], 'message': message['message'] , 'to_user': message["to_user"] ,'from_user': "******", 'my_name':db.get_user_name(number) , 'is_group':'True'})

            print("send:" + waiter[1] + '\nmessage:' + message['message'])
示例#3
0
    def get(self):
        group_list = []
        group_name = self.get_argument("group_name")

        db.delete_group(group_name)
        print(group_name)
        face_pics = ['cat.gif', 'fere.gif', 'lion.gif']
        user = db.get_user_id_from_name(self.get_current_user())
        img_name = user + '.gif'
        for group in db.get_group_list():
            user_list = db.get_group_user_list(
                db.get_group_id_from_name(group[0]))
            if user in user_list:
                group_list.append(group)
        user_list = db.get_user_list()
        user_list.remove(self.get_current_user())
        self.render('index.html',
                    img_path=self.static_url('images/' + img_name),
                    user_name=str(self.get_current_user()),
                    user_list=user_list,
                    group_list=group_list,
                    my_name=self.get_current_user(),
                    my_active_time=db.get_my_active_time(
                        self.get_current_user()),
                    all_active_time=db.get_all_active_time())
示例#4
0
    def open(self, *args, **kwargs):  #初期メッセージ送信
        global to_user
        global group_flag
        global waiters

        print("open")
        print(self)
        waiters.append([self, db.get_user_id_from_name("bot")])
        self.messages = []
示例#5
0
    def on_close(self):

        name = self.get_current_user()
        user_id = db.get_user_id_from_name(name)

        connector = sqlite3.connect("Chat.db")
        cursur = connector.cursor()

        #ユーザがログアウトした時,そのユーザのIDを0にする
        sql = 'update User SET Is_in_Lab = 0 where User_ID = ' + user_id

        connector.execute(sql)

        connector.commit()

        cursur.close()
        connector.close()

        global waiters
        waiters.remove(
            [self, db.get_user_id_from_name(self.get_current_user())])
示例#6
0
 def get(self, *args, **kwargs):
     global group_flag
     is_permit = True
     user = self.get_current_user()
     img_name = user + '.gif'
     group_list = []
     global to_user
     try:
         print(self.get_argument("request_user"))
         #self.write("request message is "+self.get_argument("request_user"))
         to_user = self.get_argument("request_user")
         group_flag = False
     except:
         try:
             to_user = self.get_argument("request_group")
             group_flag = True
             user = db.get_user_id_from_name(self.get_current_user())
             user_list = db.get_group_user_list(
                 db.get_group_id_from_name(to_user))
             if user in user_list:
                 None
             else:
                 is_permit = False
                 to_user = "******"
                 self.redirect("/permission_deny")
         except:
             to_user = '******'
             group_flag = False
     user = db.get_user_id_from_name(self.get_current_user())
     for group in db.get_group_list():
         user_list = db.get_group_user_list(
             db.get_group_id_from_name(group[0]))
         if user in user_list:
             group_list.append(group)
     user_list = db.get_user_list()
     user_list.remove(self.get_current_user())
     if (is_permit):
         groupid = db.get_group_id_from_name(to_user)
         if (groupid is None):
             self.render('index.html',
                         img_path=self.static_url('images/' + img_name),
                         user_name=str(self.get_current_user()),
                         user_list=user_list,
                         group_list=group_list,
                         my_name=self.get_current_user(),
                         my_active_time=db.get_my_active_time(
                             self.get_current_user()),
                         all_active_time=db.get_all_active_time(),
                         talk_name=to_user,
                         readed_user="******")
         else:
             self.render('index.html',
                         img_path=self.static_url('images/' + img_name),
                         user_name=str(self.get_current_user()),
                         user_list=user_list,
                         group_list=group_list,
                         my_name=self.get_current_user(),
                         my_active_time=db.get_my_active_time(
                             self.get_current_user()),
                         all_active_time=db.get_all_active_time(),
                         talk_name=to_user,
                         users=db.get_user_name_from_group(groupid),
                         readed_user="******")
示例#7
0
    def open(self, *args, **kwargs):  #初期メッセージ送信
        global to_user
        global group_flag
        global waiters

        name = self.get_current_user()
        user_id = db.get_user_id_from_name(name)

        connector = sqlite3.connect("Chat.db")
        cursur = connector.cursor()
        #ユーザがログインした時,そのユーザのIDを1にする
        sql = 'update User SET Is_in_Lab = 1 where User_ID = ' + user_id
        print("sql:" + sql)
        # print("login2_id:" + user_id)

        connector.execute(sql)

        connector.commit()

        cursur.close()
        connector.close()

        print("\n\n\n\n\n\n\n\nonope             n\n\n\n\n\n\n\n\n\n\n\n")

        print("open")
        print(self)
        waiters.append(
            [self, db.get_user_id_from_name(self.get_current_user())])
        self.messages = []
        if (group_flag == False):
            for message in db.get_message(
                    db.get_user_id_from_name(to_user),
                    db.get_user_id_from_name(self.get_current_user())):
                #print(message)
                self.messages.append({
                    'img_path':
                    '/static/images/' + db.get_user_name(message[2]) + '.gif',
                    'message':
                    message[4],
                    'to_user':
                    db.get_user_name(message[1]),
                    'from_user':
                    db.get_user_name(message[2]),
                    'my_name':
                    self.get_current_user(),
                    'is_group':
                    'False'
                })
            self.write_message({'messages': self.messages})
        else:
            for message in db.get_group_message(
                    db.get_group_id_from_name(to_user)):
                #print(message)
                self.messages.append({
                    'img_path':
                    '/static/images/' + db.get_user_name(message[2]) + '.gif',
                    'message':
                    message[4],
                    'to_user':
                    db.get_group_name(message[1]),
                    'from_user':
                    db.get_user_name(message[2]),
                    'my_name':
                    self.get_current_user(),
                    'is_group':
                    'True'
                })
            self.write_message({'messages': self.messages})
示例#8
0
 def on_close(self):
     global waiters
     waiters.remove([self, db.get_user_id_from_name("bot")])