class TokenizedMessage {
public function __construct($text, $tags = []) {
- $this->text = $text;
+ $this->text = trim($text);
$this->tags = $tags;
- $this->raw = strtolower(preg_replace('/[^\w]/u', '', $text));
- $this->tokens = array_values(array_map('trim', array_filter(preg_split('/\b/', strtolower($text)))));
+ $this->raw = strtolower(preg_replace('/[^\w]/u', '', $this->text));
+ $this->tokens = array_values(array_map('trim', array_filter(preg_split('/\b/', strtolower($this->text)))));
$this->emoteless = $this->text;
if (isset($this->tags['emotes']) && !empty($this->tags['emotes'])) {
public function classify() {
if (is_null($this->classification)) {
- if (empty($this->raw)) {
+ if (empty($this->text)) {
$this->classification = 'unclassified';
} else if ($this->startsWith('!')) {
$this->classification = 'cmd';
$this->classification = 'love';
} else if ($this->hasToken(['nani', 'wat', 'wtf']) || $this->hasEmoteThatEndsWith(['wat', 'wtf'])) {
$this->classification = 'wtf';
+ } else if ($this->hasConsecutiveTokens([':', 'eyes', ':']) || $this->hasEmoteThatEndsWith(['eyes'])) {
+ $this->classification = 'eyes';
+ } else if ($this->hasEmoteThatEndsWith(['angry', 'rage', 'ree'])) {
+ $this->classification = 'rage';
+ } else if ($this->hasToken([':(']) || $this->hasEmoteThatEndsWith(['cry', 'sad'])) {
+ $this->classification = 'sad';
+ } else if ($this->hasToken(['monkas', 'sweat_smile']) || $this->hasEmoteThatEndsWith(['sweat'])) {
+ $this->classification = 'sweat';
} else if ($this->endsWithEmoteless('?')) {
$this->classification = 'question';
} else if ($this->startsOrEndsWithRaw(['o7']) || $this->hasEmoteThatContains('salut')) {
private function randomChat(Channel $channel) {
return $channel->queryChatlog()
- ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified'])
+ ->whereNotIn('classification', ['gg', 'gl', 'o7'])
->first();
}
'hi',
'gl',
'gg',
+ 'eyes',
'love',
'lol',
+ 'rage',
+ 'sad',
+ 'sweat',
'wtf',
'pog',
'hype',
channel: 'Channel',
chat: 'Chat',
chatCategories: {
+ eyes: 'Augen',
gg: 'Good Game',
gl: 'Good Luck',
hi: 'Begrüßung',
o7: 'Salutieren',
pog: 'Pog',
question: 'Frage',
+ rage: 'Zorn',
+ sad: 'Traurig',
+ sweat: 'Schwitzen',
thx: 'Danke',
unclassified: 'Generisch',
wtf: 'WTF',
channel: 'Channel',
chat: 'Chat',
chatCategories: {
+ eyes: 'Eyes',
gg: 'Good Game',
gl: 'Good Luck',
hi: 'Greeting',
o7: 'Salute',
pog: 'Pog',
question: 'Question',
+ rage: 'Rage',
+ sad: 'Sad',
+ sweat: 'Sweat',
thx: 'Thanks',
unclassified: 'Generic',
wtf: 'WTF',
public function test_classification() {
$this->assertEquals('cmd', TokenizedMessage::fromString('!start')->classify());
+ $this->assertEquals('eyes', TokenizedMessage::fromString(':eyes:')->classify());
+ $this->assertEquals('eyes', TokenizedMessage::fromString('holysm3Eyes', ['emotes' => 'blah:0-11'])->classify());
+
$this->assertEquals('gg', TokenizedMessage::fromString('gg')->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('GG')->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('Gg')->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('ggs')->classify());
+ $this->assertEquals('gg', TokenizedMessage::fromString('gg monkaS')->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('ja gg dann, ne')->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('duden2Gg', ['emotes' => 'blah:0-7'])->classify());
$this->assertEquals('gg', TokenizedMessage::fromString('ticknaGg2', ['emotes' => 'blah:0-8'])->classify());
$this->assertEquals('pog', TokenizedMessage::fromString('Pog')->classify());
$this->assertNotEquals('pog', TokenizedMessage::fromString('wo war der')->classify());
+ $this->assertEquals('rage', TokenizedMessage::fromString('duden2Rage', ['emotes' => 'blah:0-10'])->classify());
+
$this->assertEquals('question', TokenizedMessage::fromString('Joaaa geht so ...und selbst?')->classify());
+ $this->assertEquals('sad', TokenizedMessage::fromString(':(')->classify());
+ $this->assertEquals('sad', TokenizedMessage::fromString('PoroSad', ['emotes' => 'blah:0-7'])->classify());
+
+ $this->assertEquals('sweat', TokenizedMessage::fromString('monkaS')->classify());
+
$this->assertEquals('thx', TokenizedMessage::fromString('danke für den tipp')->classify());
$this->assertEquals('wtf', TokenizedMessage::fromString('wtf? lol')->classify());