Fixed a bunch of bugs
This commit is contained in:
parent
60b8dd7bab
commit
84276e2eb8
2
app.go
2
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)
|
a.cb, err = chatbot.NewChatBot(a.ctx, streamUrl, channel.ChatBot, a.logError)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.logError.Println("error creating new chat bot:", err)
|
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)
|
err = a.cb.Login(username, password)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Modal } from './Modal';
|
import { Modal, SmallModal } from './Modal';
|
||||||
|
|
||||||
import { NewChatBot } from '../../wailsjs/go/main/App';
|
import { NewChatBot } from '../../wailsjs/go/main/App';
|
||||||
|
|
||||||
|
@ -73,56 +73,67 @@ export function ChatBotModal(props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<>
|
||||||
onClose={close}
|
<Modal
|
||||||
show={props.show}
|
onClose={close}
|
||||||
style={{ minWidth: '300px', maxWidth: '400px' }}
|
show={props.show}
|
||||||
cancelButton={'Cancel'}
|
style={{ minWidth: '300px', maxWidth: '400px' }}
|
||||||
onCancel={close}
|
cancelButton={'Cancel'}
|
||||||
submitButton={saving ? 'Saving' : 'Save'}
|
onCancel={close}
|
||||||
onSubmit={
|
submitButton={saving ? 'Saving' : 'Save'}
|
||||||
saving
|
onSubmit={
|
||||||
? () => {
|
saving
|
||||||
console.log('Saving');
|
? () => {
|
||||||
}
|
console.log('Saving');
|
||||||
: submit
|
}
|
||||||
}
|
: submit
|
||||||
title={'Chat Bot'}
|
}
|
||||||
>
|
title={'Chat Bot'}
|
||||||
<div className='chat-bot-modal'>
|
>
|
||||||
{error && <span className='chat-bot-error'>{error}</span>}
|
<div className='chat-bot-modal'>
|
||||||
<div className='chat-bot-setting'>
|
{/* {error && <span className='chat-bot-error'>{error}</span>} */}
|
||||||
<span className='chat-bot-setting-label'>Username</span>
|
<div className='chat-bot-setting'>
|
||||||
<input
|
<span className='chat-bot-setting-label'>Username</span>
|
||||||
className='chat-bot-setting-input'
|
<input
|
||||||
onChange={updateUsername}
|
className='chat-bot-setting-input'
|
||||||
placeholder='Username'
|
onChange={updateUsername}
|
||||||
type='text'
|
placeholder='Username'
|
||||||
value={username}
|
type='text'
|
||||||
/>
|
value={username}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='chat-bot-setting'>
|
||||||
|
<span className='chat-bot-setting-label'>Password</span>
|
||||||
|
<input
|
||||||
|
className='chat-bot-setting-input'
|
||||||
|
onChange={updatePassword}
|
||||||
|
placeholder='Password'
|
||||||
|
type='password'
|
||||||
|
value={password}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='chat-bot-setting'>
|
||||||
|
<span className='chat-bot-setting-label'>Stream URL</span>
|
||||||
|
<input
|
||||||
|
className='chat-bot-setting-input'
|
||||||
|
onChange={updateUrl}
|
||||||
|
placeholder='https://'
|
||||||
|
type='text'
|
||||||
|
value={url}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='chat-bot-setting'>
|
</Modal>
|
||||||
<span className='chat-bot-setting-label'>Password</span>
|
<SmallModal
|
||||||
<input
|
onClose={() => setError('')}
|
||||||
className='chat-bot-setting-input'
|
show={error !== ''}
|
||||||
onChange={updatePassword}
|
style={{ minWidth: '300px', maxWidth: '300px', maxHeight: '100px' }}
|
||||||
placeholder='Password'
|
title={'Error'}
|
||||||
type='password'
|
message={error}
|
||||||
value={password}
|
submitButton={'OK'}
|
||||||
/>
|
onSubmit={() => setError('')}
|
||||||
</div>
|
/>
|
||||||
<div className='chat-bot-setting'>
|
</>
|
||||||
<span className='chat-bot-setting-label'>Stream URL</span>
|
|
||||||
<input
|
|
||||||
className='chat-bot-setting-input'
|
|
||||||
onChange={updateUrl}
|
|
||||||
placeholder='https://'
|
|
||||||
type='text'
|
|
||||||
value={url}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,12 @@ function StreamChatBot(props) {
|
||||||
</div>
|
</div>
|
||||||
<div className='stream-chatbot-list'>
|
<div className='stream-chatbot-list'>
|
||||||
{sortChatsAlpha().map((chat, index) => (
|
{sortChatsAlpha().map((chat, index) => (
|
||||||
<StreamChatItem chat={props.chats[chat]} onItemClick={props.onEdit} />
|
<StreamChatItem
|
||||||
|
activateMessage={props.activateMessage}
|
||||||
|
chat={props.chats[chat]}
|
||||||
|
isMessageActive={props.isMessageActive}
|
||||||
|
onItemClick={props.onEdit}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,9 +51,9 @@ function StreamChatBot(props) {
|
||||||
export default StreamChatBot;
|
export default StreamChatBot;
|
||||||
|
|
||||||
function StreamChatItem(props) {
|
function StreamChatItem(props) {
|
||||||
const [active, setActive] = useState(props.chat.active);
|
const [active, setActive] = useState(props.isMessageActive(props.chat.id));
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [filename, setFilename] = useState('');
|
const [filename, setFilename] = useState(props.chat.text_file);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.chat.text_file !== '') {
|
if (props.chat.text_file !== '') {
|
||||||
|
@ -56,11 +61,13 @@ function StreamChatItem(props) {
|
||||||
setFilename(name);
|
setFilename(name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
setActive(props.isMessageActive(props.chat.id));
|
||||||
|
}, [props]);
|
||||||
|
|
||||||
const changeActive = (bool) => {
|
const changeActive = (bool) => {
|
||||||
console.log('ChangeActive:', bool);
|
// console.log('ChangeActive:', bool);
|
||||||
props.chat.active = bool;
|
// props.chat.active = bool;
|
||||||
|
props.activateMessage(props.chat.id, bool);
|
||||||
setActive(bool);
|
setActive(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ function StreamEvent(props) {
|
||||||
let hours = hours24 % 12 || 12;
|
let hours = hours24 % 12 || 12;
|
||||||
|
|
||||||
let minutes = date.getMinutes();
|
let minutes = date.getMinutes();
|
||||||
|
if (minutes < 10) {
|
||||||
|
minutes = '0' + minutes;
|
||||||
|
}
|
||||||
|
|
||||||
let mer = 'pm';
|
let mer = 'pm';
|
||||||
if (hours24 < 12) {
|
if (hours24 < 12) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ function Dashboard() {
|
||||||
const [active, setActive] = useState(false);
|
const [active, setActive] = useState(false);
|
||||||
const [openChatBot, setOpenChatBot] = useState(false);
|
const [openChatBot, setOpenChatBot] = useState(false);
|
||||||
const [chatBotMessages, setChatBotMessages] = useState({});
|
const [chatBotMessages, setChatBotMessages] = useState({});
|
||||||
|
const [chatBotMessagesActive, setChatBotMessagesActive] = useState({});
|
||||||
const [chatAsChannel, setChatAsChannel] = useState(false);
|
const [chatAsChannel, setChatAsChannel] = useState(false);
|
||||||
const [chatCommand, setChatCommand] = useState('');
|
const [chatCommand, setChatCommand] = useState('');
|
||||||
const [chatOnCommand, setChatOnCommand] = useState(false);
|
const [chatOnCommand, setChatOnCommand] = useState(false);
|
||||||
|
@ -75,7 +76,7 @@ function Dashboard() {
|
||||||
});
|
});
|
||||||
|
|
||||||
EventsOn('QueryResponse', (response) => {
|
EventsOn('QueryResponse', (response) => {
|
||||||
console.log('query response received');
|
// console.log('query response received');
|
||||||
setRefresh(!refresh);
|
setRefresh(!refresh);
|
||||||
setActive(true);
|
setActive(true);
|
||||||
setUsername(response.username);
|
setUsername(response.username);
|
||||||
|
@ -102,7 +103,7 @@ function Dashboard() {
|
||||||
|
|
||||||
EventsOn('QueryResponseError', (error) => {
|
EventsOn('QueryResponseError', (error) => {
|
||||||
setError(error);
|
setError(error);
|
||||||
console.log('Query response error:', error);
|
// console.log('Query response error:', error);
|
||||||
setActive(false);
|
setActive(false);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -237,6 +238,21 @@ function Dashboard() {
|
||||||
.catch((error) => console.log('Error creating new chat bot:', error));
|
.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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{openChat && (
|
{openChat && (
|
||||||
|
@ -290,11 +306,13 @@ function Dashboard() {
|
||||||
</div> */}
|
</div> */}
|
||||||
<div className='main-right'>
|
<div className='main-right'>
|
||||||
<StreamChatBot
|
<StreamChatBot
|
||||||
|
activateMessage={activateMessage}
|
||||||
chats={chatBotMessages}
|
chats={chatBotMessages}
|
||||||
onAdd={newChat}
|
onAdd={newChat}
|
||||||
onEdit={editChat}
|
onEdit={editChat}
|
||||||
onSettings={() => setOpenChatBot(true)}
|
onSettings={() => setOpenChatBot(true)}
|
||||||
title={'Chat Bot'}
|
title={'Chat Bot'}
|
||||||
|
isMessageActive={isMessageActive}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/tylertravisty/go-utils v0.0.0-20230524204414-6893ae548909
|
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
|
github.com/wailsapp/wails/v2 v2.7.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
4
go.sum
4
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/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 h1:xrjIFqzGQXlCrCdMPpW6+SodGFSlrQ3ZNUCr3f5tF1g=
|
||||||
github.com/tylertravisty/go-utils v0.0.0-20230524204414-6893ae548909/go.mod h1:2W31Jhs9YSy7y500wsCOW0bcamGi9foQV1CKrfvfTxk=
|
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.1 h1:VtdzuMIBePVTc26ZQeHmk3g2wtrPoAOiSjYvf8s2GTY=
|
||||||
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/go.mod h1:CACpHQV9xQqBKB7C13tUkL7O8Neb35+dJzRV1N211s4=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
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/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
|
|
|
@ -41,7 +41,7 @@ type message struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChatBot(ctx context.Context, streamUrl string, cfg config.ChatBot, logError *log.Logger) (*ChatBot, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("chatbot: error creating new client: %v", err)
|
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
|
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 {
|
func (cb *ChatBot) StartMessage(id string) error {
|
||||||
msg, exists := cb.Cfg.Messages[id]
|
msg, exists := cb.Cfg.Messages[id]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -106,7 +115,6 @@ func (cb *ChatBot) StartMessage(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: lock commands map, update commands map with channel, unlock commands map
|
|
||||||
func (cb *ChatBot) startCommand(ctx context.Context, m *message) {
|
func (cb *ChatBot) startCommand(ctx context.Context, m *message) {
|
||||||
cb.commandsMu.Lock()
|
cb.commandsMu.Lock()
|
||||||
ch := make(chan rumblelivestreamlib.ChatView)
|
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.logError.Println("error sending chat:", err)
|
||||||
cb.StopMessage(m.id)
|
cb.StopMessage(m.id)
|
||||||
runtime.EventsEmit(cb.ctx, "ChatBotCommandError-"+m.id, m.id)
|
runtime.EventsEmit(cb.ctx, "ChatBotCommandError-"+m.id, m.id)
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
prev = now
|
prev = now
|
||||||
runtime.EventsEmit(cb.ctx, "ChatBotCommandActive-"+m.id, m.id)
|
runtime.EventsEmit(cb.ctx, "ChatBotCommandActive-"+m.id, m.id)
|
||||||
|
|
Loading…
Reference in a new issue