add reset for messageTypes and enable bttv emotes for web ui
This commit is contained in:
parent
eca967de65
commit
e681abdbd6
11 changed files with 91 additions and 23 deletions
|
@ -8,6 +8,7 @@ commands, etc. yet, it focuses on logging and providing an api for the logs.
|
|||
- `!justlog status` will respond with uptime
|
||||
- `!justlog join gempir,pajlada` will join the channels and append them to the config
|
||||
- `!justlog messageType gempir 1,2` will set the recorded message types to 1 and 2 in channel gempir (will fetch the userid on its own)
|
||||
- `!justlog messageType gempir reset` will reset to default
|
||||
|
||||
### Config
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -58,18 +58,23 @@ func (b *Bot) handleMessageType(message twitch.PrivateMessage) {
|
|||
return
|
||||
}
|
||||
|
||||
var messageTypes []twitch.MessageType
|
||||
for _, msgType := range strings.Split(parts[1], ",") {
|
||||
messageType, err := strconv.Atoi(msgType)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
if parts[1] == "reset" {
|
||||
b.cfg.ResetMessageTypes(users[parts[0]].ID)
|
||||
log.Infof("[bot] setting %s config messageTypes to default", parts[0])
|
||||
} else {
|
||||
var messageTypes []twitch.MessageType
|
||||
for _, msgType := range strings.Split(parts[1], ",") {
|
||||
messageType, err := strconv.Atoi(msgType)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
messageTypes = append(messageTypes, twitch.MessageType(messageType))
|
||||
}
|
||||
|
||||
messageTypes = append(messageTypes, twitch.MessageType(messageType))
|
||||
b.cfg.SetMessageTypes(users[parts[0]].ID, messageTypes)
|
||||
b.updateMessageTypesToLog()
|
||||
log.Infof("[bot] setting %s config messageTypes to %v", parts[0], messageTypes)
|
||||
}
|
||||
|
||||
b.cfg.SetMessageTypes(users[parts[0]].ID, messageTypes)
|
||||
b.updateMessageTypesToLog()
|
||||
log.Infof("[bot] setting %s config messageTypes to %v", parts[0], messageTypes)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ type Config struct {
|
|||
|
||||
// ChannelConfig config for indiviual channels
|
||||
type ChannelConfig struct {
|
||||
MessageTypes []twitch.MessageType `json:"messageTypes"`
|
||||
MessageTypes []twitch.MessageType `json:"messageTypes,omitempty"`
|
||||
}
|
||||
|
||||
// NewConfig create configuration from file
|
||||
|
@ -65,6 +65,18 @@ func (cfg *Config) SetMessageTypes(channelID string, messageTypes []twitch.Messa
|
|||
cfg.persistConfig()
|
||||
}
|
||||
|
||||
// ResetMessageTypes removed message type option and therefore resets it
|
||||
func (cfg *Config) ResetMessageTypes(channelID string) {
|
||||
if _, ok := cfg.ChannelConfigs[channelID]; ok {
|
||||
channelCfg := cfg.ChannelConfigs[channelID]
|
||||
channelCfg.MessageTypes = nil
|
||||
|
||||
cfg.ChannelConfigs[channelID] = channelCfg
|
||||
}
|
||||
|
||||
cfg.persistConfig()
|
||||
}
|
||||
|
||||
func appendIfMissing(slice []string, i string) []string {
|
||||
for _, ele := range slice {
|
||||
if ele == i {
|
||||
|
|
File diff suppressed because one or more lines are too long
25
web/src/js/actions/loadBttvEmotes.js
Normal file
25
web/src/js/actions/loadBttvEmotes.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import setBttvChannelEmotes from "./setBttvChannelEmotes";
|
||||
|
||||
export default function (channel) {
|
||||
return function (dispatch, getState) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch("https://api.betterttv.net/2/channels/" + channel).then((response) => {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response
|
||||
} else {
|
||||
var error = new Error(response.statusText)
|
||||
error.response = response
|
||||
throw error
|
||||
}
|
||||
}).then((response) => {
|
||||
return response.json();
|
||||
}).then((json) => {
|
||||
dispatch(setBttvChannelEmotes(json))
|
||||
|
||||
resolve();
|
||||
}).catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
6
web/src/js/actions/setBttvChannelEmotes.js
Normal file
6
web/src/js/actions/setBttvChannelEmotes.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
export default (bttvChannelEmotes) => (dispatch) => {
|
||||
dispatch({
|
||||
type: 'SET_BTTV_CHANNEL_EMOTES',
|
||||
bttvChannelEmotes: bttvChannelEmotes
|
||||
});
|
||||
}
|
|
@ -4,6 +4,7 @@ import LogView from "./LogView";
|
|||
import { connect } from "react-redux";
|
||||
import loadChannels from "../actions/loadChannels";
|
||||
import loadLogs from "../actions/loadLogs";
|
||||
import loadBttvEmotes from "../actions/loadBttvEmotes";
|
||||
import { ToastContainer, toast } from "react-toastify";
|
||||
import 'react-toastify/dist/ReactToastify.min.css';
|
||||
|
||||
|
@ -17,6 +18,7 @@ class LogSearch extends Component {
|
|||
componentDidMount() {
|
||||
if (this.props.channel && this.props.username) {
|
||||
this.props.dispatch(loadLogs());
|
||||
this.props.dispatch(loadBttvEmotes(this.props.channel));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class LogView extends Component {
|
|||
state = {
|
||||
loading: false,
|
||||
height: 0,
|
||||
buttonText: "load"
|
||||
buttonText: "load",
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -58,6 +58,16 @@ class LogView extends Component {
|
|||
));
|
||||
}
|
||||
|
||||
if (this.props.bttvChannelEmotes) {
|
||||
for (const emote of this.props.bttvChannelEmotes.emotes) {
|
||||
const regex = new RegExp(`(?:^|\ )(${emote.code})(?:$|\ )`);
|
||||
|
||||
message = reactStringReplace(message, regex, (match, i) => (
|
||||
<img key={i} src={this.buildBttvEmote(this.props.bttvChannelEmotes.urlTemplate, emote.id)} alt={match} />
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<p>
|
||||
{message}
|
||||
|
@ -79,10 +89,14 @@ class LogView extends Component {
|
|||
buildTwitchEmote = (id) => {
|
||||
return `https://static-cdn.jtvnw.net/emoticons/v1/${id}/1.0`;
|
||||
}
|
||||
|
||||
buildBttvEmote = (urlTemplate, id) => {
|
||||
return urlTemplate.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||
}
|
||||
}
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
|
||||
bttvChannelEmotes: state.bttvChannelEmotes,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ export default () => {
|
|||
return {
|
||||
apiBaseUrl: process.env.apiBaseUrl,
|
||||
channels: [],
|
||||
bttvChannelEmotes: null,
|
||||
logs: {},
|
||||
loading: false,
|
||||
twitchEmotes: {},
|
||||
|
|
|
@ -10,6 +10,8 @@ export default (state, action) => {
|
|||
return { ...state, channel: action.channel, username: action.username };
|
||||
case "SET_TWITCH_EMOTES":
|
||||
return { ...state, twitchEmotes: action.twitchEmotes };
|
||||
case "SET_BTTV_CHANNEL_EMOTES":
|
||||
return { ...state, bttvChannelEmotes: action.bttvChannelEmotes };
|
||||
default:
|
||||
return { ...state };
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue