Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e81324845 | |||
cc7b34f64d | |||
2dcf4adc33 |
@@ -5,15 +5,21 @@ declare(strict_types=1);
|
|||||||
namespace mirzaev\marina\controllers;
|
namespace mirzaev\marina\controllers;
|
||||||
|
|
||||||
// Файлы проекта
|
// Файлы проекта
|
||||||
use mirzaev\marina\controllers\core;
|
use mirzaev\marina\controllers\core,
|
||||||
|
mirzaev\marina\controllers\traits\converters;
|
||||||
|
|
||||||
// Discord framework
|
// Discord framework
|
||||||
use Discord\Discord as discord,
|
use Discord\Discord as discord,
|
||||||
Discord\Parts\Channel\Message as message,
|
Discord\Parts\Channel\Message as message,
|
||||||
Discord\Parts\Guild\Role as role,
|
Discord\Parts\Guild\Role as role,
|
||||||
|
Discord\Parts\Guild\CommandPermissions as permissions,
|
||||||
Discord\Parts\User\Member as member,
|
Discord\Parts\User\Member as member,
|
||||||
|
Discord\Parts\Interactions\Interaction as interaction,
|
||||||
Discord\WebSockets\Event as event,
|
Discord\WebSockets\Event as event,
|
||||||
Discord\Builders\MessageBuilder as _message;
|
Discord\Parts\Interactions\Command\Command as command,
|
||||||
|
Discord\Builders\MessageBuilder as _message,
|
||||||
|
Discord\Builders\CommandBuilder as _command,
|
||||||
|
Discord\Parts\Interactions\Command\Option as option;
|
||||||
|
|
||||||
// Встроенные библиотеки
|
// Встроенные библиотеки
|
||||||
use exception;
|
use exception;
|
||||||
@@ -26,6 +32,10 @@ use exception;
|
|||||||
*/
|
*/
|
||||||
final class index extends core
|
final class index extends core
|
||||||
{
|
{
|
||||||
|
use converters {
|
||||||
|
utf8_to_extended_ascii as protected ascii;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Главная страница
|
* Главная страница
|
||||||
*
|
*
|
||||||
@@ -39,22 +49,50 @@ final class index extends core
|
|||||||
// Запись в буфер вывода (терминал)
|
// Запись в буфер вывода (терминал)
|
||||||
echo "Marina is ready!", PHP_EOL;
|
echo "Marina is ready!", PHP_EOL;
|
||||||
|
|
||||||
// Сообщение: "марина"
|
// Сообщение: создано
|
||||||
$discord->on(event::MESSAGE_CREATE, function (message $message, discord $discord) {
|
$discord->on(event::MESSAGE_CREATE, function (message $message, discord $discord) {
|
||||||
if ($message->author->bot) {
|
// Игнорирование чат-роботов
|
||||||
// Do nothing
|
if ($message->author->bot) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Запись в буфер вывода (терминал)
|
// Запись в буфер вывода (терминал)
|
||||||
echo "{$message->author->username}: {$message->content}", PHP_EOL;
|
echo "{$message->author->username}: {$message->content}", PHP_EOL;
|
||||||
|
|
||||||
if (mb_stristr($message->content, 'марина') !== false) {
|
if ($message->author->id === '490821645028687873' || mb_stristr($message->content, 'мимк') !== false) {
|
||||||
$message->reply(_message::new()->setContent('ЗДАРОВА'));
|
// Сообщение от Дмитрия Демина (мимк) (vladimirbaryshkin) или содержит его псевдоним
|
||||||
|
|
||||||
|
// Добавление реакции на его сообщение
|
||||||
|
$message->react('😬');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (explode(' ', $message->content) as $word) {
|
||||||
|
// Перебор слов из текста сообщения
|
||||||
|
|
||||||
|
// Инициализация буфера символов для конвертации: UTF-8 -> ASCII+
|
||||||
|
$buffer = [];
|
||||||
|
|
||||||
|
// Конвертация проверяемых слов
|
||||||
|
$marina = self::ascii('марина', $buffer);
|
||||||
|
$marishka = self::ascii('маришка', $buffer);
|
||||||
|
$marinochka = self::ascii('мариночка', $buffer);
|
||||||
|
$marinushka = self::ascii('маринушка', $buffer);
|
||||||
|
$marya = self::ascii('маря', $buffer);
|
||||||
|
|
||||||
|
// Конвертация слова
|
||||||
|
$_word = self::ascii(mb_strtolower($word), $buffer);
|
||||||
|
|
||||||
|
if (
|
||||||
|
levenshtein($_word, $marina, 2, 2, 1) < 3
|
||||||
|
|| levenshtein($_word, $marishka, 2, 1, 2) < 4
|
||||||
|
|| levenshtein($_word, $marinochka, 2, 1, 2) < 4
|
||||||
|
|| levenshtein($_word, $marinushka, 2, 1, 2) < 4
|
||||||
|
|| (levenshtein($_word, $marya, 3, 3, 1) < 3 && $word !== 'мария')
|
||||||
|
) {
|
||||||
|
$message->reply(_message::new()->setContent('ЗДАРОВА'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Пользователь: обновление роли
|
// Пользователь: обновление
|
||||||
$discord->on(event::GUILD_MEMBER_UPDATE, function (member $new, discord $discord, ?member $old = null) {
|
$discord->on(event::GUILD_MEMBER_UPDATE, function (member $new, discord $discord, ?member $old = null) {
|
||||||
// Запись в буфер вывода (терминал)
|
// Запись в буфер вывода (терминал)
|
||||||
|
|
||||||
@@ -196,6 +234,23 @@ final class index extends core
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$discord->application->commands->save(new command($discord, [
|
||||||
|
'name' => 'dreamers',
|
||||||
|
'description' => 'BEBRA DREAMERS',
|
||||||
|
'options' => [(new option($discord))
|
||||||
|
->setName('invite')
|
||||||
|
->setDescription('Send an invitation link to "BEBRA DREAMERS"')
|
||||||
|
->setType(option::SUB_COMMAND)]
|
||||||
|
]));
|
||||||
|
|
||||||
|
$discord->listenCommand(['dreamers', 'invite'], function (interaction $interaction) {
|
||||||
|
// Игнорирование чат-роботов
|
||||||
|
if ($interaction->user->bot) return;
|
||||||
|
|
||||||
|
// Отправка ссылки с приглашением присоединиться на сервер BEBRA DREAMERS
|
||||||
|
if ($interaction->data->options->has('invite')) $interaction->respondWithMessage(_message::new()->setContent('https://discord.bebra.team'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->discord->run();
|
$this->discord->run();
|
||||||
|
30
mirzaev/marina/system/controllers/traits/converters.php
Normal file
30
mirzaev/marina/system/controllers/traits/converters.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace mirzaev\marina\controllers\traits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Заготовки для конвертации строк
|
||||||
|
*
|
||||||
|
* @package mirzaev\marina\controllers\traits
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
trait converters
|
||||||
|
{
|
||||||
|
private static function utf8_to_extended_ascii(string $target, &$map)
|
||||||
|
{
|
||||||
|
// find all multibyte characters (cf. utf-8 encoding specs)
|
||||||
|
$matches = array();
|
||||||
|
if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $target, $matches))
|
||||||
|
return $target; // plain ascii string
|
||||||
|
|
||||||
|
// update the encoding map with the characters not already met
|
||||||
|
foreach ($matches[0] as $mbc)
|
||||||
|
if (!isset($map[$mbc]))
|
||||||
|
$map[$mbc] = chr(128 + count($map));
|
||||||
|
|
||||||
|
// finally remap non-ascii characters
|
||||||
|
return strtr($target, $map);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user