Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #226
- Loading branch information
Showing
28 changed files
with
431 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
const appApi = require("../../../api/app"); | ||
const { _ } = require("../../i18next"); | ||
const twitch = require("../index"); | ||
const login = require("../login"); | ||
const retry = require("../retry"); | ||
|
||
function mapSort(rewards) { | ||
return rewards.map((reward) => reward._data).sort((a, b) => a.cost - b.cost); | ||
} | ||
|
||
module.exports = async function getRewardList() { | ||
async function _getRewardList() { | ||
const user = await login(); | ||
const rewards = await twitch.api.helix.channelPoints.getCustomRewards(user); | ||
return rewards ? mapSort(rewards) : null; | ||
} | ||
|
||
module.exports = async function getRewardList() { | ||
try { | ||
return await retry(_getRewardList); | ||
} catch (error) { | ||
appApi.stateNotify("error", _("errors.unable_to_fetch_rewards_list")); | ||
return []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
const getLastFollows = require("../api/getLastFollows"); | ||
const pushActions = require("../pushActions"); | ||
const appApi = require("../../../api/app"); | ||
const { _ } = require("../../i18next"); | ||
const retry = require("../retry"); | ||
|
||
module.exports = async function streamStatePlugin({ delay = 2 } = {}) { | ||
const follows = await getLastFollows(); | ||
module.exports = async function followsPlugin({ delay = 0.5 } = {}) { | ||
try { | ||
const follows = await retry(getLastFollows); | ||
|
||
follows.forEach((viewer) => { | ||
pushActions("onFollow", { user: viewer.name }); | ||
}); | ||
follows.forEach((viewer) => { | ||
pushActions("onFollow", { user: viewer.name }); | ||
}); | ||
|
||
setTimeout(streamStatePlugin, delay * 1000); | ||
setTimeout(followsPlugin, delay * 1000); | ||
} catch (error) { | ||
appApi.stateNotify("error", _("errors.unable_to_fetch_new_follows")); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
const state = require("../state"); | ||
const retry = require("../retry"); | ||
const { _ } = require("../../i18next"); | ||
const appApi = require("../../../api/app"); | ||
const getStreamByChannel = require("../api/getStreamByChannel"); | ||
|
||
module.exports = async function streamStatePlugin({ delay = 10 } = {}) { | ||
const channel = state.get("user.display_name"); | ||
const stream = await getStreamByChannel(channel); | ||
state.set("stream", stream); | ||
setTimeout(streamStatePlugin, delay * 1000); | ||
try { | ||
const channel = state.get("user.display_name"); | ||
const stream = await retry(() => getStreamByChannel(channel)); | ||
setTimeout(streamStatePlugin, delay * 1000); | ||
state.set("stream", stream); | ||
} catch (error) { | ||
appApi.stateNotify("error", _("errors.unable_to_fetch_stream_state")); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
const Viewer = require("../../../db/Models/Viewer"); | ||
const getFollows = require("../api/getFollows"); | ||
const appApi = require("../../../api/app"); | ||
const { _ } = require("../../i18next"); | ||
const retry = require("../retry"); | ||
|
||
module.exports = async function updateFollowPlugin() { | ||
module.exports = async function updateFollowsPlugin() { | ||
const all = await Viewer.findAll(); | ||
if (all.length) return; | ||
await getFollows(); | ||
|
||
try { | ||
await retry(getFollows); | ||
} catch (error) { | ||
appApi.stateNotify("error", _("errors.unable_to_fetch_all_follows")); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const loggers = require("../../libs/loggers"); | ||
const pRetry = require("p-retry"); | ||
|
||
const logger = loggers.get("app"); | ||
|
||
module.exports = async function retry(promise, options) { | ||
return await pRetry(promise, { | ||
retries: 5, | ||
...options, | ||
onFailedAttempt: (error) => { | ||
logger.error(error.message, error); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
import { color } from "./colors"; | ||
export let type; | ||
export let notices; | ||
</script> | ||
|
||
{#if notices.length} | ||
<div class="text-sm px-2 inline rounded-full {color(type)}"> | ||
{notices.length} | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script> | ||
import { iconColor } from "./colors"; | ||
import Icon from "@/components/UI/Icon.svelte"; | ||
import info from "svelte-icons/md/MdInfo.svelte"; | ||
import error from "svelte-icons/md/MdError.svelte"; | ||
import warning from "svelte-icons/md/MdWarning.svelte"; | ||
import success from "svelte-icons/md/MdCheckCircle.svelte"; | ||
export let type; | ||
const icons = { | ||
info, | ||
error, | ||
warning, | ||
success, | ||
}; | ||
let icon = icons[type] || icons.info; | ||
</script> | ||
|
||
<Icon icon="{icon}" class="{iconColor(type)}" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script> | ||
import ms from "ms"; | ||
import NoticeIcon from "./Icon.svelte"; | ||
import { slide } from "svelte/transition"; | ||
import { closeNotice } from "@/stores/notify"; | ||
import Icon from "@/components/UI/Icon.svelte"; | ||
import MdCheck from "svelte-icons/md/MdCheck.svelte"; | ||
export let notice; | ||
export let time = Date.now(); | ||
</script> | ||
|
||
<div | ||
transition:slide|local | ||
on:mouseenter="{() => closeNotice(notice)}" | ||
class="flex p-2 gap-2 items-center text-gray-800 bg-gray-300 border-b border-gray-600 hover:bg-opacity-100 {notice.read ? 'bg-opacity-75' : ''}" | ||
> | ||
<NoticeIcon type="{notice.type}" /> | ||
<div class="flex-auto break-all">{notice.message}</div> | ||
{#if notice.read} | ||
<div class="fill-current "> | ||
<Icon icon="{MdCheck}" /> | ||
</div> | ||
{/if} | ||
<div class="opacity-50">{ms(time - notice.time)}</div> | ||
</div> |
Oops, something went wrong.