After seeing @ Nemesis's implementation of Yubaba in Java, you might want to enter your name and play with Yubaba. ?? I thought it was a bot. You can add bot friends from the ** QR code below **. Please play with it.
I would like to inform the world that such a thing is popular in the engineer area, so please take a look at LGMT.
The language used was Python. It's a "" contract. Write your name there. It was a little annoying that a request from the user was required to activate "", but it was annoying, so I tried to respond by saying "** work **".
Basically, please play only in the part where the characters are cut.
main.py
from flask import Flask, request, abort
import random
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage)
import os
app = Flask(__name__)
YOUR_CHANNEL_ACCESS_TOKEN = 'XXXXXXXXXXX'
YOUR_CHANNEL_SECRET = 'XXXXXXXXXXX'
line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(YOUR_CHANNEL_SECRET)
@app.route("/callback", methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
word = event.message.text
if 'Let me work' in word:
reply_word = "It's a contract. Write your name there."
else:
newName = random.choice(word)
reply_word = f"Hung.{word}I mean. It's a luxurious name. From now on your name is{newName}It is. Mind you,{newName}That's right. I'll reply when I understand{newName}!!"
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=reply_word))
if __name__ == "__main__":
port = int(os.getenv("PORT", 5000))
app.run(host="0.0.0.0", port=port)
It cuts out nicely.
** Please forgive me for not being able to throw the usual error because I can't send an empty string. ** **
It is a mystery why one-character cutting is popular. I want to randomly cut out the number of characters.
LINE bot is too convenient, so I want to know more features.
that's all.
Recommended Posts