以åã«ãåçªã«ãbotãã¤ããã¦ã¼ãã¨æ¸ããããã§ããã
- ï¼éå»è¨äºï¼botを作りたい - (旧姓)タケルンバ卿日記 2008-11-29
æ¨æ¥ãã®ã¼ã¯ãã¦ã¹2ã«ã¦ã以ä¸ã®ã¡ã³ãã¼ã¨åå¼·ä¼ãå®æ½ã
- ã¸ã ã¡ï¼pettan.jpï¼
- id:crystalineï¼Crystaline [クリスタライン]ï¼
- yteppeiï¼http://marke.seesaa.net/ï¼
æ§ã
ãªæ¹ã®ãååããæ¯æ´ããæå°ã®ãã¨ãä½ã¨ãå½¢ã«ãªãã¾ããããã¾ã ã¾ã æ¹åããç¹ã¯ããããbotã¨è¨ãåããªãé¨åããããã©ãã
ã©ãããæµãã§ä½ã£ãããè¨é²ã®ããã«ãæ®ãã¦ããããã¨æãã¾ãã
1.ã©ãããbotã«ããã決ãã
ã³ã³ã»ããã¯ãbotを作りたいãã§æ±ºãã¦ããéãã
botを作りたい - (旧姓)タケルンバ卿日記
botを作りたい - (旧姓)タケルンバ卿日記
- ã§ãããã¨ãªããçã§é£ãã¦ã¼ããç¼ãã¦é£ãã¦ã¼ããç ®ã¦é£ãã¦ã¼ããªããã®ã»ãªããæ¬æã«å ¥ããã
- ããã«ã§ãããã¨ãªããè¶ ã¬ã¢ã«ãã¡ã·ãããªãã¨ãé£ããããã¿ãããªèãã»ãªããåºç¾ãããããã«ããã
é£ã¹ãã®ã«é¢ããä¸è¨ã¨ãç»åã®URLã表示ãããæãã
æ¯è¼çã³ã³ã»ããã¯æ確ãå®æå½¢ã¯ããã£ã¦ããåé¡ã¯ããããå®ç¾ããããã»ã¹ãããããªãã£ããã¨ããã¹ã¦ã¯ããã ãªã
2.Twitterã®IDãåå¾ãã
次ã«ãbotã¨ãã¦çºè¨ãæ稿ãã主ä½ã確ä¿ãIDãã¨ãã
æåã¯ãTwitterãã ãã«ãitterããã¤ãæ¹ãããããªã¨ããquitterï¼é£ãã£ãã¼ï¼ãã¨ããååãèãã¦ããã®ã ããã©ãå
ç´ãããã
誰ã ããªãã¨ã
ããã§ãiããåã£ã¦ã¿ãã¨ããããã¾ãã¾ç©ºãIDã ãããqutterï¼é£ã£ãã¼ï¼ãã¨ãªã£ã¦åé¡ãªãæããªã®ã§åå¾ããã
3.Rubyãã¤ã³ã¹ãã¼ã«ãã
PHPã§ã¯æ¢ã«ãªã¬ã®ã¢ã¤ãã¢ãå®ç¾ããã¦ãã¾ã£ãã®ã§ãåãæ¹æ³ã¯é¿ãããã¨ããã©ãã§ãããæå°ãããã¦id:dominion525ãããããRubyã§ç°¡åã«ã§ãããï¼ãã¨ããã¢ããã¤ã¹ãããã ããã®ã§ãRubyã§ãã£ã¦ã¿ããã¨ã«ããã
æå§ãã«ãã¾ãã¯ããã°ã©ã ãã¤ã³ã¹ãã¼ã«ã
ãã¡ãã®èª¬æãèªã¿ã¤ã¤ã
ããã家ããã¤ã³ã¹ãã¼ã«ãçµæ§ã¤ã³ã¹ãã¼ã«ã«æéããããã
ã§ãã£ã¦å
¥ããã確èªãã³ãã³ãããã³ãããéããâ¦â¦ãããªã®ä½¿ãã®ãã¤ã¶ãã â¦â¦ãMS-DOSæ代以æ¥ããç¥ããã
ruby -v
ã¨å ¥ãã¦ãªã¿ã¼ã³ãããEnterãã¼ããªã¿ã¼ã³ã¨å¼ã¶ã®ã¯å¤ãä¸ä»£ã ãã許ãã
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
ã¨ãããã§ã¡ããã¨å ¥ã£ã¦ãããã¨ãããããrubyã®1.8.6ããã¡ãã¨å ¥ã£ã¦ã¾ããï¼
4.ãhello worldãã¨ã
æ¨æ¥ã®åå¼·ä¼ä»¥åã«ãã¡ãã£ã¨ã¯æµããç解ãã¦ãããã¨ãこれãèªã¿ã¤ã¤ããhello worldãã表示ãããããªãã ãããã¦ã¿ããã¾ãã¨ã«ãããã«ãã¡ã¢å¸³ã¨ãã§æã£ã¦ããããã.rbãã¨ãããã¡ã¤ã«åã§ä¿åãã¦ããããã³ãã³ãããã³ããã§èµ°ãããã°åãããã ãä¹±æ´ã ããããããç解ã
ä¸å¿ãããã¾ã§ã¯ãã£ã¦æ¨æ¥ã®åå¼·ä¼ã¨ãªãã
5.ãã¼ããã½ã³ã³æã£ã¦ãªã
åé¡ã¯ããããªã¬ã¯èªå®
ã§ãã¹ã¯ãããã§ä½æ¥ãã¨ãããã¼ããã½ã³ã³ããªãããµããã
ããããããã¨ã«ãæ¨æ¥ã¯ã®ã¼ã¯ãã¦ã¹2ã®ç·å¸¥ã§ããid:NA_geekã«ã空ãããã¼ããã½ã³ã³ããåããããã¨ãã§ããã®ã§ãããã§ä½æ¥ãããããããã¨ã ãããèªå®
ã§ããã®ã¨åæ§ã«ç°å¢ãæ´ããã
ã¾ãã§ãããã¯ä»å¾ã®å±éãèããã«ãä½ã¨ãããã¨ãªããéã¯ãããããã©ããã®ã¿ã¤ãã³ã°ã§1å°è²·ããã°ãªãã
6.端ç·ãå¾ã
ãããã«ãããæä½éã®ç解ããªãã¨ä½ãã§ããªããã¨ããããã§ãåå¼·ä¼ã§ãこれã®ç¶ããããããéæãããããã¨ããã£ããid:dominion525ãããへだちããã«èãã¨ããå½¢å¼ã§é²ããããã ãã©ããã£ã¦ãããã¡ã«ãããããã使ãã°ãããã§ãï¼ãã¨ããã²ããããå¾ãã
puts 'ããããã' sleep 1 r = rand(3) + 1 if r == 1 puts 'ã°ã¼' elsif r == 2 puts 'ãã§ã' elsif r == 3 puts 'ãã¼' endるびま
ãããå®è¡ããã¨ãæåã«ãããããããã¨è¡¨ç¤ºããã1ç§å¾ã«ãã°ã¼ã»ãã§ãã»ãã¼ãã®ããããã表示ãããããã®ããããã¨ã¯ãrand(3)+1ãå³ã¡ã0ãã2ãã¾ã§ã®æ°å¤ã«1ã足ãããã®ãã¤ã³ã¼ã«ã1ãã3ã1ãªãã°ã¼ã§ã2ãªããã§ãã3ã§ãã¼ãããããå¦çã§ããã¨ã
ã¨ãããã¨ã¯ã ããããå¿ç¨ããã°ãããã¤ãã®ã»ãªããããã©ã³ãã ã«ãããé¸ã°ãããã¨ã¯å¯è½ã ããã
7.ä¸å¿ãå¦å¥³ä½ãªã®ããªï¼
ããã§ãæ©éãããããã®ãæ¸ãã¦ã¿ãã
r = rand(7) + 1 if r == 1 puts 'ç ®ã¦é£ãã¦ã¼' elsif r == 2 puts 'ç¼ãã¦é£ãã¦ã¼' elsif r == 3 puts 'çã§é£ãã¦ã¼' elsif r == 4 puts 'æãã¦é£ãã¦ã¼' elsif r == 5 puts 'ãªãã¨ãæ±ãã¦ã¼' elsif r == 6 puts 'è¸ãã¦é£ãã¦ã¼' elsif r == 7 puts 'ãããè ¹ãã£ã±ãã ã¼' end
ãããå®è¡ããã¨ãããã«æãã7ã¤ã®ã»ãªããããã©ãããã©ã³ãã ã«é¸ãã§è¡¨ç¤ºããããrand(7)ãã®æ°å¤ãå¢ãããä¸ã«ä»ã足ãã°æ¡å¼µãã§ãããã¾ããã»ãªãã®å¾ãã«ãããã¨åãããURLãå ¥ããã°ãå½åèãã¦ãããã®ã«è¿ããã®ã¯ã§ããã
puts 'ç ®ã¦é£ãã¦ã¼ http://âââ'
ã¨ããã°ããããã ã
ã©ã³ãã ã§è¡¨ç¤ºããè¦ç´ ããå
¨é¨å
¥åã¨ãããããã¡ãã§ç¨æããªããã°ãªããããã ãããé常ã«åå§çã§ç¨æãªãã®ã ããã©ãåæ段éã¨ãã¦ã¯ããã§ããããããããããè¦ç´ ãåå¾ããæè¡ã¨ããããèªååãããã¨ã¯ã§ããã¯ãã ããæ¬æ¥ã¯ããããã®ãbotãªã®ã ããããã¨ããããã¯ããã¨ãããç¨æã ãããä½ã ããããã¾ãã¯å½¢ã«ããã°ãããå®éã«åãããã»ãã楽ãããããªã
8.ãã¹ãæå
ãã¨ã¯ã¨ããããbotã®ãã¼ã¹ã¨ãªããã®ã¯ã§ããããã¨ã¯ãããããã°ã©ã ã¨ãã¦æ示ããæ示ãããå®è¡ããç°å¢ãã¤ããã°ãããæ示ãããã¨ã©ã³ãã ã«ã»ãªããé¸ã³ããããTwitterã«æ稿ããæµããä½ãã°ããã
ãããå©ç¨ããã¦ããã ããã¨ã«ãããã使ãã¨APIã使ã£ã¦ãããã°ã©ã ããæ稿ãã¦ãããã£ã¦ãããã
ããããã¦ã³ãã¼ããããã°ã©ã ããµã¼ãã«ãï½ããç°å¢ã¨ããµã¼ãã«ãããããã°ã©ã ã«ã¢ã¯ã»ã¹ãã¦ãåããç°å¢ãæã«å
¥ããã
ã§ããã®éãæ¥æ¬èªã ã¨æååãããã¨ãããã¨ãªã®ã§ã
ã£ã¦ã®ãæãã¦ããããããã足ããè±èªãªãã¨ããããæ¥æ¬èªã ã¨è¡¨ç¤ºãã¢ã¬ã§ã³ã¬ã§ã½ã¬ããããããããããããã¨ã«ãããããã使ãã°æååãããªãã®ã ããããããã¨ãªã®ã ãããã§ããã®ã ã
ããã¾ã§çµãã¦ããã¹ããâ¦â¦æåï¼ããã¾ããã£ãæããã©ã³ãã ã§ç¨æããã»ãªããæ稿ããããåæãã¹ãã¨ãã¦ã¯ä¸ã
ãå¾ã¯ãã®ããªã¨ã¼ã·ã§ã³ãä»ã足ãã ããããã¦ãããèªå®
ã§ã§ããããã«ç°å¢ãæ´ããã ããã§ããæµãã¯ã¤ããããããæãã
ç¨ããæéã«ãªã£ãã®ã§ãã®ã¼ã¯ãã¦ã¹2ãåºããå¾ã¯èªå®
ã§ç¶ãã ã
9.é£ã£ãã¼ ver.1
帰å®
ããèªå®
PCã«å
¥ãã¦ãªããã¼ã«é¡ãå
¥ãã¾ãããåæé²è¡ã§ã»ãªããæ¸ãã¾ãããå¾ãã«ç»åã®URLã足ãã¾ãããæ´ç·´ãã®ãããããªãããæå¤ã¨å°éãªä½æ¥ã¯å¥½ããªã®ã§ãè¦ã«ãªãããããããã®ãä½ã£ã¦ãã¨ãã£ã¦æ¥½ãããã
ã§ãã¨ããããå®æãã¾ããã
ãã¡ãã§ç¨æããã»ãªããã©ã³ãã ã§æ稿ãã¾ãã
ãããªæããã»ãªãã®å¾ã«URLããããã¯ãªãã¯ããã¨ãã¿ã±ã«ã³ãã®ã¯ã¦ãªãã©ãã©ã¤ãããè¦ç¹ã£ããé¢é£ç»åã®ãã¼ã¸ã«é£ã¶ã¨ãã§ããããè¦ã人ãã¡ã空è
¹æã¨é£æ¬²ã«èº«æ¶ããã¨ãããããã·ã¹ãã ã«ãªã£ã¦ããã¾ããããããã£ãããã©ãã¼ãã¦ãã ããã¾ãã
10.ä»å¾ã®èª²é¡
æ稿ã¿ã¤ãã³ã°
æ稿ããã¿ã¤ãã³ã°ã¯èªåã§ã¯ãªãããã¡ãããæ示ããªãã¨ãã¡ã§ãããã¡ããèµ·åããªãã¨åããªããããããæå³ã§ã¯botã«ãªãããã¦ã¾ãããæåã§ãã人åããã
ãªã®ã§ãèªåã§ç¶ç¶çã«æ稿ããããã«ãããã§ãããæåã®ãã£ããã¯ãã¡ãã§é£ã°ãã¦ããã¨ãã¦ããå¾ã¯èªåçã«æ¢ããã¾ã§æ稿ããæµãã«ãããã
èãæ¹ã¨ãã¦ã¯ãwhile trueãã¨ãsleepãã§çµãã°ããã®ããªãã«ã¼ããããããä¸å®æéå¾ã«æ稿ããæµããã¤ããããsleep 3600ãã¨ãã«ããã°ããã¡ããæ¢ããã¾ã§ã¯1æéã«1åã«æ稿ããã¯ãããtimesãã§åæ°ãæå®ãã¦ããããªã
å°æ¥çã«ã¯ããããçµã¿åããã¦ãèªåçã«æ稿ãã¦ããããã«è¦ããããã«ãããã
æ稿æéãã©ã³ãã ã«
ã¤ãã§ã«è¨ãã¨ãçæ³ã¨ãã¦ã¯ãæ稿ã¨æ稿ã®éãã©ã³ãã ã«ãããããsleep 3600ãã¨ãã ã¨60åééã ãã©ããããã10åãã120åã®éã®ã©ãããã¿ããã«ããããªããã®æ¹ããªã¢ã«æãåºã¦ããã¨æãã
ãã®ãããã¯åå¼·ãã§ããããã«ãªã£ã¦ããã
ãªãã©ã¤ã«åå¿ããããã«ããã
åå¿ã§ããããã«ããããã
- ããã©ããªããªãã©ï¼ãã¡ã·é£ã£ããï¼ã
- ããªãã¨ãé£ãããï¼ã
- ããªã¬ãæ»ãã ãããªã¬ãé£ãï¼ããªã¬ã¯ãªãã¨ã®ä¸ã§çããï¼ã
- ãææ´é¨éã¯ãã¤æ¥ãï¼ï¼ãã¸ã£ã ããããã¯ã¾ã ãï¼ï¼ã
- ãããã«ã¯å¡©åã足ããªããã
ã¿ããã«æ¯ã¥ããããã
èªåã§éç¨ããã
ç¾ç¶ã¯おごちゃんã®ãåæã§ããµã¼ãã®ã¹ãã¼ã¹ããåããã¦ã¾ããç³ã訳ãªããæ¬å½ã«ãããã¨ããããã¾ãããä¸è©±ã«ãªãã¾ãã
ã¨ã¯ããããã¤ã¾ã§ãçãã¦ããããã«ããããªãã®ã§ãèªåã§ä½ã¨ããããã§ãããããã«ãã©ãçãã¾ã§ã®ãåæãªããã§ãä½ã¨ãèªåã§éç¨ã§ããããã«ãããããµã¼ãåãã¦ãä½ã¨ãã§ããããã«ãããã
çºè¨ã®ããªã¨ã¼ã·ã§ã³ãå¢ãããã
ã©ãã©ãå¢ãããããªãã©ã³ãã æ§ãããã ãã©ãããªã¨ã¼ã·ã§ã³ãå¢ãããããã¾ã ã¾ã å°ãªãã®ã§ãã
ã¯ã¦ãªãã©ãã©ã¤ãã¨ããTumblrã¨ãã¨çµã¿åããã¦ãããããã¨ã«ããæ¡å¼µããããªã
ã¨ã¾ããç¾ç¶ã¯ãããªã¨ãããä¸å®å
¨ã¨ã¯ãããä¸å¿ã¯åãåºãã¾ãããé£æ¬²åºæ¿botãqutterï¼é£ã£ãã¼ï¼ããæ¯éããããã
è¬æ
å¤ãã®çæ§ããå±ã¾ãã¨ãæ¯æ´ããæå°ãã¢ããã¤ã¹ãããã ãã¾ãããèª ã«ãããã¨ããããã¾ããã
çããã®ãããã§ãä½ã¨ãã§ãã¾ãããã¾ã ã¾ã ä¸ååã§ãããå°ããã¤è¯ããã¦ããããã¨æãã¾ãã
ä»å¾ã¨ããããããé¡ãç³ãä¸ãã¾ãã