mikutter で、クリック一発でイベント発行出来る方法無いかなぁと考えていたら、 mikutter-adventure を思い出したので、参照しながらボタンクリックでイベント発火の練習をしてみる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ミニマムにボタン表示とイベント発火を試したかっただけなので、 | |
# ちゃんとしたプラグイン形式にはしていない。 | |
# mikutter のコンソールにコピペして実行して試した。 | |
require File.join(CHIConfig::PLUGIN_PATH, "change_account", "interactive") | |
Plugin.create(:interactive_test) { | |
timeline(:home_timeline) << Message.new( | |
system: true, | |
message: "ボタン付きメッセージのテストでーす。", | |
confirm: {"Yes" => :Yes, "No" => :No}, | |
confirm_callback: lambda { |pushed_button| | |
timeline(:home_timeline) << Message.new( | |
system: true, | |
message: "「#{pushed_button.to_s}」ボタンが押されたよー!" | |
) | |
} | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ミニマムにボタン表示とイベント発火を試したかっただけなので、 | |
# ちゃんとしたプラグイン形式にはしていない。 | |
# mikutter のコンソールにコピペして実行して試した。 | |
require File.join(CHIConfig::PLUGIN_PATH, "change_account", "interactive") | |
Plugin.create(:interactive_test) { | |
timeline(:home_timeline) << Message.new( | |
system: true, | |
message: "ボタン付きメッセージのテストでーす。\n連想配列が渡せるみたい。", | |
confirm: { | |
"へー" => {label: "へー", value: "1123456"}, | |
"ふーん" => {label: "ふーん", value: "2234567"} | |
}, | |
confirm_callback: lambda { |pushed_button| | |
timeline(:home_timeline) << Message.new( | |
system: true, | |
message: "「#{pushed_button[:label]}」ボタンが押されたよー!\n値は「#{pushed_button[:value]}」みたい。" | |
) | |
} | |
) | |
} |
こんな感じでメッセージ内に表示されたボタンに応じたイベントを発行できるようだ。
多分コマンドでも代用できるけど、いちいち右クリックして選択とかしたくない・させたくない場合に使えそう。 (多用してボタンが並ぶとちょうどよいタイミングで画面がスクロールしてひどいことになったりしそうですが...)
タスク管理プラグイン作って、完了ボタンを押すとみくったーちゃんが褒めてくれる感じのプラグインなんてどうだろうか?
参考文献
mikutter-adventure/mikutter-adventure.rb at master · moguno/mikutter-adventure