summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2024-02-26 19:05:37 -0500
committerLoren Burkholder <computersemiexpert@outlook.com>2024-02-26 19:05:37 -0500
commit99bbe266091d489695b588a44b5d5498b10e91c7 (patch)
treea4a5f2cbdb466714098b46e94397345e17d105a7 /src
parentFix gitlab ci syntax error (diff)
downloadnheko-99bbe266091d489695b588a44b5d5498b10e91c7.tar.xz
Add a glitch text command
Diffstat (limited to 'src')
-rw-r--r--src/CommandCompleter.cpp6
-rw-r--r--src/CommandCompleter.h1
-rw-r--r--src/Utils.cpp23
-rw-r--r--src/Utils.h3
-rw-r--r--src/timeline/InputBar.cpp3
5 files changed, 36 insertions, 0 deletions
diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp
index ee666559..67be642f 100644
--- a/src/CommandCompleter.cpp
+++ b/src/CommandCompleter.cpp
@@ -91,6 +91,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const
                 return QStringLiteral("/rainfall ");
             case Msgtype:
                 return QStringLiteral("/msgtype ");
+            case Glitch:
+                return QStringLiteral("/glitch ");
             case Goto:
                 return QStringLiteral("/goto ");
             case ConvertToDm:
@@ -170,6 +172,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const
                 return tr("/msgtype <msgtype> [message]");
             case Goto:
                 return tr("/goto <message reference>");
+            case Glitch:
+                return tr("/glitch <message>");
             case ConvertToDm:
                 return QStringLiteral("/converttodm");
             case ConvertToRoom:
@@ -245,6 +249,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const
                 return tr("Send a message with rain.");
             case Msgtype:
                 return tr("Send a message with a custom message type.");
+            case Glitch:
+                return tr("Send a message with a glitch effect.");
             case Goto:
                 return tr("Go to a specific message using an event id, index or matrix: link");
             case ConvertToDm:
diff --git a/src/CommandCompleter.h b/src/CommandCompleter.h
index 35ce2b36..44b192c3 100644
--- a/src/CommandCompleter.h
+++ b/src/CommandCompleter.h
@@ -48,6 +48,7 @@ public:
         RainbowConfetti,
         Rainfall,
         Msgtype,
+        Glitch,
         Goto,
         ConvertToDm,
         ConvertToRoom,
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 8d372763..253b3761 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -16,6 +16,7 @@
 #include <QGuiApplication>
 #include <QImageReader>
 #include <QProcessEnvironment>
+#include <QRandomGenerator64>
 #include <QScreen>
 #include <QSettings>
 #include <QStringBuilder>
@@ -2012,3 +2013,25 @@ utils::removeExpiredEvents()
 
     ApplyEventExpiration::next(std::move(asus));
 }
+
+QString
+utils::glitchText(const QString &text)
+{
+    static const QList<QChar> diacritics = []() {
+        QList<QChar> ret;
+        for (wchar_t c = u'\u0300'; c <= u'\u036f'; ++c)
+            ret.append(QChar(c));
+        return ret;
+    }();
+
+    QString result;
+
+    for (int i = 0; i < text.size(); ++i) {
+        result.append(text.at(i));
+        if (QRandomGenerator64::global()->bounded(0, 100) >= 25)
+            result.append(
+              diacritics.at(QRandomGenerator64::global()->bounded(0, diacritics.size())));
+    }
+
+    return result;
+}
diff --git a/src/Utils.h b/src/Utils.h
index 7f844627..1f477485 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -205,4 +205,7 @@ updateSpaceVias();
 
 void
 removeExpiredEvents();
+
+QString
+glitchText(const QString &text);
 }
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index 03ae5658..f29b806c 100644
--- a/src/timeline/InputBar.cpp
+++ b/src/timeline/InputBar.cpp
@@ -238,6 +238,7 @@ InputBar::updateTextContentProperties(const QString &t)
                                              QStringLiteral("rainbowconfetti"),
                                              QStringLiteral("rainfall"),
                                              QStringLiteral("msgtype"),
+                                             QStringLiteral("glitch"),
                                              QStringLiteral("goto"),
                                              QStringLiteral("converttodm"),
                                              QStringLiteral("converttoroom"),
@@ -918,6 +919,8 @@ InputBar::command(const QString &command, QString args)
         rainfall(args);
     } else if (command == QLatin1String("msgtype")) {
         customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1));
+    } else if (command == QLatin1String("glitch")) {
+        message(utils::glitchText(args));
     } else if (command == QLatin1String("goto")) {
         // Goto has three different modes:
         // 1 - Going directly to a given event ID