fix (alerts): Account for string userid.
This commit is contained in:
26
cog.py
26
cog.py
@@ -115,7 +115,7 @@ class AlertCog(LionCog):
|
|||||||
# Note we set page size to 100
|
# Note we set page size to 100
|
||||||
# So we should never get repeat or missed streams
|
# So we should never get repeat or missed streams
|
||||||
# Since we can request a max of 100 userids anyway.
|
# Since we can request a max of 100 userids anyway.
|
||||||
streaming[stream.user_id] = stream
|
streaming[int(stream.user_id)] = stream
|
||||||
|
|
||||||
started = set(streaming.keys()).difference(self.live_streams.keys())
|
started = set(streaming.keys()).difference(self.live_streams.keys())
|
||||||
ended = set(self.live_streams.keys()).difference(streaming.keys())
|
ended = set(self.live_streams.keys()).difference(streaming.keys())
|
||||||
@@ -123,9 +123,9 @@ class AlertCog(LionCog):
|
|||||||
for streamerid in started:
|
for streamerid in started:
|
||||||
stream = streaming[streamerid]
|
stream = streaming[streamerid]
|
||||||
stream_data = await self.data.Stream.create(
|
stream_data = await self.data.Stream.create(
|
||||||
streamerid=stream.user_id,
|
streamerid=int(stream.user_id),
|
||||||
start_at=stream.started_at,
|
start_at=stream.started_at,
|
||||||
twitch_stream_id=stream.id,
|
twitch_stream_id=int(stream.id),
|
||||||
game_name=stream.game_name,
|
game_name=stream.game_name,
|
||||||
title=stream.title,
|
title=stream.title,
|
||||||
)
|
)
|
||||||
@@ -143,7 +143,7 @@ class AlertCog(LionCog):
|
|||||||
|
|
||||||
async def on_stream_start(self, stream_data):
|
async def on_stream_start(self, stream_data):
|
||||||
# Get channel subscriptions listening for this streamer
|
# Get channel subscriptions listening for this streamer
|
||||||
uid = stream_data.streamerid
|
uid = int(stream_data.streamerid)
|
||||||
logger.info(f"Streamer <uid:{uid}> started streaming! {stream_data=}")
|
logger.info(f"Streamer <uid:{uid}> started streaming! {stream_data=}")
|
||||||
subbed = await self.data.AlertChannel.fetch_where(streamerid=uid)
|
subbed = await self.data.AlertChannel.fetch_where(streamerid=uid)
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ class AlertCog(LionCog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Build message
|
# Build message
|
||||||
streamer = await self.data.Streamer.fetch(stream_data.streamerid)
|
streamer = await self.data.Streamer.fetch(int(stream_data.streamerid))
|
||||||
if not streamer:
|
if not streamer:
|
||||||
# Streamer was deleted while handling the alert
|
# Streamer was deleted while handling the alert
|
||||||
# Just quietly ignore
|
# Just quietly ignore
|
||||||
@@ -235,7 +235,7 @@ class AlertCog(LionCog):
|
|||||||
|
|
||||||
# Store sent alert
|
# Store sent alert
|
||||||
alert = await self.data.StreamAlert.create(
|
alert = await self.data.StreamAlert.create(
|
||||||
streamid=stream_data.streamid,
|
streamid=int(stream_data.streamid),
|
||||||
subscriptionid=subscription.subscriptionid,
|
subscriptionid=subscription.subscriptionid,
|
||||||
sent_at=utc_now(),
|
sent_at=utc_now(),
|
||||||
messageid=message.id
|
messageid=message.id
|
||||||
@@ -246,7 +246,7 @@ class AlertCog(LionCog):
|
|||||||
|
|
||||||
async def on_stream_end(self, stream_data):
|
async def on_stream_end(self, stream_data):
|
||||||
# Get channel subscriptions listening for this streamer
|
# Get channel subscriptions listening for this streamer
|
||||||
uid = stream_data.streamerid
|
uid = int(stream_data.streamerid)
|
||||||
logger.info(f"Streamer <uid:{uid}> stopped streaming! {stream_data=}")
|
logger.info(f"Streamer <uid:{uid}> stopped streaming! {stream_data=}")
|
||||||
subbed = await self.data.AlertChannel.fetch_where(streamerid=uid)
|
subbed = await self.data.AlertChannel.fetch_where(streamerid=uid)
|
||||||
|
|
||||||
@@ -269,8 +269,8 @@ class AlertCog(LionCog):
|
|||||||
async def sub_resolve(self, subscription, stream_data):
|
async def sub_resolve(self, subscription, stream_data):
|
||||||
# Check if there is a current active alert to resolve
|
# Check if there is a current active alert to resolve
|
||||||
alerts = await self.data.StreamAlert.fetch_where(
|
alerts = await self.data.StreamAlert.fetch_where(
|
||||||
streamid=stream_data.streamid,
|
streamid=int(stream_data.streamid),
|
||||||
subscriptionid=subscription.subscriptionid,
|
subscriptionid=int(subscription.subscriptionid),
|
||||||
)
|
)
|
||||||
if not alerts:
|
if not alerts:
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -322,7 +322,7 @@ class AlertCog(LionCog):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Edit message with custom arguments
|
# Edit message with custom arguments
|
||||||
streamer = await self.data.Streamer.fetch(stream_data.streamerid)
|
streamer = await self.data.Streamer.fetch(int(stream_data.streamerid))
|
||||||
formatter = await edit_setting.generate_formatter(self.bot, stream_data, streamer)
|
formatter = await edit_setting.generate_formatter(self.bot, stream_data, streamer)
|
||||||
formatted = await formatter(edit_setting.value)
|
formatted = await formatter(edit_setting.value)
|
||||||
args = edit_setting.value_to_args(subscription.subscriptionid, formatted)
|
args = edit_setting.value_to_args(subscription.subscriptionid, formatted)
|
||||||
@@ -400,7 +400,7 @@ class AlertCog(LionCog):
|
|||||||
|
|
||||||
# Create streamer data if it doesn't already exist
|
# Create streamer data if it doesn't already exist
|
||||||
streamer_data = await self.data.Streamer.fetch_or_create(
|
streamer_data = await self.data.Streamer.fetch_or_create(
|
||||||
tw_user.id,
|
int(tw_user.id),
|
||||||
login_name=tw_user.login,
|
login_name=tw_user.login,
|
||||||
display_name=tw_user.display_name,
|
display_name=tw_user.display_name,
|
||||||
)
|
)
|
||||||
@@ -418,8 +418,10 @@ class AlertCog(LionCog):
|
|||||||
self.watching[streamer_data.userid] = streamer_data
|
self.watching[streamer_data.userid] = streamer_data
|
||||||
|
|
||||||
# Open AlertEditorUI for the new subscription
|
# Open AlertEditorUI for the new subscription
|
||||||
# TODO
|
|
||||||
await ctx.reply("StreamAlert Created.")
|
await ctx.reply("StreamAlert Created.")
|
||||||
|
ui = AlertEditorUI(bot=self.bot, sub_data=sub_data, callerid=ctx.author.id)
|
||||||
|
await ui.run(ctx.interaction)
|
||||||
|
await ui.wait()
|
||||||
|
|
||||||
async def alert_acmpl(self, interaction: discord.Interaction, partial: str):
|
async def alert_acmpl(self, interaction: discord.Interaction, partial: str):
|
||||||
if not interaction.guild:
|
if not interaction.guild:
|
||||||
|
|||||||
Reference in New Issue
Block a user