Exemplo n.º 1
0
def send_score_to_sheet(event, thisUser):

    testName = thisUser.memo.split('%')

    thisUser.status = ''
    thisUser.where = ''
    thisUser.memo = ''
    thisUser.save()

    requests.post(env('GAS_ENTRY'),
                  data={
                      'subj':
                      thisUser.job if len(testName) == 1 else testName[1],
                      'name': testName[0],
                      'scores': string_to_scores_list(event.message.text)
                  })

    url = 'https://docs.google.com/spreadsheets/d/1OUR9r-VDK834KXHBubOWS1EqXB3Tre07q7HKXHxSYFE/edit?usp=sharing'

    return line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(
            text=f"成績已送出(表單需要一點時間更新)\n{url}",
            quick_reply=QUICKREPLY_MENU(event, thisUser),
        ))
Exemplo n.º 2
0
def score_main(event, thisUser):
    thisUser.where = 'score'
    thisUser.status = 'wfi_testName'
    thisUser.save()

    return line_bot_api.reply_message(event.reply_token,
                                      TextSendMessage(text="請輸入考試名稱 :"))
Exemplo n.º 3
0
def score_registerJob(event, thisUser):
    thisUser.where = 'score'
    thisUser.status = 'wfi_job'
    thisUser.save()

    return line_bot_api.reply_message(event.reply_token,
                                      TextSendMessage(text="請輸入小老師名稱 :"))
Exemplo n.º 4
0
def handle_text_message(event: MessageEvent):
    """
    Echo the same message
    """

    line_bot_api = LineBotApi(LINE_CHANNEL_TOKEN)
    line_bot_api.reply_message(
        event.reply_token, TextSendMessage(event.message.text)
    )
Exemplo n.º 5
0
def handle_follow(event):
    newUser = User(
        lineID=event.source.user_id,
        where='register',
        status='wfi',
    )
    newUser.save()

    return line_bot_api.reply_message(
        event.reply_token, TextSendMessage(text="請輸入 座號 + 空格 + 姓名 :"))
Exemplo n.º 6
0
def bike(event, thisUser):
  url = 'https://data.tycg.gov.tw/api/v1/rest/datastore/a1b4714b-3b75-4ff8-a8f2-cc377e4eaa0f?format=json'

  resp = requests.get(url)
  data = resp.json()['result']['records'][1]
  update = data['mday'][8:]

  result = f"""車子數量 : {data['sbi']}
空位 : {data['bemp']}
最後更新時間 : {update[:2]}:{update[2:4]}:{update[4:]}"""

  if event.source.type == 'group':
    return line_bot_api.reply_message(event.reply_token,TextSendMessage(
      text= result
    ))

  return line_bot_api.reply_message(event.reply_token,TextSendMessage(
    text= result,
    quick_reply=QUICKREPLY_MENU(event, thisUser)
  ))
Exemplo n.º 7
0
 def get_reply_messages(self):
     text_functions = {
         '打卡': 'check_in',
         '嗨': 'hello',
         '首頁': 'index',
     }
     text_function = text_functions.get(self.text)
     if text_function:
         return getattr(self, text_function)()
     else:
         return TextSendMessage(text=self.text)
Exemplo n.º 8
0
def score_applyJob(event, thisUser):
    thisUser.where = ''
    thisUser.status = ''
    thisUser.job = event.message.text
    thisUser.save()

    return line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(
            text="登記完成 !",
            quick_reply=QUICKREPLY_MENU(event, thisUser),
        ))
Exemplo n.º 9
0
def register(event, thisUser):
    try:
        number, name = event.message.text.split()
        number = int(number)

        thisUser.number = number
        thisUser.name = name

    except:
        return line_bot_api.reply_message(
            event.reply_token, TextSendMessage(text="出現問題, 請重新輸入 :"))

    thisUser.status = ""
    thisUser.where = ""
    thisUser.save()

    return line_bot_api.reply_message(
        event.reply_token,
        TextSendMessage(
            text="已建檔完成 !",
            quick_reply=QUICKREPLY_MENU(event, thisUser),
        ))
Exemplo n.º 10
0
def score_gi_main(event, thisUser):
    if thisUser.status == 'wfi_testName':

        thisUser.status = 'wfi_testScores'
        thisUser.memo = event.message.text
        thisUser.save()

        return line_bot_api.reply_message(event.reply_token,
                                          TextSendMessage(text="請輸入成績 :"))

    if thisUser.status == 'wfi_testScores':
        return send_score_to_sheet(event, thisUser)

    if thisUser.status == 'wfi_job':
        return score_applyJob(event, thisUser)
