mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-08 09:30:44 +01:00
Compare commits
9 Commits
33fbc4c446
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c81f079e8 | |||
| 75831a5406 | |||
| eddad6454d | |||
| 8ac15a1687 | |||
| 36c542b822 | |||
| b67d00bcd7 | |||
| 81a51a3d0d | |||
| 90756c884c | |||
| df501c27d7 |
41
.github/workflows/build_docker_image.yml
vendored
41
.github/workflows/build_docker_image.yml
vendored
@@ -3,18 +3,16 @@ name: Build docker image
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- "main"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build-Docker-Image:
|
Build-Docker-Image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
-
|
- name: Set up Docker Buildx
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- id: repository_name
|
- id: repository_name
|
||||||
@@ -22,16 +20,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
string: ${{ github.repository }}
|
string: ${{ github.repository }}
|
||||||
|
|
||||||
-
|
- name: Login to ghcr.io
|
||||||
name: Login to ghcr.io
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
-
|
- name: Build and push
|
||||||
name: Build and push
|
|
||||||
id: docker_build
|
id: docker_build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
env:
|
env:
|
||||||
@@ -43,32 +39,7 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
file: ./docker/build.dockerfile
|
file: ./docker/build.dockerfile
|
||||||
|
|
||||||
-
|
- name: Invoke deployment hook
|
||||||
name: Invoke deployment hook (game_list)
|
|
||||||
uses: joelwmale/webhook-action@master
|
uses: joelwmale/webhook-action@master
|
||||||
with:
|
with:
|
||||||
url: ${{ secrets.WEBHOOK_URL }}
|
url: ${{ secrets.WEBHOOK_URL }}
|
||||||
|
|
||||||
-
|
|
||||||
name: Invoke deployment hook (twitch_webhook)
|
|
||||||
uses: joelwmale/webhook-action@master
|
|
||||||
with:
|
|
||||||
url: ${{ secrets.WEBHOOK_URL_2 }}
|
|
||||||
|
|
||||||
-
|
|
||||||
name: Invoke deployment hook (temporal_worker)
|
|
||||||
uses: joelwmale/webhook-action@master
|
|
||||||
with:
|
|
||||||
url: ${{ secrets.WEBHOOK_URL_3 }}
|
|
||||||
|
|
||||||
# -
|
|
||||||
# name: Invoke deployment hook (stream_notifications)
|
|
||||||
# uses: joelwmale/webhook-action@master
|
|
||||||
# with:
|
|
||||||
# url: ${{ secrets.WEBHOOK_URL_4 }}
|
|
||||||
|
|
||||||
# -
|
|
||||||
# name: Invoke deployment hook (web_app)
|
|
||||||
# uses: joelwmale/webhook-action@master
|
|
||||||
# with:
|
|
||||||
# url: ${{ secrets.WEBHOOK_URL_5 }}
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ async def main():
|
|||||||
twitch_activities.on_stream_state_change_activity,
|
twitch_activities.on_stream_state_change_activity,
|
||||||
twitch_activities.check_streams_states,
|
twitch_activities.check_streams_states,
|
||||||
twitch_activities.on_redemption_reward_add_activity,
|
twitch_activities.on_redemption_reward_add_activity,
|
||||||
|
twitch_activities.on_channel_update_activity,
|
||||||
],
|
],
|
||||||
workflow_runner=UnsandboxedWorkflowRunner()
|
workflow_runner=UnsandboxedWorkflowRunner()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from .message_proc import on_message_activity
|
from .message_proc import on_message_activity
|
||||||
from .on_state_change import on_stream_state_change_activity
|
from .on_state_change import on_stream_state_change_activity, on_channel_update_activity
|
||||||
from .redemption_reward import on_redemption_reward_add_activity
|
from .redemption_reward import on_redemption_reward_add_activity
|
||||||
from .state_checker import check_streams_states
|
from .state_checker import check_streams_states
|
||||||
|
|
||||||
@@ -9,4 +9,5 @@ __all__ = [
|
|||||||
"on_stream_state_change_activity",
|
"on_stream_state_change_activity",
|
||||||
"check_streams_states",
|
"check_streams_states",
|
||||||
"on_redemption_reward_add_activity",
|
"on_redemption_reward_add_activity",
|
||||||
|
"on_channel_update_activity",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from temporalio import activity
|
from temporalio import activity
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from applications.twitch_webhook.state import State, EventType
|
from twitchAPI.helper import first
|
||||||
|
|
||||||
|
from applications.twitch_webhook.state import State, EventType, UpdateEvent
|
||||||
from applications.twitch_webhook.watcher import StateWatcher
|
from applications.twitch_webhook.watcher import StateWatcher
|
||||||
|
from applications.twitch_webhook.twitch.authorize import authorize
|
||||||
|
|
||||||
|
|
||||||
class OnStreamStateChangeActivity(BaseModel):
|
class OnStreamStateChangeActivity(BaseModel):
|
||||||
@@ -21,3 +26,33 @@ async def on_stream_state_change_activity(
|
|||||||
data.event_type,
|
data.event_type,
|
||||||
data.new_state,
|
data.new_state,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class OnChannelUpdateActivity(BaseModel):
|
||||||
|
event: UpdateEvent
|
||||||
|
event_type: EventType
|
||||||
|
|
||||||
|
|
||||||
|
@activity.defn
|
||||||
|
async def on_channel_update_activity(
|
||||||
|
data: OnChannelUpdateActivity
|
||||||
|
):
|
||||||
|
twitch = await authorize(data.event.broadcaster_user_login)
|
||||||
|
|
||||||
|
stream = await first(twitch.get_streams(
|
||||||
|
user_id=[data.event.broadcaster_user_id])
|
||||||
|
)
|
||||||
|
if stream is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
await on_stream_state_change_activity(
|
||||||
|
OnStreamStateChangeActivity(
|
||||||
|
streamer_id=int(data.event.broadcaster_user_id),
|
||||||
|
event_type=data.event_type,
|
||||||
|
new_state=State(
|
||||||
|
title=data.event.title,
|
||||||
|
category=data.event.category_name,
|
||||||
|
last_live_at=datetime.now(timezone.utc)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -308,6 +308,8 @@ class MessagesProc:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def on_message(cls, received_as: str, event: MessageEvent):
|
async def on_message(cls, received_as: str, event: MessageEvent):
|
||||||
|
return
|
||||||
|
|
||||||
if event.chatter_user_name in cls.FULL_IGNORED_USER_LOGINS:
|
if event.chatter_user_name in cls.FULL_IGNORED_USER_LOGINS:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
from datetime import datetime, timezone, timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from temporalio import workflow
|
from temporalio import workflow
|
||||||
|
|
||||||
from twitchAPI.helper import first
|
|
||||||
|
|
||||||
from applications.twitch_webhook.state import UpdateEvent, EventType, State
|
|
||||||
from applications.twitch_webhook.twitch.authorize import authorize
|
|
||||||
from applications.twitch_webhook.activities.on_state_change import on_stream_state_change_activity, OnStreamStateChangeActivity
|
|
||||||
from applications.temporal_worker.queues import MAIN_QUEUE
|
from applications.temporal_worker.queues import MAIN_QUEUE
|
||||||
|
from applications.twitch_webhook.activities.on_state_change import OnChannelUpdateActivity, on_channel_update_activity
|
||||||
|
from applications.twitch_webhook.state import UpdateEvent, EventType
|
||||||
|
|
||||||
|
|
||||||
@workflow.defn
|
@workflow.defn
|
||||||
@@ -18,23 +15,12 @@ class OnChannelUpdateWorkflow:
|
|||||||
event: UpdateEvent,
|
event: UpdateEvent,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
):
|
):
|
||||||
twitch = await authorize(event.broadcaster_user_login)
|
|
||||||
|
|
||||||
stream = await first(twitch.get_streams(user_id=[event.broadcaster_user_id]))
|
|
||||||
if stream is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
await workflow.start_activity(
|
await workflow.start_activity(
|
||||||
on_stream_state_change_activity,
|
on_channel_update_activity,
|
||||||
OnStreamStateChangeActivity(
|
OnChannelUpdateActivity(
|
||||||
int(event.broadcaster_user_id),
|
event=event,
|
||||||
event_type,
|
event_type=event_type,
|
||||||
State(
|
|
||||||
title=event.title,
|
|
||||||
category=event.category_name,
|
|
||||||
last_live_at=datetime.now(timezone.utc)
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
task_queue=MAIN_QUEUE,
|
task_queue=MAIN_QUEUE,
|
||||||
schedule_to_close_timeout=timedelta(minutes=1)
|
start_to_close_timeout=timedelta(minutes=1),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ class OnMessageWorkflow:
|
|||||||
on_message_activity,
|
on_message_activity,
|
||||||
message,
|
message,
|
||||||
task_queue=MAIN_QUEUE,
|
task_queue=MAIN_QUEUE,
|
||||||
schedule_to_close_timeout=timedelta(minutes=1)
|
schedule_to_close_timeout=timedelta(minutes=5)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from applications.temporal_worker.queues import MAIN_QUEUE
|
|||||||
@workflow.defn
|
@workflow.defn
|
||||||
class OnStreamOnlineWorkflow:
|
class OnStreamOnlineWorkflow:
|
||||||
@workflow.run
|
@workflow.run
|
||||||
async def run(self, broadcaster_user_id: str, event_type: EventType):
|
async def run(self, broadcaster_user_id: str | int, event_type: EventType):
|
||||||
await workflow.start_activity(
|
await workflow.start_activity(
|
||||||
on_stream_state_change_activity,
|
on_stream_state_change_activity,
|
||||||
OnStreamStateChangeActivity(
|
OnStreamStateChangeActivity(
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
from httpx import Client
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
from httpx import Client
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
VAULT_HOST: str
|
VAULT_HOST: str
|
||||||
@@ -35,6 +34,8 @@ class Config(BaseModel):
|
|||||||
|
|
||||||
OPENAI_API_KEY: str
|
OPENAI_API_KEY: str
|
||||||
|
|
||||||
|
TEMPOLAR_URL: str = "temporal:7233"
|
||||||
|
|
||||||
|
|
||||||
def get_config() -> Config:
|
def get_config() -> Config:
|
||||||
settings = Settings() # type: ignore
|
settings = Settings() # type: ignore
|
||||||
@@ -45,7 +46,7 @@ def get_config() -> Config:
|
|||||||
headers={
|
headers={
|
||||||
"X-Vault-Token": settings.VAULT_TOKEN,
|
"X-Vault-Token": settings.VAULT_TOKEN,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from temporalio.client import Client
|
from temporalio.client import Client
|
||||||
from temporalio.contrib.pydantic import pydantic_data_converter
|
from temporalio.contrib.pydantic import pydantic_data_converter
|
||||||
|
|
||||||
|
from core.config import config
|
||||||
|
|
||||||
|
|
||||||
async def get_client() -> Client:
|
async def get_client() -> Client:
|
||||||
return await Client.connect(
|
return await Client.connect(
|
||||||
"temporal:7233",
|
config.TEMPOLAR_URL, namespace="default", data_converter=pydantic_data_converter
|
||||||
namespace="default",
|
|
||||||
data_converter=pydantic_data_converter
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user