Skip to content

Commit

Permalink
feat: add ban to eventlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Aug 24, 2023
1 parent 18a8adb commit 8d1b455
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 16 deletions.
8 changes: 8 additions & 0 deletions apps/api/internal/impl_protected/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (c *Dashboard) convertType(t model.ChannelEventListItemType) dashboard.Even
return dashboard.EventType_CHAT_CLEAR
case model.ChannelEventListItemTypeRedemptionCreated:
return dashboard.EventType_REDEMPTION_CREATED
case model.ChannelEventListItemTypeChannelBan:
return dashboard.EventType_CHANNEL_BAN
default:
return 0
}
Expand Down Expand Up @@ -233,6 +235,12 @@ func (c *Dashboard) GetDashboardEventsList(ctx context.Context, _ *emptypb.Empty
FirstUserMessageUserName: entity.Data.FirstUserMessageUserName,
FirstUserMessageUserDisplayName: entity.Data.FirstUserMessageUserDisplayName,
FirstUserMessageMessage: entity.Data.FirstUserMessageMessage,
BanReason: entity.Data.BanReason,
BanEndsInMinutes: entity.Data.BanEndsInMinutes,
BannedUserName: entity.Data.BannedUserName,
BannedUserLogin: entity.Data.BannedUserLogin,
ModeratorName: entity.Data.ModeratorName,
ModeratorDisplayName: entity.Data.ModeratorDisplayName,
},
CreatedAt: fmt.Sprint(entity.CreatedAt.UnixMilli()),
}
Expand Down
16 changes: 2 additions & 14 deletions apps/events/internal/grpc_impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package grpc_impl

import (
"context"
"fmt"
"math"
"strings"
"time"

"github.com/samber/lo"
"github.com/satont/twir/apps/events/internal"
model "github.com/satont/twir/libs/gomodels"
"github.com/satont/twir/libs/grpc/generated/events"
"google.golang.org/protobuf/types/known/emptypb"
"strings"
)

