Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alerts): add tier variant occurence filter #4490

Merged
merged 2 commits into from Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions locales/en/ui/registry/alerts.json
Expand Up @@ -55,6 +55,12 @@
"random": "Random",
"exact-amount": "Exact amount",
"greater-than-or-equal-to-amount": "Greater than or equal to amount",
"tier-exact-amount": "Tier is exactly",
"tier-greater-than-or-equal-to-amount": "Tier is higher or equal to",
"months-exact-amount": "Months amount is exactly",
"months-greater-than-or-equal-to-amount": "Months amount is higher or equal to",
"gifts-exact-amount": "Gifts amount is exactly",
"gifts-greater-than-or-equal-to-amount": "Gifts amount is higher or equal to",
"very-rarely": "Very rarely",
"rarely": "Rarely",
"default": "Default",
Expand Down
2 changes: 2 additions & 0 deletions src/bot/api.ts
Expand Up @@ -109,6 +109,7 @@ const updateFollowerState = async(users: Readonly<Required<UserInterface>>[], us
event: 'follows',
name: user.username,
amount: 0,
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down Expand Up @@ -1876,6 +1877,7 @@ class API extends Core {
event: 'follows',
name: user.username,
amount: 0,
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down
3 changes: 2 additions & 1 deletion src/bot/database/entity/alert.ts
Expand Up @@ -6,6 +6,7 @@ import { ColumnNumericTransformer } from './_transformer';
export interface EmitData {
name: string;
amount: number;
tier: number;
recipient?: string;
currency: string;
monthsName: string;
Expand All @@ -19,7 +20,7 @@ export interface CommonSettingsInterface {
alertId?: string;
enabled: boolean;
title: string;
variantCondition: 'random' | 'exact' | 'gt-eq';
variantCondition: 'random' | 'exact' | 'gt-eq' | 'tier-exact' | 'tier-gt-eq';
variantAmount: number;
messageTemplate: string;
layout: '1' | '2' | '3' | '4' | '5';
Expand Down
1 change: 1 addition & 0 deletions src/bot/integrations/donationalerts.ts
Expand Up @@ -167,6 +167,7 @@ class Donationalerts extends Integration {
event: 'tips',
name: data.username.toLowerCase(),
amount: Number(data.amount.toFixed(2)),
tier: 0,
currency: data.currency,
monthsName: '',
message: data.message,
Expand Down
1 change: 1 addition & 0 deletions src/bot/integrations/qiwi.ts
Expand Up @@ -112,6 +112,7 @@ class Qiwi extends Integration {
event: 'tips',
name: username || 'Anonymous',
amount,
tier: 0,
currency: DONATION_CURRENCY,
monthsName: '',
message,
Expand Down
1 change: 1 addition & 0 deletions src/bot/integrations/streamelements.ts
Expand Up @@ -186,6 +186,7 @@ class StreamElements extends Integration {
event: 'tips',
name: username.toLowerCase(),
amount: Number(Number(eventData.data.amount).toFixed(2)),
tier: 0,
currency: DONATION_CURRENCY,
monthsName: '',
message,
Expand Down
1 change: 1 addition & 0 deletions src/bot/integrations/streamlabs.ts
Expand Up @@ -241,6 +241,7 @@ class Streamlabs extends Integration {
alerts.trigger({
event: 'tips',
name: event.from.toLowerCase(),
tier: 0,
amount: Number(parseFloat(event.amount).toFixed(2)),
currency: event.currency,
monthsName: '',
Expand Down
1 change: 1 addition & 0 deletions src/bot/integrations/tipeeestream.ts
Expand Up @@ -163,6 +163,7 @@ class TipeeeStream extends Integration {
event: 'tips',
name: username,
amount: Number(Number(amount).toFixed(2)),
tier: 0,
currency: donationCurrency,
monthsName: '',
message,
Expand Down
2 changes: 1 addition & 1 deletion src/bot/permissions.ts
Expand Up @@ -316,7 +316,7 @@ class Permissions extends Core {
amount = user.subscribeStreak;
break;
case 'subtier':
amount = user.subscribeTier === 'Prime' ? 1 : Number(user.subscribeTier);
amount = user.subscribeTier === 'Prime' ? 0 : Number(user.subscribeTier);
break;
case 'tips':
amount = user.tips.reduce((a, b) => (a + currency.exchange(b.amount, b.currency, currency.mainCurrency)), 0);
Expand Down
1 change: 1 addition & 0 deletions src/bot/pubsub.ts
Expand Up @@ -88,6 +88,7 @@ const connect = () => {
event: 'rewardredeems',
name: dataMessage.data.redemption.reward.title,
amount: 0,
tier: 0,
currency: '',
monthsName: '',
message: dataMessage.data.redemption.user_input,
Expand Down
2 changes: 2 additions & 0 deletions src/bot/registries/alerts.ts
Expand Up @@ -203,6 +203,7 @@ class Alerts extends Registry {

test(opts: { event: keyof Omit<AlertInterface, 'id' | 'updatedAt' | 'name' |'alertDelayInMs' | 'profanityFilterType' | 'loadStandardProfanityList' | 'customProfanityList'> }) {
const amount = Math.floor(Math.random() * 1000);
const tier = Math.floor(Math.random() * 4);
const messages = [
'Lorem ipsum dolor sit amet, https://www.google.com',
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam dictum tincidunt diam. Aliquam erat volutpat. Mauris tincidunt sem sed arcu. Etiam sapien elit, consequat eget, tristique non, venenatis quis, ante. Praesent id justo in neque elementum ultrices. Integer pellentesque quam vel velit. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Etiam commodo dui eget wisi. Cras pede libero, dapibus nec, pretium sit amet, tempor quis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.',
Expand All @@ -214,6 +215,7 @@ class Alerts extends Registry {
const data: EmitData = {
name: opts.event === 'cmdredeems' ? '!' + generateUsername() : generateUsername(),
amount,
tier,
recipient: generateUsername(),
currency: currency.mainCurrency,
monthsName: getLocalizedName(amount, translate('core.months')),
Expand Down
8 changes: 8 additions & 0 deletions src/bot/tmi.ts
Expand Up @@ -359,6 +359,7 @@ class TMI extends Core {
event: 'hosts',
name: username,
amount: Number(viewers),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down Expand Up @@ -393,6 +394,7 @@ class TMI extends Core {
event: 'raids',
name: message.parameters.login,
amount: Number(message.parameters.viewerCount),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down Expand Up @@ -469,6 +471,7 @@ class TMI extends Core {
event: 'subs',
name: username,
amount: 0,
tier: tier === 'Prime' ? 0 : Number(tier),
currency: '',
monthsName: '',
message: '',
Expand Down Expand Up @@ -547,6 +550,7 @@ class TMI extends Core {
event: 'resubs',
name: username,
amount: Number(subCumulativeMonths),
tier: tier === 'Prime' ? 0 : Number(tier),
currency: '',
monthsName: getLocalizedName(subCumulativeMonths, translate('core.months')),
message: messageFromUser,
Expand Down Expand Up @@ -585,6 +589,7 @@ class TMI extends Core {
event: 'subcommunitygifts',
name: username,
amount: Number(count),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down Expand Up @@ -657,6 +662,7 @@ class TMI extends Core {
name: username,
recipient,
amount: subCumulativeMonths,
tier: 0,
currency: '',
monthsName: getLocalizedName(subCumulativeMonths, translate('core.months')),
message: '',
Expand Down Expand Up @@ -741,6 +747,7 @@ class TMI extends Core {
recipient: username,
name: price.command,
amount: Number(userstate.bits),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand All @@ -757,6 +764,7 @@ class TMI extends Core {
event: 'cheers',
name: username,
amount: Number(userstate.bits),
tier: 0,
currency: '',
monthsName: '',
message: messageFromUser,
Expand Down
1 change: 1 addition & 0 deletions src/bot/webhooks.ts
Expand Up @@ -260,6 +260,7 @@ class Webhooks {
event: 'follows',
name: data.from_name,
amount: 0,
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand Down
6 changes: 6 additions & 0 deletions src/bot/widgets/eventlist.ts
Expand Up @@ -47,6 +47,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: 0,
tier: Number(values.tier === 'Prime' ? 0 : values.tier),
currency: '',
monthsName: '',
message: '',
Expand All @@ -59,6 +60,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: Number(values.viewers),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand All @@ -70,6 +72,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: Number(values.subCumulativeMonths),
tier: Number(values.tier === 'Prime' ? 0 : values.tier),
currency: '',
monthsName: getLocalizedName(values.subCumulativeMonths, translate('core.months')),
message: values.message,
Expand All @@ -81,6 +84,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: Number(values.count),
tier: 0,
currency: '',
monthsName: '',
message: '',
Expand All @@ -92,6 +96,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: Number(values.bits),
tier: 0,
currency: '',
monthsName: '',
message: values.message,
Expand All @@ -103,6 +108,7 @@ class EventList extends Widget {
event: eventType,
name: await users.getNameById(event.userId),
amount: Number(values.amount),
tier: 0,
currency: values.currency,
monthsName: '',
message: values.message,
Expand Down
20 changes: 19 additions & 1 deletion src/overlay/views/alertsRegistry.vue
Expand Up @@ -391,6 +391,20 @@ export default class AlertsRegistryOverlays extends Vue {
&& o.variantAmount <= emitData.amount
});

// search for tier-gt-eq variants
const possibleAlertsWithTierExactAmount = possibleAlerts.filter(o => {
return o.enabled
&& o.variantCondition === 'tier-exact'
&& o.variantAmount === emitData.tier
});

// search for tier-gt-eq variants
const possibleAlertsWithTierGtEqAmount = possibleAlerts.filter(o => {
return o.enabled
&& o.variantCondition === 'tier-gt-eq'
&& o.variantAmount <= emitData.tier
});

// search for random variants
let possibleAlertsWithRandomCount: (CommonSettingsInterface | AlertHostInterface | AlertTipInterface | AlertResubInterface)[] = [];
for (const alert of possibleAlerts) {
Expand All @@ -405,13 +419,17 @@ export default class AlertsRegistryOverlays extends Vue {
}
}

console.debug({possibleAlertsWithRandomCount, possibleAlertsWithExactAmount, possibleAlertsWithGtEqAmount})
console.debug({emitData, possibleAlerts, possibleAlertsWithRandomCount, possibleAlertsWithExactAmount, possibleAlertsWithGtEqAmount, possibleAlertsWithTierExactAmount, possibleAlertsWithTierGtEqAmount})

let alert: CommonSettingsInterface | AlertHostInterface | AlertTipInterface | AlertResubInterface | undefined;
if (possibleAlertsWithExactAmount.length > 0) {
alert = possibleAlertsWithExactAmount[Math.floor(Math.random() * possibleAlertsWithExactAmount.length)];
} else if (possibleAlertsWithGtEqAmount.length > 0) {
alert = possibleAlertsWithGtEqAmount[Math.floor(Math.random() * possibleAlertsWithGtEqAmount.length)];
} else if (possibleAlertsWithTierExactAmount.length > 0) {
alert = possibleAlertsWithTierExactAmount[Math.floor(Math.random() * possibleAlertsWithTierExactAmount.length)];
} else if (possibleAlertsWithTierGtEqAmount.length > 0) {
alert = possibleAlertsWithTierGtEqAmount[Math.floor(Math.random() * possibleAlertsWithTierGtEqAmount.length)];
} else {
alert = possibleAlertsWithRandomCount[Math.floor(Math.random() * possibleAlertsWithRandomCount.length)];
}
Expand Down
10 changes: 5 additions & 5 deletions src/panel/views/registries/alerts/alerts-edit.vue
Expand Up @@ -143,11 +143,11 @@
</b-col>
<b-col>
<b-card>
<form-follow v-if="selectedAlertType === 'cmdredeems' || selectedAlertType === 'follows' || selectedAlertType === 'subs' || selectedAlertType === 'subgifts' || selectedAlertType === 'subcommunitygifts'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-cheers v-else-if="selectedAlertType === 'cheers' || selectedAlertType === 'tips'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-resubs v-else-if="selectedAlertType === 'resubs'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-hosts v-else-if="selectedAlertType === 'hosts' || selectedAlertType === 'raids'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-reward v-else-if="selectedAlertType === 'rewardredeems'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-follow :event="selectedAlertType" v-if="selectedAlertType === 'cmdredeems' || selectedAlertType === 'follows' || selectedAlertType === 'subs' || selectedAlertType === 'subgifts' || selectedAlertType === 'subcommunitygifts'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-cheers :event="selectedAlertType" v-else-if="selectedAlertType === 'cheers' || selectedAlertType === 'tips'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-resubs :event="selectedAlertType" v-else-if="selectedAlertType === 'resubs'" :validationDate.sync="validationDate" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-hosts :event="selectedAlertType" v-else-if="selectedAlertType === 'hosts' || selectedAlertType === 'raids'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
<form-reward :event="selectedAlertType" v-else-if="selectedAlertType === 'rewardredeems'" :validationDate.sync="validationDate" :type="selectedAlertType" :alert.sync="selectedAlert" :isValid.sync="isValid[selectedAlertType][selectedAlertId]" @delete="deleteVariant(selectedAlertType, $event)"/>
</b-card>
</b-col>
</b-row>
Expand Down
5 changes: 4 additions & 1 deletion src/panel/views/registries/alerts/components/form-cheers.vue
Expand Up @@ -31,8 +31,10 @@
:label-for="'variant' + data.id"
>
<variant
:key="'variant-' + data.id"
:condition.sync="data.variantCondition"
:amount.sync="data.variantAmount"
:event="event"
:state="$v.data.variantAmount.$invalid && $v.data.variantAmount.$dirty ? false : null"
></variant>
</b-form-group>
Expand Down Expand Up @@ -286,7 +288,7 @@
</b-card-body>
</b-collapse>
</b-card>

<b-card no-body>
<b-card-header header-tag="header" class="p-1" role="tab">
<b-button block v-b-toggle="'accordion-2' + data.id" variant="light" class="text-left">{{translate('registry.alerts.message.setting')}}</b-button>
Expand Down Expand Up @@ -469,6 +471,7 @@ import { required, minValue } from 'vuelidate/lib/validators'
export default class AlertsEditCheersForm extends Vue {
@PropSync('alert') readonly data !: AlertTipInterface
@Prop() readonly index !: number
@Prop() readonly event !: string
@Prop() readonly validationDate !: number

theme = localStorage.getItem('theme') || get(this.$store.state, 'configuration.core.ui.theme', 'light');
Expand Down
4 changes: 3 additions & 1 deletion src/panel/views/registries/alerts/components/form-follow.vue
Expand Up @@ -31,9 +31,10 @@
:label-for="'variant' + data.id"
>
<variant
:key="'variant-' + data.id"
:condition.sync="data.variantCondition"
:amount.sync="data.variantAmount"
event="follow"
:event="event"
:state="$v.data.variantAmount.$invalid && $v.data.variantAmount.$dirty ? false : null"
></variant>
</b-form-group>
Expand Down Expand Up @@ -332,6 +333,7 @@ import { required, minValue } from 'vuelidate/lib/validators'
export default class AlertsEditFollowForm extends Vue {
@PropSync('alert') data !: CommonSettingsInterface
@Prop() readonly index !: number
@Prop() readonly event !: string
@Prop() readonly validationDate !: number

theme = localStorage.getItem('theme') || get(this.$store.state, 'configuration.core.ui.theme', 'light');
Expand Down
3 changes: 3 additions & 0 deletions src/panel/views/registries/alerts/components/form-hosts.vue
Expand Up @@ -31,8 +31,10 @@
:label-for="'variant' + data.id"
>
<variant
:key="'variant-' + data.id"
:condition.sync="data.variantCondition"
:amount.sync="data.variantAmount"
:event="event"
:state="$v.data.variantAmount.$invalid && $v.data.variantAmount.$dirty ? false : null"
></variant>
</b-form-group>
Expand Down Expand Up @@ -342,6 +344,7 @@ export default class AlertsEditHostForm extends Vue {
@PropSync('alert') readonly data !: AlertHostInterface
@PropSync('type') readonly alertType !: ['hosts', 'raids']
@Prop() readonly index !: number
@Prop() readonly event !: string
@Prop() readonly validationDate !: number

theme = localStorage.getItem('theme') || get(this.$store.state, 'configuration.core.ui.theme', 'light');
Expand Down
3 changes: 3 additions & 0 deletions src/panel/views/registries/alerts/components/form-resubs.vue
Expand Up @@ -31,8 +31,10 @@
:label-for="'variant' + data.id"
>
<variant
:key="'variant-' + data.id"
:condition.sync="data.variantCondition"
:amount.sync="data.variantAmount"
:event="event"
:state="$v.data.variantAmount.$invalid && $v.data.variantAmount.$dirty ? false : null"
></variant>
</b-form-group>
Expand Down Expand Up @@ -455,6 +457,7 @@ import { required, minValue } from 'vuelidate/lib/validators'
export default class AlertsEditFollowForm extends Vue {
@PropSync('alert') readonly data !: AlertResubInterface
@Prop() readonly index !: number
@Prop() readonly event !: string
@Prop() readonly validationDate !: number

theme = localStorage.getItem('theme') || get(this.$store.state, 'configuration.core.ui.theme', 'light');
Expand Down