Exemple #1
0
 def __notice_notdone(self):
     self.now = dt.datetime.now()
     db = DB(os.environ['TODO_DB'])
     self.dict_list = db.dict_list()
     self.channel = os.environ['SLACK_CHANNEL']
     for dict in self.dict_list:
         # 前バージョンとの互換性を保つ
         if not "noticetime" in dict.keys():
             continue
         noticetime = int(dict['noticetime'])
         try:
             self.__limit_at = dt.datetime.strptime(dict["limit_at"],
                                                    '%Y/%m/%d %H:%M')
             # statusの更新
             if self.now > self.__limit_at and dict['status'] == '未':
                 db.change_id(dict['id'], 'status', '期限切れ')
         except:
             break
         color = ''
         text = ''
         post = False
         if dict["status"] == '未':
             if self.__limit_at < self.now + dt.timedelta(
                     hours=1) and noticetime == 1:
                 text = "期限まであと1時間。ひょっとして提出し忘れてるんじゃ?:face_with_rolling_eyes::face_with_rolling_eyes:"
                 noticetime = 0
                 color = 'ff4500'
                 post = True
             elif self.__limit_at < self.now + dt.timedelta(
                     days=1) and noticetime == 2:
                 text = "期限まであと1日もありません!!のんびりしてる暇なんてありませんね:sweat_drops:"
                 noticetime = 1
                 color = 'ffff00'
                 post = True
             elif self.__limit_at < self.now + dt.timedelta(
                     days=3) and noticetime == 3:
                 text = "期限まであと3日。そろそろとりかかろう...:sunglasses:"
                 noticetime = 2
                 color = '7cfc00'
                 post = True
         if post == True:
             attachments = [{
                 "color":
                 color,
                 "blocks": [{
                     "type": "section",
                     "text": {
                         "type":
                         "mrkdwn",
                         "text":
                         '*' + dict["title"] + '*\n' + '期限:' +
                         dict["limit_at"] + '\nid:' + dict["id"]
                     }
                 }]
             }]
             tools.postMessage(text,
                               attachments,
                               channel=self.channel,
                               icon_emoji=":panda_face:")
             db.change_id(dict['id'], 'noticetime', noticetime)
Exemple #2
0
def todo_change_id(id, column, value):
    database = DB(os.environ['TODO_DB'])
    status_code = database.change_id(id, column, value)
    msg = ''
    if status_code == 400:
        msg = 'カラムが不正です'
    elif status_code == 401:
        msg = 'idが不正です'
    elif status_code == 402:
        msg = 'sqlite文が実行できません'
    elif status_code == 403:
        msg = 'limit_atを正しく入力してください'
    elif status_code == 404:
        msg = 'idまたはupdate_atを変更することはできません'
    elif status_code == 200:
        msg = '値を変更しました'
    return msg
Exemple #3
0
def todo_finish(userid, ids):
    msg = ''
    msg1 = '\nid: '
    msg2 = '\nid: '
    msg3 = '\nid: '
    success = False
    failed = False
    others = False
    id = ids.split()
    database = DB(os.environ['TODO_DB'])
    for i in id:
        strip = i.find('|')
        if strip > 0:
            i = i[strip + 1:]
        i = i.replace('>', '')
        data = database.select_id(i)
        if data["user"] == None:
            msg2 += '`' + i + '` '
            failed = True
            continue
        elif userid != data["user"]:
            msg3 += '`' + i + '` '
            others = True
            continue
        status_code = database.change_id(i, 'status', '済')
        if status_code == 200:
            msg1 += '`' + i + '` '
            success = True
    if success and failed and others:
        msg = msg1 + 'を完了しました。お疲れ様でした。' + msg2 + 'は存在しません。' + msg3 + 'は他人のタスクです。'
    elif success and failed:
        msg = msg1 + 'を完了しました。お疲れ様でした。' + msg2 + 'は存在しません。'
    elif failed and others:
        msg = msg2 + 'は存在しません。' + msg3 + 'は他人のタスクです。'
    elif success:
        msg = msg1 + 'を完了しました。お疲れ様でした。'
    elif failed:
        msg = msg2 + 'は存在しません。'
    elif others:
        msg = msg3 + 'は他人のタスクです。'
    else:
        msg = 'このコマンドは実行できません。'
    return msg
