From 99bbe266091d489695b588a44b5d5498b10e91c7 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Mon, 26 Feb 2024 19:05:37 -0500 Subject: [PATCH 1/3] Add a glitch text command --- src/CommandCompleter.cpp | 6 ++++++ src/CommandCompleter.h | 1 + src/Utils.cpp | 23 +++++++++++++++++++++++ src/Utils.h | 3 +++ src/timeline/InputBar.cpp | 3 +++ 5 files changed, 36 insertions(+) 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 [message]"); case Goto: return tr("/goto "); + case Glitch: + return tr("/glitch "); 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 #include #include +#include #include #include #include @@ -2012,3 +2013,25 @@ utils::removeExpiredEvents() ApplyEventExpiration::next(std::move(asus)); } + +QString +utils::glitchText(const QString &text) +{ + static const QList diacritics = []() { + QList 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 From 21d51d9739996266f7f515c56c79754010357a17 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 27 Feb 2024 13:13:08 -0500 Subject: [PATCH 2/3] Add a command to gradually glitch text in a message --- src/CommandCompleter.cpp | 6 +++++ src/CommandCompleter.h | 1 + src/Utils.cpp | 52 +++++++++++++++++++++++++++++++++------ src/Utils.h | 3 +++ src/timeline/InputBar.cpp | 3 +++ 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index 67be642f..33e7ef2c 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -93,6 +93,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/msgtype "); case Glitch: return QStringLiteral("/glitch "); + case GradualGlitch: + return QStringLiteral("/gradualglitch "); case Goto: return QStringLiteral("/goto "); case ConvertToDm: @@ -174,6 +176,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("/goto "); case Glitch: return tr("/glitch "); + case GradualGlitch: + return tr("/gradualglitch "); case ConvertToDm: return QStringLiteral("/converttodm"); case ConvertToRoom: @@ -251,6 +255,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("Send a message with a custom message type."); case Glitch: return tr("Send a message with a glitch effect."); + case GradualGlitch: + return tr("Send a message that gradually glitches."); 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 44b192c3..9dc18119 100644 --- a/src/CommandCompleter.h +++ b/src/CommandCompleter.h @@ -49,6 +49,7 @@ public: Rainfall, Msgtype, Glitch, + GradualGlitch, Goto, ConvertToDm, ConvertToRoom, diff --git a/src/Utils.cpp b/src/Utils.cpp index 253b3761..3151d017 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -2014,24 +2014,60 @@ utils::removeExpiredEvents() ApplyEventExpiration::next(std::move(asus)); } +namespace { +static const QList diacritics = []() { + QList ret; + for (wchar_t c = u'\u0300'; c <= u'\u036f'; ++c) + ret.append(QChar(c)); + return ret; +}(); +} + QString utils::glitchText(const QString &text) { - static const QList diacritics = []() { - QList 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; +} + +QString +utils::graduallyGlitchText(const QString &text) +{ + QString result; + + const int noGlitch = text.size() * 0.5; + const int someGlitch = text.size() * 0.8; + const int lotsOfGlitch = text.size() * 0.95; + + for (int i = 0; i < text.size(); ++i) { + result.append(text.at(i)); + + if (i < noGlitch) // first 40% of text is normal + continue; + else if (i < someGlitch) // next 25% is progressively glitchier + { + if (QRandomGenerator64::global()->bounded(noGlitch, someGlitch) < + noGlitch + (i - noGlitch) * 0.05) + result.append( + diacritics.at(QRandomGenerator64::global()->bounded(0, diacritics.size()))); + } else if (i < lotsOfGlitch) { // oh no, it's spreading! + if (QRandomGenerator64::global()->bounded(someGlitch, lotsOfGlitch) < i) + result.append( + diacritics.at(QRandomGenerator64::global()->bounded(0, diacritics.size()))); + } else { // just give up, your computer is cursed now + do { + if (QRandomGenerator64::global()->bounded(text.size() / 5, text.size()) < i) + result.append( + diacritics.at(QRandomGenerator64::global()->bounded(0, diacritics.size()))); + } while (QRandomGenerator64::global()->bounded(0, 100) < 35); + } + } return result; } diff --git a/src/Utils.h b/src/Utils.h index 1f477485..75438a7b 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -208,4 +208,7 @@ removeExpiredEvents(); QString glitchText(const QString &text); + +QString +graduallyGlitchText(const QString &text); } diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index f29b806c..62d38cf5 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -239,6 +239,7 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("rainfall"), QStringLiteral("msgtype"), QStringLiteral("glitch"), + QStringLiteral("gradualglitch"), QStringLiteral("goto"), QStringLiteral("converttodm"), QStringLiteral("converttoroom"), @@ -921,6 +922,8 @@ InputBar::command(const QString &command, QString args) customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == QLatin1String("glitch")) { message(utils::glitchText(args)); + } else if (command == QLatin1String("gradualglitch")) { + message(utils::graduallyGlitchText(args)); } else if (command == QLatin1String("goto")) { // Goto has three different modes: // 1 - Going directly to a given event ID From c35b217a4fd511fc23db3d303ba0c67e2a4d7157 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 27 Feb 2024 15:01:46 -0500 Subject: [PATCH 3/3] Add a warning that glitching text can, shockingly, corrupt your message --- man/nheko.1.adoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/nheko.1.adoc b/man/nheko.1.adoc index 5bd5d622..ff316308 100644 --- a/man/nheko.1.adoc +++ b/man/nheko.1.adoc @@ -215,6 +215,12 @@ Redacts a specific event. */roomnick* __:: Change your nickname in a single room. +*/glitch* __:: +Applies a glitch effect to the given _message_. Beware that this will break mentions, HTML, and some Markdown in your message. + +*/gradualglitch* __:: +Applies a progressively more severe glitch effect to the _message_. Again, this will break mentions, HTML, and some Markdown. + === Emoticons */shrug* _[message]_::