「ver.2.0/応用/機能追加/ID別設定」の編集履歴(バックアップ)一覧はこちら
ver.2.0/応用/機能追加/ID別設定 - (2010/06/23 (水) 16:08:05) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
始める前に最低限''左メニューから読める設置手順すべて''を熟読しよう。&br;
&color(#ff0000){''※※注意※※&br;&size(24){PHPを一切勉強しない初心者は絶対にこの項目を行わないで下さい。};&br;ただ単にコピー&ペーストするだけでは何時まで経っても初心者のままです。一つ一つPHPを理解しよう!''};&br;
bot.phpやEasyBotter.phpを編集する上で、基本使いそうなPHP制御構造等は[[Twitter Bot関連リンク]]にお勧め解説サイトをリンクしています。
※wikiの編集が分からなくて、追加してほしい項目がある場合はページ下の「コメント」から誰かに頼んで下さい。
#contents
*特定のアカウントと会話(リプライ)させたくない [#o0aaf045]
EasyBotter.php内
//必要なつぶやきのみに絞る
function selectTweets($response){
$replies = array();
foreach($response as $reply){
//自分自身のつぶやきを除外する
$replyName = (string)$reply->user->screen_name;
if($this->_screen_name == $replyName){
continue;
}
//RT, QTを除外する
$text = (string)$reply->text;
if(strpos($text,"RT") != FALSE || strpos($text,"QT") != FALSE){
continue;
}
$replies[] = $reply;
}
return $replies;
}
を探す。
**botと名の付くアカウントを制限する [#n9e81b80]
if($this->_screen_name == $replyName){
を
//■■botを除外■■
if($this->_screen_name == $replyName || preg_match("@bot@i",$replyName)){
に変更する。
bot(大小文字関係なく)と名の付くアカウントに対してはリプライしなくなります。
**特定のアカウントを制限する [#v1124dd8]
if($this->_screen_name == $replyName){
を
//■■特定の人を除外■■
$bottername = array("abcd","efgh");
if($this->_screen_name == $replyName || in_array($replyName, $bottername)){
とすることで、abcdとefghという名のアカウントに対してリプライしなくなります。
botと入ってないアカウント名のBOTを指定したい場合に使用して下さい。
*特定のアカウントとの会話(リプライ)数を制限したい [#hcd8233e]
このサンプルは[[zkb_ot>http://kzkbot.blog9.fc2.com/blog-entry-8.html]]さんのソースを参考にしています。
EasyBotter.php内
//リプライを作る
(略)
$status = "";
//リプライパターンと照合
if(!empty($this->_replyPatternData[$replyPatternFile])){
を探す。
$status = "";
の直前に
//■■会話数制限(リプライ返し)■■
$filenameb = "kaiwalog.txt";//kaiwalog.txtに誰からリプライがあったか最新$botk1件記録する
//$filenamebは存在するか?
if(!file_exists($filenameb)){
touch($twit_logfile) or die('ファイル作成に失敗\n');
chmod($twit_logfile, 0606) or die('権限変更に失敗\n');//※パーミッションは鯖によって違います
}
$botdata = file_get_contents($filenameb);
$botdata2 = $botdata;
$countk = substr_count($botdata2,(string)$reply->user->screen_name);
$botdata = explode(",",$botdata);
$kazu = count($botdata);
$botkey = 1;
$botk1 = "10";$botk1--;//記録件数
$botk2 = "2";//回までOK
$bottername = array("abcd","efgh");//制限したいアカウント名をいれる
if(preg_match("@bot@i",(string)$reply->user->screen_name) || in_array((string)$reply->user->screen_name,$bottername)){
if ($countk>=$botk2){
$botkey = "0";
$botdata = implode(",",$botdata);
}else{
while ($kazu>$botk1){$botdatax = array_pop($botdata);$kazu = count($botdata);}
$botdata=implode(",",$botdata);
$botdata=(string)$reply->user->screen_name.",".$botdata;
}
}else{
while ($kazu>$botk1){$botdatax = array_pop($botdata);$kazu = count($botdata);}
$botdata=implode(",",$botdata);
$botdata=(string)$reply->user->screen_name.",".$botdata;
}
file_put_contents($filenameb,$botdata);
if($botkey == "0"){
continue;
}
を追記し、保存する。
空のkaiwalog.txtを作成し、EasyBotter.phpと共にサーバーへアップロードする。
kaiwalog.txtはログファイル用のパーミッションにする。
※作成しなくても自動作成するようにしてありますが、自分で作成してうpするのが確実
**備考 [#ldfe0701]
リプライをくれたアカウント名を最新10件記録します。
そのうち、bot(大小文字関係なく)と名の付くアカウントから3回目のリプライにはリプライ返ししません(2回まではリプライをする。)
abcdとefghという名のアカウントに対しても制限します。
↑botと入ってないアカウント名のBOTを指定したい場合に使用して下さい。
***毎日ログをリセットしたい [#y24beea8]
bot.php内
$eb = new EasyBotter();
の直後に
//■■リプライした人の記録リセット■■
if(date("H-i")=="00-00"){$fp = fopen("kaiwalog.txt", "w");fclose($fp);}
を入れてください。
0時0分にアクセスした時、ファイルを真っ白にしてから処理を行います。
*特定のアカウントに対しては、別のリプライパターンを読み込ませたい [#g6a99bfa]
EasyBotter.php内
//リプライを作る
function makeReplyTweets($replies, $replyFile, $replyPatternFile){
if(empty($this->_replyPatternData[$replyPatternFile]) && !empty($replyPatternFile)){
$this->_replyPatternData[$replyPatternFile] = $this->readPatternFile($replyPatternFile);
}
(略)
foreach($this->_replyPatternData[$replyPatternFile] as $pattern => $res){
1.
if(empty($this->_replyPatternData[$replyPatternFile]) && !empty($replyPatternFile)){
の直後に
$org_repfile = $replyPatternFile; //デフォルトのファイル名を保管
を追記する。
2.
>foreach($this->_replyPatternData[$replyPatternFile] as $pattern => $res){
の直前に
//■■特定の人には別パターン■■
$userName = (string)$reply->user->screen_name;
switch(true){
case stristr($userName, "bot")://botと名のつくアカウント名に対して
$replyPatternFile = "bot_pattern.php";//bot_pattern.phpを適用する
$this->_replyPatternData[$replyPatternFile] = $this->readPatternFile($replyPatternFile);
break;
case $userName == "abcd"://abcdというアカウント名に対して
case $userName == "efgh"://efghというアカウント名に対して
$replyPatternFile = "xxx_pattern.php";//xxx_pattern.phpを適用する
$this->_replyPatternData[$replyPatternFile] = $this->readPatternFile($replyPatternFile);
break;
default://それ以外
$replyPatternFile = $org_repfile; //デフォルトのパターンファイル名
}
または
//■■特定の人には別パターン■■
$userName = (string)$reply->user->screen_name;
if(stristr($userName, "bot")){//botと名のつくアカウント名に対して
$replyPatternFile = "bot_pattern.php";//bot_pattern.phpを適用する
$this->_replyPatternData[$replyPatternFile] = $this->readPatternFile($replyPatternFile);
}else if($userName == "abcd" || $userName == "efgh"){
$replyPatternFile = "xxx_pattern.php";//xxx_pattern.phpを適用する
$this->_replyPatternData[$replyPatternFile] = $this->readPatternFile($replyPatternFile);
}else{
$replyPatternFile = $org_repfile; //デフォルトのパターンファイル名
}
を追記する。
*特定のアカウントは自動フォローしない [#hd86ba2c]
EasyBotter.php内
foreach($followList as $screen_name){
$response = $this->followUser($screen_name);
}
を
foreach($followList as $screen_name){
//■■xxxはフォロー返ししない■■
if(!preg_match("@bot@i",$screen_name)){
$response = $this->followUser($screen_name);
}
}
と変更する。
例ではbotと名のつくアカウントすべて。
*コメント [#ub9d67da]
#comment
表示オプション
横に並べて表示:
変化行の前後のみ表示: