broken tmi messages are now not crashing the frontend anymore, fixed bttv a bit. still need to figure out channel emotes

This commit is contained in:
gempir 2020-05-16 20:21:52 +02:00
parent 13096c77fe
commit 692ac439b6
7 changed files with 26 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
import setBttvChannelEmotes from "./setBttvChannelEmotes";
export default function (channel) {
export default function (channelid) {
return function (dispatch, getState) {
return new Promise((resolve, reject) => {
fetch("https://api.betterttv.net/2/channels/" + channel).then((response) => {
fetch("https://api.betterttv.net/3/cached/users/twitch/" + channelid).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response
} else {

View file

@ -1,9 +1,9 @@
import setBttvEmotes from "./setBttvEmotes";
export default function (channel) {
export default function () {
return function (dispatch, getState) {
return new Promise((resolve, reject) => {
fetch("https://api.betterttv.net/2/emotes").then((response) => {
fetch("https://api.betterttv.net/3/cached/emotes/global").then((response) => {
if (response.status >= 200 && response.status < 300) {
return response
} else {

View file

@ -7,6 +7,9 @@ export default function (channel, username, year, month) {
return new Promise((resolve, reject) => {
channel = channel || getState().channel;
username = username || getState().username;
channel = channel.toLowerCase();
username = username.toLowerCase();
const date = new Date();
year = year || date.getFullYear();
month = month || date.getMonth() + 1;
@ -14,11 +17,11 @@ export default function (channel, username, year, month) {
dispatch(setLoading(true));
let channelPath = "channel";
if (channel.toLowerCase().startsWith("id:")) {
if (channel.startsWith("id:")) {
channelPath = "id";
}
let usernamePath = "user";
if (username.toLowerCase().startsWith("id:")) {
if (username.startsWith("id:")) {
usernamePath = "id";
}

View file

@ -20,7 +20,8 @@ class LogSearch extends Component {
componentDidMount() {
if (this.props.channel && this.props.username) {
this.props.dispatch(loadLogs());
this.props.dispatch(loadBttvChannelEmotes(this.props.channel));
// load again when i figure out good way to fetch the id
// this.props.dispatch(loadBttvChannelEmotes(this.props.channel));
}
}

View file

@ -56,7 +56,13 @@ class LogView extends Component {
if (msgObj.tags.emotes && msgObj.tags.emotes !== true) {
for (const emoteString of msgObj.tags.emotes.split("/")) {
if (typeof emoteString !== "string") {
continue;
}
const [emoteId, occurences] = emoteString.split(":");
if (typeof occurences !== "string") {
continue;
}
for (const occurence of occurences.split(",")) {
const [start, end] = occurence.split("-");
replacements.push({start: Number(start), end: Number(end) + 1, emoteId});
@ -83,15 +89,15 @@ class LogView extends Component {
for (const emote of this.props.bttvChannelEmotes.emotes) {
const regex = new RegExp(`\\b(${emote.code})\\b`, "g");
message = message.replace(regex, `<img src="${this.buildBttvEmote(this.props.bttvChannelEmotes.urlTemplate, emote.id)}" alt="${emote.id}" />`);
message = message.replace(regex, `<img src="${this.buildBttvEmote(emote.id)}" alt="${emote.id}" />`);
}
}
if (this.props.bttvEmotes) {
for (const emote of this.props.bttvEmotes.emotes) {
for (const emote of this.props.bttvEmotes) {
const regex = new RegExp(`\\b(${emote.code})\\b`, "g");
message = message.replace(regex, `<img src="${this.buildBttvEmote(this.props.bttvEmotes.urlTemplate, emote.id)}" alt="${emote.id}" />`);
message = message.replace(regex, `<img src="${this.buildBttvEmote(emote.id)}" alt="${emote.id}" />`);
}
}
@ -116,8 +122,8 @@ class LogView extends Component {
return `https://static-cdn.jtvnw.net/emoticons/v1/${id}/1.0`;
}
buildBttvEmote = (urlTemplate, id) => {
return urlTemplate.replace("{{id}}", id).replace("{{image}}", "1x");
buildBttvEmote = (id) => {
return `https://cdn.betterttv.net/emote/${id}/1x`;
}
}
const mapStateToProps = (state) => {