mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-21 18:50:47 +03:00
Merge pull request #1688 from Nheko-Reborn/glitchtext
Add a glitch text command
This commit is contained in:
commit
b076b5b0ce
6 changed files with 91 additions and 0 deletions
|
@ -215,6 +215,12 @@ Redacts a specific event.
|
|||
*/roomnick* _<roomname>_::
|
||||
Change your nickname in a single room.
|
||||
|
||||
*/glitch* _<message>_::
|
||||
Applies a glitch effect to the given _message_. Beware that this will break mentions, HTML, and some Markdown in your message.
|
||||
|
||||
*/gradualglitch* _<message>_::
|
||||
Applies a progressively more severe glitch effect to the _message_. Again, this will break mentions, HTML, and some Markdown.
|
||||
|
||||
=== Emoticons
|
||||
|
||||
*/shrug* _[message]_::
|
||||
|
|
|
@ -91,6 +91,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
|||
return QStringLiteral("/rainfall ");
|
||||
case Msgtype:
|
||||
return QStringLiteral("/msgtype ");
|
||||
case Glitch:
|
||||
return QStringLiteral("/glitch ");
|
||||
case GradualGlitch:
|
||||
return QStringLiteral("/gradualglitch ");
|
||||
case Goto:
|
||||
return QStringLiteral("/goto ");
|
||||
case ConvertToDm:
|
||||
|
@ -170,6 +174,10 @@ 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 GradualGlitch:
|
||||
return tr("/gradualglitch <message>");
|
||||
case ConvertToDm:
|
||||
return QStringLiteral("/converttodm");
|
||||
case ConvertToRoom:
|
||||
|
@ -245,6 +253,10 @@ 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 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:
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
RainbowConfetti,
|
||||
Rainfall,
|
||||
Msgtype,
|
||||
Glitch,
|
||||
GradualGlitch,
|
||||
Goto,
|
||||
ConvertToDm,
|
||||
ConvertToRoom,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QImageReader>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QRandomGenerator64>
|
||||
#include <QScreen>
|
||||
#include <QSettings>
|
||||
#include <QStringBuilder>
|
||||
|
@ -2012,3 +2013,61 @@ utils::removeExpiredEvents()
|
|||
|
||||
ApplyEventExpiration::next(std::move(asus));
|
||||
}
|
||||
|
||||
namespace {
|
||||
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
|
||||
utils::glitchText(const QString &text)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -205,4 +205,10 @@ updateSpaceVias();
|
|||
|
||||
void
|
||||
removeExpiredEvents();
|
||||
|
||||
QString
|
||||
glitchText(const QString &text);
|
||||
|
||||
QString
|
||||
graduallyGlitchText(const QString &text);
|
||||
}
|
||||
|
|
|
@ -238,6 +238,8 @@ InputBar::updateTextContentProperties(const QString &t)
|
|||
QStringLiteral("rainbowconfetti"),
|
||||
QStringLiteral("rainfall"),
|
||||
QStringLiteral("msgtype"),
|
||||
QStringLiteral("glitch"),
|
||||
QStringLiteral("gradualglitch"),
|
||||
QStringLiteral("goto"),
|
||||
QStringLiteral("converttodm"),
|
||||
QStringLiteral("converttoroom"),
|
||||
|
@ -918,6 +920,10 @@ 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("gradualglitch")) {
|
||||
message(utils::graduallyGlitchText(args));
|
||||
} else if (command == QLatin1String("goto")) {
|
||||
// Goto has three different modes:
|
||||
// 1 - Going directly to a given event ID
|
||||
|
|
Loading…
Reference in a new issue