Exemplo n.º 11
0
    def on_enter_show(self, event):

        now = 0
        for i in range(len(player_num)):
            if player_num[i].number == CurrentPlayer[len(CurrentPlayer) -
                                                     1].number:
                now = i
        message = TextSendMessage(
            text='No.%d:\n2pt:%d-%d\n3pt%d-%d\n1pt%d-%d\nReb%d-%d' %
            (player_num[now].number, player_num[now].two_made,
             player_num[now].two_miss, player_num[now].three_made,
             player_num[now].three_miss, player_num[now].free_made,
             player_num[now].free_miss, player_num[now].ORebound,
             player_num[now].DRebound))
        line_bot_api.reply_message(event.reply_token, message)
Exemplo n.º 12
0
def reply(output, event):
    """回覆使用者,但是會先檢查"""
    # 如果在群組內發言而且沒有免檢查特權就檢查他
    group_check = database.group_data['permission']['check']
    need_check = event.source.user_id not in database.group_data[
        'permission']['no_check']
    if isinstance(output, SendMessage):
        bot.reply_message(event.reply_token, output)
    elif output:
        if (event.source.type == 'group' and
                need_check and
                event.source.group_id in group_check and
                database.is_banned(output)):
            return

        output = TextSendMessage(output)
        bot.reply_message(event.reply_token, output)
Exemplo n.º 13
0
 def get_reply_messages(self):
     messages = [
         TextSendMessage(text='打卡成功'),
         TextSendMessage(text=self.address)
     ]
     return messages
Exemplo n.º 14
0
 def index():
     return TextSendMessage(text='https://liff.line.me/1655260637-Dlg2wBRp')
Exemplo n.º 15
0
 def hello(self):
     return TextSendMessage(
         text='我所在的群組為{group_id}\n我的使用者身份為{user_id}'.format(
             user_id=self.user_id, group_id=self.group_id))
Exemplo n.º 16
0
 def check_in():
     return TextSendMessage(
         text='請點選打卡按鈕',
         quick_reply=QuickReply(
             items=[QuickReplyButton(action=LocationAction(label='打卡'))]))
Exemplo n.º 17
0
def help(event, thisUser):
  return line_bot_api.reply_message(event.reply_token,TextSendMessage(
    text= """bike : 取得校門口Ubike資訊""",
    quick_reply= QUICKREPLY_MENU(event, thisUser)
  ))
def translate(event):
    """
    step1. 建立Mongodb連線
    step2. 檢查是否要改翻譯目標語言,並把用戶的翻譯設定撈出來
    step3. 呼叫 googletrans API 並把翻譯內容回傳使用者

    """
    def _getUserTranslationSettings(user_profile):
        user_profile = collection.find_one({"userId": userId})
        return user_profile

    def _changeUserTranslationDest(user_profile, dest):
        user_lang_modified = collection.find_one_and_update(
            filter={"userId": userId},
            update={"$set": {
                "dest": dest
            }},
            return_document=ReturnDocument.AFTER)
        return user_lang_modified

    def _changSettings():
        lang = event.message.text[4:]
        dest = LANGCODES.get(lang)
        user_lang_modified = _changeUserTranslationDest(user_profile,
                                                        dest=dest)
        print(
            "Translated destination language is successfully changed to: %s" %
            user_lang_modified.get("dest"))
        return user_lang_modified

    # step1
    #     with open("../mongo_client_settings", "r", encoding="utf-8") as infile:
    #         mongo_client_settings = json.loads(infile.read())

    uri = mongo_client_settings.get("uri")
    port = mongo_client_settings.get("port")
    conn = MongoClient(uri, port=port)
    db = conn.translator
    collection = db.translator_users

    # step2
    user_profile = line_bot_api.get_profile(
        event.source.user_id).as_json_dict()
    userId = user_profile.get("userId")

    if event.message.text.find(
            "^to_") != -1:  # find("pattern")回傳值型態為 int, 若有這個字串,回傳0:沒有這個字串則回傳-1
        user_lang_modified = _changSettings()
        change_settings_msg = TextSendMessage(
            "The translated language is successfully changed to %s." %
            (event.message.text[4:]))
        line_bot_api.reply_message(event.reply_token, change_settings_msg)
    elif event.message.text.find("lang_list") != -1:
        lang_list_msg = TextSendMessage(str(lang_list))
        line_bot_api.reply_message(event.reply_token, lang_list_msg)
    else:
        # step3
        user_profile = _getUserTranslationSettings(
            user_profile)  # return the user_profile with "src" and "dest"

        dest = user_profile.get("dest")

        translated_text_send_message = TextSendMessage(
            translator.translate(event.message.text, dest=dest).text)

        line_bot_api.reply_message(event.reply_token,
                                   translated_text_send_message)
    except InvalidSignatureError:
        abort(400)

    return 'OK'