Exemple #4
0
    def __notice_notdone(self):
        self.now = dt.datetime.now()
        db = DB(os.environ['TODO_DB'])
        self.dict_list = db.dict_list()
        self.channel = os.environ['SLACK_CHANNEL']
        self.notice_tasks = []
        for dict in self.dict_list:
            # 前バージョンとの互換性を保つ
            if not "noticetime" in dict.keys():
                continue
            noticetime = int(dict['noticetime'])
            try:
                self.__limit_at = dt.datetime.strptime(dict["limit_at"],
                                                       '%Y/%m/%d %H:%M')
                # statusの更新
                if self.now > self.__limit_at and dict['status'] == '未':
                    db.change_id(dict['id'], 'status', '期限切れ')
            except:
                break
            color = ''
            text = ''
            post_dm = False
            post_announce = False
            attachments = []
            # 全体アナウンス
            if dict['user'] == 'all':
                if self.__limit_at < self.now + dt.timedelta(
                        hours=1) and noticetime == 1:
                    text = '3日後の予定をお知らせします。'
                    noticetime = 0
                    color = 'ff4500'
                    post_announce = True
                elif self.__limit_at < self.now + dt.timedelta(
                        days=1) and noticetime == 2:
                    text = '1日後の予定をお知らせします。'
                    noticetime = 1
                    color = 'ffff00'
                    post_announce = True
                elif self.__limit_at < self.now + dt.timedelta(
                        days=3) and noticetime == 3:
                    text = '1時間後の予定をお知らせします。'
                    noticetime = 2
                    color = '7cfc00'
                    post_announce = True
            else:
                if dict["status"] == '未':
                    if self.__limit_at < self.now + dt.timedelta(
                            hours=1) and noticetime == 1:
                        text = "期限まであと1時間。ひょっとして提出し忘れてるんじゃ?:face_with_rolling_eyes::face_with_rolling_eyes:"
                        noticetime = 0
                        color = 'ff4500'
                        post_dm = True
                    elif self.__limit_at < self.now + dt.timedelta(
                            days=1) and noticetime == 2:
                        text = "期限まであと1日もありません!!のんびりしてる暇なんてありませんね:sweat_drops:"
                        noticetime = 1
                        color = 'ffff00'
                        post_dm = True
                    elif self.__limit_at < self.now + dt.timedelta(
                            days=3) and noticetime == 3:
                        text = "期限まであと3日。そろそろとりかかろう...:sunglasses:"
                        noticetime = 2
                        color = '7cfc00'
                        post_dm = True
            if post_dm == True:
                dict["limit_at"] = dict["limit_at"][5:]
                if dict["subject"] != 'None' and dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n教科:' +
                                dict["subject"] + '\n期限:' + dict["limit_at"] +
                                '\n id : `' + str(dict["id"]) + '`'
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                elif dict["subject"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n教科:' +
                                dict["subject"] + '\n期限:' + dict["limit_at"] +
                                '\n id : `' + str(dict["id"]) + '` '
                            }
                        }]
                    }]
                elif dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n期限:' +
                                dict["limit_at"] + '\n id : `' +
                                str(dict["id"]) + '` '
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                else:
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                ' *' + dict["title"] + '* \n期限:' +
                                dict["limit_at"] + '\n id : `' +
                                str(dict["id"]) + '` '
                            }
                        }]
                    }]

            if post_announce == True:
                dict["user"] = self.channel
                dict["limit_at"] = dict["limit_at"][5:]
                if dict["subject"] != 'None' and dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です。\n教科:' +
                                dict["subject"] + '\n日付:' + dict["limit_at"]
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                elif dict["subject"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です。\n教科:' +
                                dict["subject"] + '\n日付:' + dict["limit_at"]
                            }
                        }]
                    }]
                elif dict["note"] != 'None':
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です\n日付:' +
                                dict["limit_at"]
                            }
                        }, {
                            "type":
                            "context",
                            "elements": [{
                                "type": "plain_text",
                                "text": "※備考\n" + dict["note"]
                            }]
                        }]
                    }]
                else:
                    attachments = [{
                        "color":
                        color,
                        "blocks": [{
                            "type": "section",
                            "text": {
                                "type":
                                "mrkdwn",
                                "text":
                                '*' + dict["title"] + '* の情報です\n日付:' +
                                dict["limit_at"]
                            }
                        }]
                    }]

            if post_announce or post_dm:
                # tools.postMessage(text, attachments, channel=dict['user'], icon_emoji=":panda_face:")
                db.change_id(dict['id'], 'noticetime', noticetime)
                self.notice_tasks.append({
                    "text": text,
                    "attachments": attachments,
                    "channel": dict["user"]
                })

        return self.notice_tasks
