• 05-02-2014, 00:46:46
    #10
    teamturker adlı üyeden alıntı: mesajı görüntüle
    Her ne kodlarsanız kodlayın algoritmayı kafanızda oluşturmadan hiç bir işe başlayamıyorsunuz başlasanızda zaten ortasında tıkanıp kalıyorsunuz ayrıca ajax veya javascript kullanamıyorum çünki bunu yapmak istediğim yer bir mobil chat sistemi malum günümüzde hala javascript desteklemeyen cihaz kullanıcıları mevcut hemde azımsanmıyacak kadar o yüzden sadece php kullanmak durumundayım
    salt php ile yapamazsın. irc kendi tcp-ip protokolüne sahiptir.
    php http protokolüne tabidir.
    istediğin algoritmada kullanıcı talebi olmadan sunucu istemci yönlü iletişim lazım.
    php ile ajax olmadan yeni soru soramazsın. kullanıcının sürekli sayfa yenilemesi gerekir. javascript ajax olmadan bu istediklerinin yapılabilmesi mümkün değil.
    onun dışında basit bir test sistemi istiyorsun aslında. veritabanına sorularını yanıtlarını sürelerini ekleyeceksin. Sonra bağlı olanların karşısına veritabanından bu soruları getireceksin, doğru yanıt vereni database e yazacaksın puan olarak.
    kalanı senin yapay zeka kurguna kalmış, doğru yanıt gelmediğinde bot ne diyecek, hızlı yanıt geldiğinde ne diyecek, son anda yanıt gelirse bot ne tepki verecek bunlarla ilgili kayıtlar oluşturacaksın.
    bu yazmak istediğin sistem eğer anlattığın gibi cevap olacaksa botun veritabanında hazır mesajları olacak, bu mesajların hangi koşullarda çıkacağıyla ilgili koşullar üreteceksin yanıtları da üyeleri de puanları da veritabanına yazacaksın..

    üstün bir algoritma gerekmiyor sanırım.
  • 05-02-2014, 13:53:41
    #11
    digiklan adlı üyeden alıntı: mesajı görüntüle
    salt php ile yapamazsın. irc kendi tcp-ip protokolüne sahiptir.
    php http protokolüne tabidir.
    Bu tam olarak doğru sayılmaz. PHP de diğer pek çok dil gibi bir web sunucusu ve CGI vasıtası ile istek-cevap modelinde dinamik sayfalar oluşturulurken kullanılabilir. Ancak bu PHP'nin sadece HTTP ptokolüne bağımlı olduğu anlamına gelmez. Zira HTTP veya TCP/IP bir dile ait olan protokoller değildirler.

    teamturker adlı üyeden alıntı: mesajı görüntüle
    mantığını bir oturtsam kodlar dökülüp gelecek lakin bir türlü mantığını oturtamadım.
    Aşağıda hızlıca hazırladığım bir soru botu sınıfı var. Sizin için önemli olan kısmının IRC ile bağlantıyı kurmak ve soru botunun temel sınıflarını yazmak olduğunu farz ederek, soru botunu 'irc.freenode.net' üzerinde çalışacak şekilde yazdım ancak genel anlamda geçerli olsa da bu konuda herhangi bir standart olacağı kesin değildir. Standart olmayan sunucularda çalıştırmanız için bazı ayarlamalar yapmanız gerekebilir. Ve tabii ki tam teçhizatlı bir soru botu değil. Geri kalan algoritmaları kendiniz belirleyip kodlarınızı yazmalısınız.

    <?
    class Bot
    {
      private $questionsPool;
      private $host;
      private $port;
      private $channel;
      private $nickname;
      private $socket;
      private $currentQuestion;
    
      public function __construct($questionsPool, $host = 'irc.freenode.net', $port = '6667', $channel = '#oyun', $nickname = 'phpsorubotu')
      {
        $this->questionsPool = $questionsPool;
        $this->host = $host;
        $this->port = $port;
        $this->channel = $channel;
        $this->nickname = $nickname;
        set_time_limit(0);
      }
    
      public function connect()
      {
        $this->socket = @fsockopen($this->host, $this->port, $errno, $errstr, 2);
    
        if($this->socket)
        {
          $this->execute('PASS NOPASS' . PHP_EOL);
          $this->execute('NICK ' . $this->nickname . PHP_EOL);
          $this->execute('USER ' . $this->nickname . ' USING PHP BOT' . PHP_EOL);
    
          while(!feof($this->socket))
            $this->read(fgets($this->socket, 1024));
        }
      }
    
      private function read($line)
      {
        echo "[READ] " . $line;
    
        if(strpos($line, "End of /MOTD command"))
          $this->execute('JOIN ' . $this->channel . PHP_EOL);
        elseif(strpos($line, "#oyun :End of /NAMES list"))
          $this->onJoin();
        elseif(substr($line, 0, 6) == "PING :")
          $this->execute('PONG :' . substr($line, 6) . PHP_EOL);
        else
          $this->tryResponse($line);
    
      }
    
      private function onJoin()
      {
        $this->say('Merhaba ');
        $this->pickNewQuestion();
      }
    
      public function say($message)
      {
        $this->execute('PRIVMSG ' . $this->channel . ' :' . $message . "\r\n");
      }
    
      public function ask()
      {
        $this->execute('PRIVMSG ' . $this->channel . ' :' . $this->currentQuestion->getQuestionClause() . "\r\n");
      }
    
      public function tryResponse($line)
      {
        if(strpos($line, '!soru'))
          $this->ask();
        else
          $this->tryAnswer($line);
      }
    
      private function tryAnswer($line)
      {
        if(!$this->currentQuestion)
          return;
    
        if($this->currentQuestion->isValidAnswerIn($line))
        {
          $this->say('Tebrikler');
          $this->pickNewQuestion();
        }
      }
    
      private function pickNewQuestion()
      {
        $this->currentQuestion = $this->questionsPool->getOne();
        $this->ask();
      }
    
      private function execute($command)
      {
        echo "[EXEC] $command";
    
        @fwrite($this->socket, $command, strlen($command));
        flush();
      }
    }
    
    class QuestionsPool
    {
      private $pool = array();
    
      public function register($question)
      {
        array_push($this->pool, $question);
      }
    
      public function getOne()
      {
        return $this->pool[array_rand($this->pool)];
      }
    }
    
    class Question
    {
      private $question_clause;
      private $answer;
    
      public function __construct($question_clause, $answer)
      {
        $this->question_clause = $question_clause;
        $this->answer = $answer;
      }
    
      public function getQuestionClause()
      {
        return $this->question_clause;
      }
    
      public function getAnswer()
      {
        return $this->answer;
      }
    
      public function isValidAnswerIn($line)
      {
        return strpos(strtolower($line), strtolower($this->answer)) !== FALSE;
      }
    }
    
    $questions_pool = new QuestionsPool();
    $questions_pool->register(new Question('2 + 2', '4'));
    $questions_pool->register(new Question('Dünyanın en yüksek noktası neresidir?', 'Everest'));
    
    $bot = new Bot($questions_pool);
    $bot->connect();
    ?>
    [EXEC] PASS NOPASS
    [EXEC] NICK phpsorubotu
    [EXEC] USER phpsorubotu USING PHP BOT
    [READ] :hitchcock.freenode.net NOTICE * :*** Looking up your hostname...
    [READ] :hitchcock.freenode.net NOTICE * :*** Checking Ident
    [READ] :hitchcock.freenode.net NOTICE * :*** Couldn't look up your hostname
    [READ] :hitchcock.freenode.net NOTICE * :*** No Ident response
    [READ] :hitchcock.freenode.net 001 phpsorubotu :Welcome to the freenode Internet Relay Chat Network phpsorubotu
    [READ] :hitchcock.freenode.net 002 phpsorubotu :Your host is hitchcock.freenode.net[93.152.160.101/6667], running version ircd-seven-1.1.3
    [READ] :hitchcock.freenode.net 003 phpsorubotu :This server was created Mon Dec 31 2012 at 23:37:41 EET
    [READ] :hitchcock.freenode.net 004 phpsorubotu hitchcock.freenode.net ircd-seven-1.1.3 DOQRSZaghilopswz CFILMPQSbcefgijklmnopqrstvz bkloveqjfI
    [READ] :hitchcock.freenode.net 005 phpsorubotu CHANTYPES=# EXCEPTS INVEX CHANMODES=eIbq,k,flj,CFLMPQScgimnprstz CHANLIMIT=#:120 PREFIX=(ov)@+ MAXLIST=bqeI:100 MODES=4 NETWORK=freenode KNOCK STATUSMSG=@+ CALLERID=g :are supported by this server
    [READ] :hitchcock.freenode.net 005 phpsorubotu CASEMAPPING=rfc1459 CHARSET=ascii NICKLEN=16 CHANNELLEN=50 TOPICLEN=390 ETRACE CPRIVMSG CNOTICE DEAF=D MONITOR=100 FNC TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:4,NOTICE:4,ACCEPT:,MONITOR: :are supported by this server
    [READ] :hitchcock.freenode.net 005 phpsorubotu EXTBAN=$,arxz WHOX CLIENTVER=3.0 SAFELIST ELIST=CTU :are supported by this server
    [READ] :hitchcock.freenode.net 251 phpsorubotu :There are 203 users and 85980 invisible on 26 servers
    [READ] :hitchcock.freenode.net 252 phpsorubotu 32 :IRC Operators online
    [READ] :hitchcock.freenode.net 253 phpsorubotu 5 :unknown connection(s)
    [READ] :hitchcock.freenode.net 254 phpsorubotu 43376 :channels formed
    [READ] :hitchcock.freenode.net 255 phpsorubotu :I have 839 clients and 1 servers
    [READ] :hitchcock.freenode.net 265 phpsorubotu 839 9804 :Current local users 839, max 9804
    [READ] :hitchcock.freenode.net 266 phpsorubotu 86183 98963 :Current global users 86183, max 98963
    [READ] :hitchcock.freenode.net 250 phpsorubotu :Highest connection count: 9805 (9804 clients) (1206165 connections received)
    [READ] :hitchcock.freenode.net 375 phpsorubotu :- hitchcock.freenode.net Message of the Day - 
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Welcome to hitchcock.freenode.net in Sofia, Bulgaria, EU, kindly sponsored by
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- OnlineDirect (http://onlinedirect.bg).
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- HITCHCOCK, SIR ALFRED [1899 - 1980] Born in Essex,
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- England, Sir Alfred Hitchcock was a noted film director
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- and producer. Over a long career he pioneered many modern
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- techniques in film-making, made more than 50 feature films,
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- and influenced many present-day directors and producers.
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Welcome to freenode - supporting the free and open source
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- software communities since 1998.
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- By connecting to freenode you indicate that you have read and
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- agree to adhere to our policies and procedures as per the
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- website (http://freenode.net/).
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- We would like to remind you that unauthorised public logging
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- of channels on the network is prohibited. Public channel
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- logging should only take place where the channel owner(s) has
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- requested this and users of the channel are all made aware
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- (if you are publically logging your channel, you may wish to 
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- keep a notice in the topic and perhaps as an on-join message).
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- freenode runs an open proxy scanner. For details on freenode 
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- network policy, please take a look at our policy page 
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- (http://freenode.net/policy.shtml).  Your use of the network
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- indicates your acceptance of this policy.
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Please join #freenode for any network-related questions or
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- queries, there are numerous freenode volunteers and helpful
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- users who would be happy to try answer any questions you might
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- have.
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Check out www.fossevents.org to find out what is happening in
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- your area, join us at FOSSCON (www.fosscon.org) for talks and
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- real-life collaboration or bring a picnic and come join
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- like-minded geeks for a geeknic (www.geeknic.org) somewhere
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- close to you. 
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Lastly, massive thanks to the OSU Open Source Lab
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- (http://osuosl.org/) and Private Internet Access
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- (https://www.privateinternetaccess.com/) for their sustained,
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- long term support and dedication they show to the FOSS
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- communities.
    [READ] :hitchcock.freenode.net 372 phpsorubotu :-  
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- ***************************************************************
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- Please read http://blog.freenode.net/2010/11/be-safe-out-there/
    [READ] :hitchcock.freenode.net 372 phpsorubotu :- ***************************************************************
    [READ] :hitchcock.freenode.net 376 phpsorubotu :End of /MOTD command.
    [EXEC] JOIN #oyun
    [READ] :phpsorubotu MODE phpsorubotu :+i
    [READ] :NickServ!NickServ@services. NOTICE phpsorubotu :phpsorubotu is not a registered nickname.
    [READ] :phpsorubotu!~phpsorubo@***.***.***.*** JOIN #oyun
    [READ] :hitchcock.freenode.net 353 phpsorubotu = #oyun :phpsorubotu PsiCat
    [READ] :hitchcock.freenode.net 366 phpsorubotu #oyun :End of /NAMES list.
    [EXEC] PRIVMSG #oyun :Merhaba 
    [EXEC] PRIVMSG #oyun :Dünyanın en yüksek noktası neresidir?
    [READ] :PsiCat!~PsiCat@***.***.***.*** PRIVMSG #oyun :!soru
    [EXEC] PRIVMSG #oyun :Dünyanın en yüksek noktası neresidir?
    [READ] :PsiCat!~PsiCat@***.***.***.*** PRIVMSG #oyun :everest
    [EXEC] PRIVMSG #oyun :Tebrikler
    * phpsorubotu (~phpsorubo@***.***.***.***) has joined #oyun
    <phpsorubotu> Merhaba 
    <phpsorubotu> Dünyanın en yüksek noktası neresidir?
    <PsiCat> !soru
    <phpsorubotu> Dünyanın en yüksek noktası neresidir?
    <PsiCat> everest
    <phpsorubotu> Tebrikler