예제 #1
0
def process_single_line(commands: list):
    """單行查詢
    Args:
        commands: 包含查詢內容的列表
    """
    user_guide = TemplateSendMessage(
        alt_text='''電腦版無法顯示按紐,按鈕功能只是舉例,實際使用上請自行替換
                查群規: 貓 群規
                查名字: 貓 小貓貓
                查遊戲維基網址: 貓 光炮
                查遊戲內物品資料: 貓 光炮 21''',
        template=ButtonsTemplate(
            text='簡單功能介紹',
            actions=[
                MessageAction(label='查群規', text='貓 群規'),
                MessageAction(label='查名字', text='貓 小貓貓'),
                MessageAction(label='查遊戲內物品資料', text='貓 光炮 21'),
                MessageAction(label='查一段等級之間經驗',
                              text='貓 計算經驗\n光炮 1 0 21\n守衛 3 20 21')
            ]
        )
    )

    if len(commands) == 1:
        if commands[0] == '群規':
            return database.get_rules()
        if commands[0] == '執法者':
            return database.group_data['admin']
        if commands[0] == '使用說明':
            return user_guide
        try:
            name = database.correct(commands[0])
        except ValueError:
            name = commands[0]
        return generate_url(name)

    if commands[0] == '群規':
        try:
            return database.get_rules(int(commands[1]))
        except ValueError as error:
            print(error)
        return ''

    if commands[1] == '圖片':
        try:
            name = database.correct(commands[0])
        except ValueError:
            pass
        if database.item_data[name]['type'] != 'node':
            return database.get_picture(name, 0)

    try:
        name = database.correct(commands[0])
        level = int(commands[1])
        database.verify_input(name, level, level)
    except ValueError as error:
        pass
    else:
        return database.item_data[name]['data'][level]['data_string']
    return ''
예제 #2
0
def detect_json(fileName):
    #開啟檔案,轉成json
    with open(fileName, encoding='utf-8') as f:
        jsonArray = json.load(f)

    # 解析json
    returnArray = []
    for jsonObject in jsonArray:

        # 讀取其用來判斷的元件
        message_type = jsonObject.get('type')
        # 轉換
        if message_type == 'text':
            returnArray.append(TextSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'imagemap':
            returnArray.append(
                ImagemapSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'template':
            returnArray.append(
                TemplateSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'image':
            returnArray.append(ImageSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'sticker':
            returnArray.append(
                StickerSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'audio':
            returnArray.append(AudioSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'location':
            returnArray.append(
                LocationSendMessage.new_from_json_dict(jsonObject))

    # 回傳
    return returnArray
예제 #3
0
    def create_carousel(cls, offset: int = 0):
        news_list = cls.get_news_list(offset=offset)
        carousel_list = [
            CarouselColumn(thumbnail_image_url=news_list[r]["url_screen_shot"],
                           title=news_list[r]["title"],
                           text=news_list[r]["day"],
                           actions=[
                               MessageTemplateAction(label="画像を見る",
                                                     text="宮大" +
                                                     str(offset + r + 1)),
                               URITemplateAction(label="URLを開く",
                                                 uri=news_list[r]["url_news"])
                           ]) for r in range(4)
        ]

        column_text = str(offset + 1) + "〜" + str(offset + 4) + "ページです"
        carousel_list.append(
            CarouselColumn(
                thumbnail_image_url=
                "https://www.kuaskmenkyo.necps.jp/miyazaki/UnivImages/宮崎大学画像.jpg",
                title="宮大支援課お知らせBot",
                text=column_text,
                actions=[
                    MessageTemplateAction(label='次のページ',
                                          text='過去宮大' + str(offset + 4)),
                    URITemplateAction(
                        label='支援課のサイトはこちら♪',
                        uri='http://gakumu.of.miyazaki-u.ac.jp/gakumu/')
                ]))
        send_carousel = TemplateSendMessage(
            alt_text="宮大お知らせ",
            template=CarouselTemplate(columns=carousel_list))
        return send_carousel
예제 #4
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_success_player(self, event):
     message = TemplateSendMessage(alt_text='Buttons template',
                                   template=ButtonsTemplate(
                                       text='Success',
                                       actions=[
                                           MessageAction(label='check',
                                                         text='check'),
                                       ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #5
0
 def story_board(self, text):
     return {
         'menu':
         TemplateSendMessage(
             alt_text='ButtonsTemplate',
             template=ButtonsTemplate(
                 title='ごみ出しメニュー',
                 text=text if text else '選択して下さい',
                 actions=[
                     PostbackAction(label='今日のごみ出し',
                                    data=json.dumps({
                                        'model': 'trash',
                                        'scene': 'result',
                                        'process': {
                                            'handle':
                                            'what_day_of_garbage_is_today'
                                        }
                                    })),
                     PostbackAction(label='戻る',
                                    data=json.dumps({
                                        'model': 'main_menu',
                                        'scene': 'menu'
                                    }))
                 ])),
         'result':
         TemplateSendMessage(alt_text='ButtonsTemplate',
                             template=ButtonsTemplate(
                                 title='ごみ出しメニュー',
                                 text=text if text else '取得できませんでした',
                                 actions=[
                                     PostbackAction(label='戻る',
                                                    data=json.dumps({
                                                        'model':
                                                        'trash',
                                                        'scene':
                                                        'menu'
                                                    }))
                                 ]))
     }
예제 #6
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_Rebound(self, event):
     #message = TextSendMessage(text='Enter player number')
     #line_bot_api.reply_message(event.reply_token, message)
     message = TemplateSendMessage(alt_text='Confirm template',
                                   template=ConfirmTemplate(
                                       text='選擇籃板種類',
                                       actions=[
                                           MessageAction(label='進攻籃板',
                                                         text='orebound'),
                                           MessageAction(label='防守籃板',
                                                         text='drebound'),
                                       ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #7
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_freept(self, event):
     #message = TextSendMessage(text='Enter player number')
     #line_bot_api.reply_message(event.reply_token, message)
     message = TemplateSendMessage(alt_text='Confirm template',
                                   template=ConfirmTemplate(
                                       text='選擇是否命中',
                                       actions=[
                                           MessageAction(label='命中',
                                                         text='freeptmade'),
                                           MessageAction(label='未命中',
                                                         text='freeptmiss'),
                                       ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #8
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_enter_player(self, event):
     #message = TextSendMessage(text='Enter player number')
     #line_bot_api.reply_message(event.reply_token, message)
     message = TemplateSendMessage(alt_text='Buttons template',
                                   template=ButtonsTemplate(
                                       title='安安你好',
                                       text='Please select',
                                       actions=[
                                           MessageAction(label='增加球員',
                                                         text='add_player'),
                                           MessageAction(label='開始比賽',
                                                         text='game'),
                                       ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #9
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_statistic(self, event):
     #message = TextSendMessage(text='Enter player number')
     #line_bot_api.reply_message(event.reply_token, message)
     message = TemplateSendMessage(alt_text='Buttons template',
                                   template=ButtonsTemplate(
                                       title='安安你好',
                                       text='Please select',
                                       actions=[
                                           MessageAction(label='兩分球出手',
                                                         text='twopt'),
                                           MessageAction(label='三分球出手',
                                                         text='threept'),
                                           MessageAction(label='罰球出手',
                                                         text='freept'),
                                           MessageAction(label='籃板球',
                                                         text='rebound'),
                                       ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #10
0
 def story_board(self, text):
     return {
         'menu':
         TemplateSendMessage(alt_text='ButtonsTemplate',
                             template=ButtonsTemplate(
                                 title='勤怠メニュー',
                                 text=text if text else '選択して下さい',
                                 actions=[
                                     URIAction(uri='line://app/<LIFF URL>',
                                               label='勤怠入力'),
                                     PostbackAction(label='戻る',
                                                    data=json.dumps({
                                                        'model':
                                                        'main_menu',
                                                        'scene':
                                                        'menu'
                                                    }))
                                 ]))
     }
예제 #11
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_freeptmiss(self, event):
     now = 0
     for i in range(len(player_num)):
         if player_num[i].number == CurrentPlayer[len(CurrentPlayer) -
                                                  1].number:
             player_num[i].free_miss += 1
             now = i
     print("Number %d miss free %d times" %
           (CurrentPlayer[len(CurrentPlayer) - 1].number,
            player_num[now].free_miss))
     message = TemplateSendMessage(
         alt_text='Buttons template',
         template=ButtonsTemplate(
             text="No.%d miss %d 1pt" %
             (CurrentPlayer[len(CurrentPlayer) - 1].number,
              player_num[now].free_miss),
             actions=[
                 MessageAction(label='check', text='check'),
             ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #12
0
파일: fsm.py 프로젝트: F74061080/basketball
 def on_enter_DRebound(self, event):
     now = 0
     for i in range(len(player_num)):
         if player_num[i].number == CurrentPlayer[len(CurrentPlayer) -
                                                  1].number:
             player_num[i].DRebound += 1
             print(player_num[i].DRebound)
             now = i
     print("Number %d made one %d times" %
           (CurrentPlayer[len(CurrentPlayer) - 1].number,
            player_num[now].DRebound))
     message = TemplateSendMessage(
         alt_text='Buttons template',
         template=ButtonsTemplate(
             text="No.%d made %d DReb" %
             (CurrentPlayer[len(CurrentPlayer) - 1].number,
              player_num[now].DRebound),
             actions=[
                 MessageAction(label='check', text='check'),
             ]))
     line_bot_api.reply_message(event.reply_token, message)
예제 #13
0
 def story_board(self, text):
     return {
         'menu':
         TemplateSendMessage(alt_text='ButtonsTemplate',
                             template=ButtonsTemplate(
                                 title='メインメニュー',
                                 text=text if text else '選択して下さい',
                                 actions=[
                                     PostbackAction(label='勤怠メニュー',
                                                    data=json.dumps({
                                                        'model':
                                                        'clock_in',
                                                        'scene':
                                                        'menu'
                                                    })),
                                     PostbackAction(label='ごみ出しメニュー',
                                                    data=json.dumps({
                                                        'model':
                                                        'trash',
                                                        'scene':
                                                        'menu'
                                                    })),
                                     PostbackAction(label='(工事中)クーポンメニュー',
                                                    data=json.dumps({
                                                        'model':
                                                        'coupon',
                                                        'scene':
                                                        'menu'
                                                    })),
                                     PostbackAction(label='(工事中)自然言語メニュー',
                                                    data=json.dumps({
                                                        'model':
                                                        'talk',
                                                        'scene':
                                                        'menu'
                                                    }))
                                 ]))
     }
예제 #14
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."
            ))