]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/chat-bot-logs/Item.js
log who sent manual random chats
[alttp.git] / resources / js / components / chat-bot-logs / Item.js
index 8340e4ed9df6097ce3d31cb8e77ee7677901d400..f50d078f27bda27666020367dfc81d14c93528af 100644 (file)
@@ -4,12 +4,9 @@ import React from 'react';
 import { ListGroup } from 'react-bootstrap';
 import { useTranslation } from 'react-i18next';
 
-const getEntryDate = entry => {
-       const dateStr = moment(entry.created_at).fromNow();
-       return entry.user
-               ? `${entry.user.username} ${dateStr}`
-               : dateStr;
-};
+import { getUserName } from '../../helpers/User';
+
+const getEntryDate = entry => moment(entry.created_at).fromNow();
 
 const getEntryOrigin = (entry, t) => {
        return t('chatBotLog.origin.chatLog', {
@@ -19,6 +16,29 @@ const getEntryOrigin = (entry, t) => {
        });
 };
 
+const getEntryInfo = (entry, t) => {
+       if (entry.user && entry.category) {
+               return t('chatBotLog.info.userCat', {
+                       category: t(`twitchBot.chatCategories.${entry.category}`),
+                       date: getEntryDate(entry),
+                       user: getUserName(entry.user),
+               });
+       }
+       if (entry.category) {
+               return t('chatBotLog.info.cat', {
+                       category: t(`twitchBot.chatCategories.${entry.category}`),
+                       date: getEntryDate(entry),
+               });
+       }
+       if (entry.user) {
+               return t('chatBotLog.info.user', {
+                       date: getEntryDate(entry),
+                       user: getUserName(entry.user),
+               });
+       }
+       return getEntryDate(entry);
+};
+
 const Item = ({ entry }) => {
        const { t } = useTranslation();
 
@@ -38,7 +58,7 @@ const Item = ({ entry }) => {
                                className="text-muted"
                                title={moment(entry.created_at).format('LLLL')}
                        >
-                               {getEntryDate(entry)}
+                               {getEntryInfo(entry, t)}
                        </div>
                </div>
        </ListGroup.Item>;