-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
67 lines (49 loc) · 1.67 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once 'vendor/autoload.php';
use Stichoza\GoogleTranslate\GoogleTranslate;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$connection = new \Phergie\Irc\Connection();
$connection
->setServerHostname('irc.chat.twitch.tv')
->setServerPort(6667)
->setPassword($_ENV['TOKEN'])
->setNickname("#" . $_ENV['CHANNEL'])
->setUsername($_ENV['NAME']);
$client = new \Phergie\Irc\Client\React\Client();
$client->on('connect.after.each', function ($connection, $write) {
global $canal;
$write->ircJoin($canal);
$write->ircPrivmsg($canal, 'Gringinho Bot is ON | Gringinho Bot tá ON');
});
function traduzirPt($word) {
$tr = new GoogleTranslate();
$tr->setSource('pt');
$tr->setSource();
$tr->setTarget('en');
return $tr->translate($word);
}
function traduzirEn($word) {
$tr = new GoogleTranslate();
$tr->setSource('en');
$tr->setSource();
$tr->setTarget('pt');
return $tr->translate($word);
}
$client->on('irc.received', function ($message, $write, $connection, $logger) {
global $canal;
$command = explode(' ', $message['params']['text']);
if ($message['command'] == 'PRIVMSG') {
if($command[0] == '!traduzir') {
$word = str_replace('!traduzir', ' ', $message['params']['text']);
$traducao = traduzirPt($word);
$write->ircPrivmsg($canal, $traducao);
}
if($command[0] == '!translate') {
$word = str_replace('!translate', ' ', $message['params']['text']);
$traducao = traduzirEn($word);
$write->ircPrivmsg($canal, $traducao);
}
}
});
$client->run($connection);