type EventsGrpcImplementation struct {
Expand Down Expand Up @@ -541,9 +537,6 @@ func (c *EventsGrpcImplementation) ChannelBan(
_ context.Context,
msg *events.ChannelBanMessage,
) (*emptypb.Empty, error) {
t, _ := time.Parse(time.RFC3339, msg.EndsAt)
banEndsIn := t.Sub(time.Now().UTC())

go c.processEvent(
msg.BaseInfo.ChannelId,
internal.Data{
Expand All @@ -552,12 +545,7 @@ func (c *EventsGrpcImplementation) ChannelBan(
ModeratorDisplayName: msg.ModeratorUserName,
ModeratorName: msg.ModeratorUserLogin,
BanReason: msg.Reason,
BanEndsInMinutes: lo.If(msg.IsPermanent, "permanent").Else(
fmt.Sprintf(
"%v",
math.Round(banEndsIn.Minutes()),
),
),
BanEndsInMinutes: msg.EndsAt,
},
model.EventChannelBan,
)
Expand Down
35 changes: 34 additions & 1 deletion apps/eventsub/internal/handler/ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ package handler

import (
"context"
"fmt"
"github.com/dnsge/twitch-eventsub-bindings"
"github.com/google/uuid"
"github.com/samber/lo"
model "github.com/satont/twir/libs/gomodels"
"github.com/satont/twir/libs/grpc/generated/events"
"math"
"time"
)

func (c *Handler) handleBan(
_ *eventsub_bindings.ResponseHeaders,
event *eventsub_bindings.EventChannelBan,
) {
t, _ := time.Parse(time.RFC3339, event.EndsAt)
banEndsIn := t.Sub(time.Now().UTC())
endsAt := lo.If(event.IsPermanent, "permanent").Else(
fmt.Sprintf(
"%v",
math.Round(banEndsIn.Minutes()),
),
)

c.services.Grpc.Events.ChannelBan(
context.TODO(), &events.ChannelBanMessage{
BaseInfo: &events.BaseInfo{
Expand All @@ -22,8 +37,26 @@ func (c *Handler) handleBan(
ModeratorUserName: event.ModeratorUserName,
ModeratorUserLogin: event.ModeratorUserLogin,
Reason: event.Reason,
EndsAt: event.EndsAt,
EndsAt: endsAt,
IsPermanent: event.IsPermanent,
},
)

c.services.Gorm.Create(
&model.ChannelsEventsListItem{
ID: uuid.New().String(),
ChannelID: event.BroadcasterUserID,
UserID: event.UserID,
Type: model.ChannelEventListItemTypeChannelBan,
CreatedAt: time.Now().UTC(),
Data: &model.ChannelsEventsListItemData{
BanReason: event.Reason,
BanEndsInMinutes: endsAt,
BannedUserLogin: event.UserLogin,
BannedUserName: event.UserName,
ModeratorDisplayName: event.ModeratorUserName,
ModeratorName: event.ModeratorUserLogin,
},
},
)
}
17 changes: 16 additions & 1 deletion frontend/dashboard/src/components/dashboard/events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NScrollbar, NResult, NSpin, NButton, NPopselect } from 'naive-ui';
import { computed } from 'vue';
import Card from './card.vue';
import Ban from './events/ban.vue';
import ChatClear from './events/chatClear.vue';
import Donate from './events/donate.vue';
import FirstUserMessage from './events/firstUserMessage.vue';
Expand All @@ -21,7 +22,7 @@ import { useDashboardEvents } from '@/api/index.js';
const { data: events, isLoading, refetch } = useDashboardEvents();
useIntervalFn(refetch, 1000);
const enabledEvents = useLocalStorage<number[]>('twirEventsWidgetFilter', Object.values(EventType).filter(t => typeof t === 'number') as number[]);
const enabledEvents = useLocalStorage<number[]>('twirEventsWidgetFilterv2', Object.values(EventType).filter(t => typeof t === 'number') as number[]);
const filteredEvents = computed(() => events.value?.events.filter(e => {
return enabledEvents.value.includes(e.type);
}) ?? []);
Expand Down Expand Up @@ -63,6 +64,10 @@ const enabledEventsOptions = [
label: 'Reward activated',
value: 8,
},
{
label: 'Ban/timeout',
value: 9,
},
];
</script>

Expand Down Expand Up @@ -146,6 +151,16 @@ const enabledEventsOptions = [
:user-display-name="event.data!.redemptionUserDisplayName"
:cost="event.data!.redemptionCost"
/>
<Ban
v-if="event.type === EventType.CHANNEL_BAN"
:created-at="event.createdAt"
:ends-in="event.data!.banEndsInMinutes"
:moderator-user-login="event.data!.moderatorName"
:moderator-user-name="event.data!.moderatorDisplayName"
:reason="event.data!.banReason"
:user-login="event.data!.bannedUserLogin"
:user-name="event.data!.bannedUserName"
/>
</template>
</TransitionGroup>
</n-scrollbar>
Expand Down
29 changes: 29 additions & 0 deletions frontend/dashboard/src/components/dashboard/events/ban.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts" setup>
import { IconUserCancel } from '@tabler/icons-vue';
import Base from './base.vue';
import { createUserName } from '@/helpers';
defineProps<{
userName: string,
userLogin: string
createdAt: string,
reason: string
moderatorUserName: string
moderatorUserLogin: string
endsIn: string
}>();
</script>

<template>
<Base :icon="IconUserCancel" :created-at="createdAt">
<template #leftContent>
<div style="display: flex; flex-direction: column">
<span>{{ createUserName(moderatorUserLogin, moderatorUserName) }} <b style="font-size: 11px">banned</b> {{ createUserName(userLogin, userName) }} for {{ endsIn }}</span>
<span style="font-size: 11px">{{ reason }}</span>
</div>
</template>
</Base>
</template>
11 changes: 11 additions & 0 deletions libs/gomodels/channels_events_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
ChannelEventListItemTypeFirstUserMessage = "FIRST_USER_MESSAGE"
ChannelEventListItemTypeChatClear = "CHAT_CLEAR"
ChannelEventListItemTypeRedemptionCreated = "REDEMPTION_CREATED"
ChannelEventListItemTypeChannelBan = "CHANNEL_BAN"
)

type ChannelsEventsListItemData struct {
Expand Down Expand Up @@ -71,6 +72,16 @@ type ChannelsEventsListItemData struct {
FirstUserMessageUserName string `json:"firstUserMessageUserName,omitempty"`
FirstUserMessageUserDisplayName string `json:"firstUserMessageUserDisplayName,omitempty"`
FirstUserMessageMessage string `json:"firstUserMessageMessage,omitempty"`

//
ModeratorName string `json:"moderatorName"`
ModeratorDisplayName string `json:"moderatorDisplayName"`

//
BanReason string `json:"banReason"`
BanEndsInMinutes string `json:"banEndsInMinutes"`
BannedUserName string `json:"bannedUserName"`
BannedUserLogin string `json:"bannedUserLogin"`
}

func (a ChannelsEventsListItemData) Value() (driver.Value, error) {
Expand Down
9 changes: 9 additions & 0 deletions libs/grpc/protos/api/dashboard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum EventType {
FIRST_USER_MESSAGE = 6;
CHAT_CLEAR = 7;
REDEMPTION_CREATED = 8;
CHANNEL_BAN = 9;
}

message EventData {
Expand Down Expand Up @@ -72,6 +73,14 @@ message EventData {
string first_user_message_user_name = 28;
string first_user_message_user_display_name = 29;
string first_user_message_message = 30;

string ban_reason = 31;
string ban_ends_in_minutes = 32;
string banned_user_name = 33;
string banned_user_login = 34;

string moderator_name = 35;
string moderator_display_name = 36;
}

message DashboardEventsList {
Expand Down

0 comments on commit 8d1b455

Please sign in to comment.