# handle FollowEvent
"""
1. Get user info and save it
2. Bind function UI to the user
3. Send "Welcome" messages to the user

"""

follow_message_list = [
    TextSendMessage("Welcome to MyTranslator bot."),
    TextSendMessage(
        "This bot would translate any language input to English by default."),
    TextSendMessage(
        "You can easily use the rich menu to change the translated language to English, Japanese or French."
    ),
    TextSendMessage(
        "Or you can type ^to_LANGUAGE format to change the translated language you want."
    ),
    TextSendMessage(
        "To see the available translated languages, type lang_list to get the information."
    )
]


@handler.add(FollowEvent)
Exemplo n.º 20
0
def yooka_template(event):
    a = event.message.text
    b = a.lower()
    if (b == "test"):
        line_bot_api.reply_message(event.reply_token, TextSendMessage(text=a))
    elif (b == "image carousel"):
        line_bot_api.reply_message(
            event.reply_token,
            TemplateSendMessage(
                alt_text='Image carousel template',
                template=ImageCarouselTemplate(columns=[
                    ImageCarouselColumn(image_url='https://example.com/'
                                        'item1.jpg',
                                        action=PostbackAction(
                                            label='postback1',
                                            data='action=buy&itemid=1')),
                    ImageCarouselColumn(image_url='https://example.com'
                                        '/item2.jpg',
                                        action=MessageAction(
                                            label='message2',
                                            text='message text2')),
                    ImageCarouselColumn(image_url='https://example.com/'
                                        'item3.jpg',
                                        action=URIAction(
                                            label='uri1',
                                            uri='https://example.com/1'))
                ])))
    elif (b == "lokasi unsada"):
        line_bot_api.reply_message(
            event.reply_token,
            LocationSendMessage(title='Universitas Darma Persada',
                                address='Jakarta Timur',
                                latitude=35.65910807942215,
                                longitude=139.70372892916203))
    elif (b == "konfirmasi"):
        line_bot_api.reply_message(
            event.reply_token,
            TemplateSendMessage(alt_text='Confirm template',
                                template=ConfirmTemplate(
                                    text='Are you sure?',
                                    actions=[
                                        PostbackAction(
                                            label='postback',
                                            text='postback text',
                                            data='action=buy&itemid=1'),
                                        MessageAction(label='message',
                                                      text='message text')
                                    ])))
    elif (b == "carousel"):
        line_bot_api.reply_message(
            event.reply_token,
            TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(columns=[
                    CarouselColumn(
                        thumbnail_image_url='https://example.com/item1.jpg',
                        title='this is menu1',
                        text='description1',
                        actions=[
                            PostbackAction(label='postback1',
                                           text='postback text1',
                                           data='action=buy&itemid=1'),
                            MessageAction(label='message1',
                                          text='message text1'),
                            URIAction(label='uri1', uri='http://example.com/1')
                        ]),
                    CarouselColumn(
                        thumbnail_image_url='https://example.com/item2.jpg',
                        title='this is menu2',
                        text='description2',
                        actions=[
                            PostbackAction(label='postback2',
                                           text='postback text2',
                                           data='action=buy&itemid=2'),
                            MessageAction(label='message2',
                                          text='message text2'),
                            URIAction(label='uri2', uri='http://example.com/2')
                        ])
                ])))
    elif (b == "siapa kamu"):
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text="Yooka"))
    elif (b == "question"):
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text="answer"))
    else:
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(
                text=
                "Wah, keliatannya aku kurang paham. Coba cek Quick Menu dibawah."
            ))
Exemplo n.º 21
0
 def on_enter_enter_number(self, event):
     message = TextSendMessage(text='Enter player number')
     line_bot_api.reply_message(event.reply_token, message)