diff --git a/app.go b/app.go index ac052b4..4f0a0df 100644 --- a/app.go +++ b/app.go @@ -236,7 +236,7 @@ func (a *App) NewChatBot(cid string, username string, password string, streamUrl a.cb, err = chatbot.NewChatBot(a.ctx, streamUrl, channel.ChatBot, a.logError) if err != nil { a.logError.Println("error creating new chat bot:", err) - return fmt.Errorf("Error creating new chat bot. Try Again.") + return fmt.Errorf("Error creating new chat bot. Try again.") } err = a.cb.Login(username, password) diff --git a/frontend/src/components/ChatBot.jsx b/frontend/src/components/ChatBot.jsx index eef6f57..8e1354e 100644 --- a/frontend/src/components/ChatBot.jsx +++ b/frontend/src/components/ChatBot.jsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; -import { Modal } from './Modal'; +import { Modal, SmallModal } from './Modal'; import { NewChatBot } from '../../wailsjs/go/main/App'; @@ -73,56 +73,67 @@ export function ChatBotModal(props) { }; return ( - { - console.log('Saving'); - } - : submit - } - title={'Chat Bot'} - > -
- {error && {error}} -
- Username - + <> + { + console.log('Saving'); + } + : submit + } + title={'Chat Bot'} + > +
+ {/* {error && {error}} */} +
+ Username + +
+
+ Password + +
+
+ Stream URL + +
-
- Password - -
-
- Stream URL - -
-
- + + setError('')} + show={error !== ''} + style={{ minWidth: '300px', maxWidth: '300px', maxHeight: '100px' }} + title={'Error'} + message={error} + submitButton={'OK'} + onSubmit={() => setError('')} + /> + ); } diff --git a/frontend/src/components/StreamChatBot.jsx b/frontend/src/components/StreamChatBot.jsx index 012c4ba..e321f7d 100644 --- a/frontend/src/components/StreamChatBot.jsx +++ b/frontend/src/components/StreamChatBot.jsx @@ -36,7 +36,12 @@ function StreamChatBot(props) {
{sortChatsAlpha().map((chat, index) => ( - + ))}
@@ -46,9 +51,9 @@ function StreamChatBot(props) { export default StreamChatBot; function StreamChatItem(props) { - const [active, setActive] = useState(props.chat.active); + const [active, setActive] = useState(props.isMessageActive(props.chat.id)); const [error, setError] = useState(''); - const [filename, setFilename] = useState(''); + const [filename, setFilename] = useState(props.chat.text_file); useEffect(() => { if (props.chat.text_file !== '') { @@ -56,11 +61,13 @@ function StreamChatItem(props) { setFilename(name); }); } - }, []); + setActive(props.isMessageActive(props.chat.id)); + }, [props]); const changeActive = (bool) => { - console.log('ChangeActive:', bool); - props.chat.active = bool; + // console.log('ChangeActive:', bool); + // props.chat.active = bool; + props.activateMessage(props.chat.id, bool); setActive(bool); }; diff --git a/frontend/src/components/StreamEvent.jsx b/frontend/src/components/StreamEvent.jsx index 0e3319d..ef12103 100644 --- a/frontend/src/components/StreamEvent.jsx +++ b/frontend/src/components/StreamEvent.jsx @@ -44,6 +44,9 @@ function StreamEvent(props) { let hours = hours24 % 12 || 12; let minutes = date.getMinutes(); + if (minutes < 10) { + minutes = '0' + minutes; + } let mer = 'pm'; if (hours24 < 12) { diff --git a/frontend/src/screens/Dashboard.jsx b/frontend/src/screens/Dashboard.jsx index 6ce791a..0a4086a 100644 --- a/frontend/src/screens/Dashboard.jsx +++ b/frontend/src/screens/Dashboard.jsx @@ -34,6 +34,7 @@ function Dashboard() { const [active, setActive] = useState(false); const [openChatBot, setOpenChatBot] = useState(false); const [chatBotMessages, setChatBotMessages] = useState({}); + const [chatBotMessagesActive, setChatBotMessagesActive] = useState({}); const [chatAsChannel, setChatAsChannel] = useState(false); const [chatCommand, setChatCommand] = useState(''); const [chatOnCommand, setChatOnCommand] = useState(false); @@ -75,7 +76,7 @@ function Dashboard() { }); EventsOn('QueryResponse', (response) => { - console.log('query response received'); + // console.log('query response received'); setRefresh(!refresh); setActive(true); setUsername(response.username); @@ -102,7 +103,7 @@ function Dashboard() { EventsOn('QueryResponseError', (error) => { setError(error); - console.log('Query response error:', error); + // console.log('Query response error:', error); setActive(false); }); }, []); @@ -237,6 +238,21 @@ function Dashboard() { .catch((error) => console.log('Error creating new chat bot:', error)); }; + const activateMessage = (id, active) => { + // console.log('Dashboard activateMessage:', id, active); + chatBotMessagesActive[id] = active; + }; + + const isMessageActive = (id) => { + // console.log('is Message active start', id, chatBotMessagesActive[id]); + if (chatBotMessagesActive[id] === undefined) { + chatBotMessagesActive[id] = false; + } + + // console.log('is Message active after', id, chatBotMessagesActive[id]); + return chatBotMessagesActive[id]; + }; + return ( <> {openChat && ( @@ -290,11 +306,13 @@ function Dashboard() { */}
setOpenChatBot(true)} title={'Chat Bot'} + isMessageActive={isMessageActive} />
diff --git a/go.mod b/go.mod index 4d8e1b5..17eacfa 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/tylertravisty/go-utils v0.0.0-20230524204414-6893ae548909 - github.com/tylertravisty/rumble-livestream-lib-go v0.2.0 + github.com/tylertravisty/rumble-livestream-lib-go v0.2.1 github.com/wailsapp/wails/v2 v2.7.1 ) diff --git a/go.sum b/go.sum index 6e3c9e9..7ea00c3 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,8 @@ github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQ github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4= github.com/tylertravisty/go-utils v0.0.0-20230524204414-6893ae548909 h1:xrjIFqzGQXlCrCdMPpW6+SodGFSlrQ3ZNUCr3f5tF1g= github.com/tylertravisty/go-utils v0.0.0-20230524204414-6893ae548909/go.mod h1:2W31Jhs9YSy7y500wsCOW0bcamGi9foQV1CKrfvfTxk= -github.com/tylertravisty/rumble-livestream-lib-go v0.2.0 h1:sOXTZKBeB9PN3xfVSVYiILhMQdBQ2OiLMq+k70x5yb0= -github.com/tylertravisty/rumble-livestream-lib-go v0.2.0/go.mod h1:CACpHQV9xQqBKB7C13tUkL7O8Neb35+dJzRV1N211s4= +github.com/tylertravisty/rumble-livestream-lib-go v0.2.1 h1:VtdzuMIBePVTc26ZQeHmk3g2wtrPoAOiSjYvf8s2GTY= +github.com/tylertravisty/rumble-livestream-lib-go v0.2.1/go.mod h1:CACpHQV9xQqBKB7C13tUkL7O8Neb35+dJzRV1N211s4= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= diff --git a/internal/chatbot/chatbot.go b/internal/chatbot/chatbot.go index c7ff7f4..0ad5df2 100644 --- a/internal/chatbot/chatbot.go +++ b/internal/chatbot/chatbot.go @@ -41,7 +41,7 @@ type message struct { } func NewChatBot(ctx context.Context, streamUrl string, cfg config.ChatBot, logError *log.Logger) (*ChatBot, error) { - client, err := rumblelivestreamlib.NewClient("", streamUrl) + client, err := rumblelivestreamlib.NewClient("", validUrl(streamUrl)) if err != nil { return nil, fmt.Errorf("chatbot: error creating new client: %v", err) } @@ -49,6 +49,15 @@ func NewChatBot(ctx context.Context, streamUrl string, cfg config.ChatBot, logEr return &ChatBot{ctx: ctx, client: client, Cfg: cfg, commands: map[string]chan rumblelivestreamlib.ChatView{}, logError: logError, messages: map[string]*message{}}, nil } +func validUrl(url string) string { + valid := strings.TrimLeft(url, "http://") + if !strings.HasPrefix(valid, "https://") { + valid = "https://" + valid + } + + return valid +} + func (cb *ChatBot) StartMessage(id string) error { msg, exists := cb.Cfg.Messages[id] if !exists { @@ -106,7 +115,6 @@ func (cb *ChatBot) StartMessage(id string) error { return nil } -// TODO: lock commands map, update commands map with channel, unlock commands map func (cb *ChatBot) startCommand(ctx context.Context, m *message) { cb.commandsMu.Lock() ch := make(chan rumblelivestreamlib.ChatView) @@ -131,6 +139,7 @@ func (cb *ChatBot) startCommand(ctx context.Context, m *message) { cb.logError.Println("error sending chat:", err) cb.StopMessage(m.id) runtime.EventsEmit(cb.ctx, "ChatBotCommandError-"+m.id, m.id) + return } else { prev = now runtime.EventsEmit(cb.ctx, "ChatBotCommandActive-"+m.id, m.id)