Exemple #5
0
def slack_app():
    if not signature_verifier.is_valid_request(request.get_data(), request.headers):
        return make_response("invalid request", 403)

    if "payload" in request.form:
        payload = json.loads(request.form["payload"])
        user_id = payload["user"]["id"]

        if payload["type"] == "view_submission" \
            and payload["view"]["callback_id"] == "login":
            # Handle a data submission request from the modal
            submitted_data = payload["view"]["state"]["values"]            
            # {'block-id': {'action_id': {'type': 'plain_text_input', 'value': 'your input'}}}
            esc_id = submitted_data['esc_id']['esc_id']['value']
            password = submitted_data['password']['password']['value']
            status_code = user_database.change_id(user_id, esc_id, password)
            if status_code == 300:
                status_code = user_database.add(user_id, esc_id, password)
            if status_code == 400:
                slack_bot_client.chat_postMessage(text='登録に失敗しました。', channel=user_id, as_user=True)
                print('failed')
                return make_response("", 400)

            # if status_code == 200 or status_code == 300:
            #     chat = slack_bot_client.chat_postMessage(channel=user_id, text='更新中...しばらくお待ちください', as_user=True)
            #     login_data = user_database.select_id(user_id)

            #     # def pandaThread():
            #     #     login_data = user_database.select_id(user_id)
            #     #     panda_database_names[user_id]  = DB(os.environ["TODO_DB"])
            #     #     status_code = autoadd.main(user=login_data["id"], username=login_data["esc_id"], password=login_data["password"], database=panda_database_names[user_id])
            #     #     if status_code == 400:
            #     #         slack_bot_client.chat_update(channel=chat["channel"], text='esc-idとパスワードが間違っています。\n/pandaコマンドを入力して再登録してください', ts=chat["ts"], as_user=True)
            #     #     elif status_code == 200:
            #     #         print('pandaThread終了')
            #     #         if chat != None:
            #     #             slack_bot_client.chat_update(channel=chat["channel"], text='更新が終了しました', ts=chat["ts"], as_user=True)
            #     #             msg = todo.todo_list(user_id) 
            #     #             slack_bot_client.chat_postMessage(channel=chat["channel"], text=msg, as_user=True)      

            #     if panda_sched.get_job(user_id) != None:
            #         panda_sched.remove_job(user_id)
            #     panda_sched.add_job(func=pandaThread, trigger='interval', minutes=30, id=login_data["id"], next_run_time=datetime.datetime.now())
            

            return make_response("", 200)

        elif payload["type"] == "block_actions":
            task_user = payload["actions"][0]["block_id"]
            text = ''                
            channel = payload["channel"]["id"]
            if payload["actions"][0]["value"] == 'finished':
                task_id = payload["actions"][0]["action_id"]
                if task_user == user_id:
                    database = DB(os.environ["TODO_DB"])
                    database.change_id(task_id, 'status', '済')
                    text = 'id:' + task_id + 'を完了しました'
            elif payload["actions"][0]["value"] == 'unfinished':
                task_id = payload["actions"][0]["action_id"][1:]
                if task_user == user_id:
                    database = DB(os.environ["TODO_DB"])
                    database.change_id(task_id, 'status', '未')
                    text = 'id:' + task_id + 'を未完了に変更しました'
            slack_bot_client.chat_postMessage(channel=channel, text=text)
            return make_response("", 200)

    return make_response("", 404)