Как стать автором
Обновить

Модуль отлова нецензурных слов на Qt

Мой младший двоюродный брат постоянно матерился в Интернете.
Так как в семье только я умею программировать, меня попросила его мать написать программу отлова матерных слов.
Я помучался. Получилось весьма забавно…

Программа действует под всеми ОС.

Код



int KeysProc(QFile StatsFile)
{
QMessageBox MsgBox;
QByteArray FileWriter;
while (true)
{
     //First, we'll process "пизда" word
     int KeyPress = PressEvent->key();
     if (KeyPress == Qt::Key_G)
     {
         KeyPress = PressEvent->key();
         if (KeyPress == Qt::Key_B)
         {
             KeyPress = PressEvent->key();
             if (KeyPress == Qt::Key_P)
             {
                 KeyPress = PressEvent->key();
                 if (KeyPress == Qt::Key_L)
                 {
                     MsgBox.setText("You have just written an uncensored word");
                     MsgBox.exec();
                     FileWriter = "The word пизда entered";
                     StatsFile.Open(IO_ReadWrite | IO_Translate);
                     StatsFile.Write(FileWriter);
                     StatsFile.Close();
                 }
             }
             if (KeyPress == Qt::Key_L)
             {
                 KeyPress = PressEvent->key();
                 if (KeyPress == Qt::Key_F)
                 {
                     KeyPress = PressEvent->key();
                     if (KeyPress == Qt::Key_H)
                     {
                         MsgBox.setText("You have just written an uncensored word");
                         MsgBox.exec();
                         FileWriter = "The word пидарас entered";
                         StatsFile.Open(IO_ReadWrite | IO_Translate);
                         StatsFile.Write(FileWriter);
                         StatsFile.Close();
                     }
                 }
                 if (KeyPress == Qt::Key_J)
                 {
                     KeyPress = PressEvent->key();
                     if (KeyPress == Qt::Key_H)
                     {
                         MsgBox.setText("You have just written an uncensored word");
                         MsgBox.exec();
                         FileWriter = "The word пидор entered";
                         StatsFile.Open(IO_ReadWrite | IO_Translate);
                         StatsFile.Write(FileWriter);
                         StatsFile.Close();
                     }
                 }
             }
         }
     }
     //Then, "хуй" word
     if (KeyPress == Qt::Key_P || KeyPress == Qt::Key_ParenLeft)
     {
         KeyPress = PressEvent->key();
         if (KeyPress == Qt::Key_E)
         {
             KeyPress = PressEvent->key();
             if (KeyPress == Qt::Key_Q || KeyPress == Qt::Key_Z || KeyPress == Qt::Key_B)
             {
                 MsgBox.setText("You have just written an uncensored word");
                 MsgBox.exec();
                 FileWriter = "The word хуй entered";
                 StatsFile.Open(IO_ReadWrite | IO_Translate);
                 StatsFile.Write(FileWriter);
                 StatsFile.Close();
             }
         }
         if (KeyPress == Qt::Key_T)
         {
             KeyPress = PressEvent->key();
             if (KeyPress == Qt::Key_H)
             {
                 MsgBox.setText("You have just written an uncensored word");
                 MsgBox.exec();
                 FileWriter = "The word хер entered";
                 StatsFile.Open(IO_ReadWrite | IO_Translate);
                 StatsFile.Write(FileWriter);
                 StatsFile.Close();
             }
         }
     }
     if (KeyPress == Qt::Key_Comma)
     {
         KeyPress = PressEvent->key();
         if (KeyPress == Qt::Key_K)
         {
             KeyPress = PressEvent->key();
             if (KeyPress == Qt::Key_Z)
             {
                 MsgBox.setText("You have just written an uncensored word");
                 MsgBox.exec();
                 FileWriter = "The word бля entered";
                 StatsFile.Open(IO_ReadWrite | IO_Translate);
                 StatsFile.Write(FileWriter);
                 StatsFile.Close();
             }
         }
     }
}
return 0;
}


Разбор кода


1. Для начала мы создаем переменную KeyPress для хранения кода нажатой клавиши и сразу присваиваем ей код последней нажатой клавиши.

int KeyPress = PressEvent->key();


2. Потом идет сравнение с кодом нажатых клавиш — к примеру, сначала с клавишей «П».
Если сравнение верно, сравниваем дальше.
В первом примере как только будет введено «пизд», программа сразу же выводит соответствующее сообщение:

MsgBox.setText("You have just written an uncensored word");
MsgBox.exec();


3. Также, после того, как будет выведено сообщение, программа запишет все в лог-файл (StatsFile):

FileWriter = "The word пизда entered";
StatsFile.Open(IO_ReadWrite | IO_Translate);
StatsFile.Write(FileWriter);
StatsFile.Close();


Надеюсь, переменную QFile вы создадите сами.

Таким образом отлавливается большинство матерных слов, возможно, я написал не все.

ПРОСЬБА ИЗВИНИТЬ ЗА МАТЕРНЫЕ СЛОВА В КОДЕ, ПРОСТО ЭТО ЧАСТЬ ПРОГРАММЫ!

Теперь брат до сих пор думает, что этот модуль стоит у него в системе… Видно, надоели окна сообщений…
Теги:
Хабы:
Данная статья не подлежит комментированию, поскольку её автор ещё не является полноправным участником сообщества. Вы сможете связаться с автором только после того, как он получит приглашение от кого-либо из участников сообщества. До этого момента его username будет скрыт псевдонимом.