5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Model;
8 class ChatLog extends Model {
12 public function channel() {
13 return $this->belongsTo(Channel::class);
16 public function user() {
17 return $this->belongsTo(User::class);
20 public function evaluate() {
21 $this->evaluateUser();
22 $this->evaluateChannel();
24 if (is_null($this->nick)) {
25 $this->type = 'system';
28 if ($this->nick == 'localhorsttv') {
33 if ($this->command == 'PRIVMSG') {
34 if ($this->isKnownBot()) {
36 } else if (substr($this->params[0], 0, 1) == '#') {
41 $this->text_content = $this->params[1];
42 if ($this->scanForSpam()) {
48 throw new \Exception('unidentified message');
51 public function isKnownBot() {
52 return in_array(strtolower($this->nick), [
55 'pokemoncommunitygame',
62 protected function evaluateUser() {
65 protected function evaluateChannel() {
66 if (empty($this->params)) {
67 $this->channel()->associate(null);
70 $cname = $this->params[0];
71 if (substr($cname, 0, 1) != '#') {
74 $channel = Channel::firstWhere('twitch_chat', '=', $cname);
75 $this->channel()->associate($channel);
78 protected function scanForSpam() {
79 if (substr($this->text_content, 0, 1) == '!') {
82 if (strpos($this->text_content, '$') !== false) {
85 if (strpos($this->text_content, '€') !== false) {
88 if (strpos($this->text_content, '@') !== false) {
91 if (strpos($this->text_content, '://') !== false) {
94 if (is_numeric($this->text_content)) {
97 if (strpos($this->text_content, 'followers') !== false) {
100 if (strpos($this->text_content, 'promotion') !== false) {
103 if (strpos($this->text_content, 'viewers') !== false) {
106 if (strpos($this->text_content, 'view ers') !== false) {
113 'banned' => 'boolean',
116 'user_id' => 'string',
119 protected $fillable = [