E
E
E6APB2017-07-30 19:25:54
Bots
E6APB, 2017-07-30 19:25:54

Is it okay to develop bots this way?

I have a simple bot. Question answer. No contexts, sessions, etc. My code looks something like this:

<?php

if ($query === 'привет') {
    echo 'Привет';
} elseif ($query === 'фыввфывфв') {
    echo 'Ага';
} elseif (preg_match('//', $query) {
    echo 'Ясно';
} else {
    echo 'Я не понял тебя';
}

Isn't this shitcode?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lee Masagos, 2017-07-30
@E6APB

It's better to store words in the same json + one class that will process all this and give the result
.

X
xmoonlight, 2017-07-30
@xmoonlight

1. See switch-case
2. Use recursive descent through the branches of the best matches to issue (display / echo) the desired answer options.
I advise you to try the comparison through the Stumper API .
By the highest percentage of coincidence with the phrases you have - give the desired answer.

P
Pavel Kornilov, 2017-07-30
@KorniloFF

Of course, GC.
You should at least use regular expressions, because 'Hello' !== 'hello!'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question