mirror of
https://github.com/GaMeNu/HFCNotificator.git
synced 2024-11-16 15:24:51 +02:00
Apparently the bot didn't really send alerts after v2.2.2...?
Well that's fixed now
This commit is contained in:
parent
882924407f
commit
6734ba1ab4
@ -79,7 +79,7 @@ class Alert:
|
|||||||
|
|
||||||
class AlertEmbed:
|
class AlertEmbed:
|
||||||
|
|
||||||
def __init__(self, alert: Alert | dict, district: db_access.District | str):
|
def __init__(self, alert: Alert | dict, district: db_access.AreaDistrict | str):
|
||||||
"""
|
"""
|
||||||
Initiating the AlertEmbed class directly is equivalent to AlertEmbed.generic_alert, but is not recommended.
|
Initiating the AlertEmbed class directly is equivalent to AlertEmbed.generic_alert, but is not recommended.
|
||||||
|
|
||||||
@ -92,28 +92,34 @@ class AlertEmbed:
|
|||||||
else:
|
else:
|
||||||
self.alert = alert
|
self.alert = alert
|
||||||
|
|
||||||
self.embed.title = f'התראה ב{self.district}'
|
self.embed.title = f'התראה ב{self.district.name}'
|
||||||
|
|
||||||
|
if isinstance(self.district, AreaDistrict):
|
||||||
|
self.embed.add_field(name=self.alert.title, value=f'איזור {self.district.area.name}')
|
||||||
|
else:
|
||||||
|
self.embed.add_field(name=self.alert.title, value=f'איזור {self.district}')
|
||||||
|
|
||||||
self.embed.add_field(name='נכון ל', value=datetime.datetime.now().strftime("%H:%M:%S\n%d/%m/%Y"), inline=False)
|
self.embed.add_field(name='נכון ל', value=datetime.datetime.now().strftime("%H:%M:%S\n%d/%m/%Y"), inline=False)
|
||||||
self.embed.add_field(name='מידע נוסף', value=self.alert.description)
|
self.embed.add_field(name='מידע נוסף', value=self.alert.description)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generic_alert(cls, alert: Alert | dict, district: db_access.District | str) -> Self:
|
def generic_alert(cls, alert: Alert | dict, district: db_access.AreaDistrict | str) -> Self:
|
||||||
ret_alem = cls(alert, district)
|
ret_alem = cls(alert, district)
|
||||||
return ret_alem
|
return ret_alem
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def missile_alert(cls, alert: Alert | dict, district: db_access.District | str) -> Self:
|
def missile_alert(cls, alert: Alert | dict, district: db_access.AreaDistrict | str) -> Self:
|
||||||
ret_alem = cls.generic_alert(alert, district)
|
ret_alem = cls.generic_alert(alert, district)
|
||||||
|
|
||||||
if (not isinstance(district, str)) and (district.migun_time is not None):
|
if (not isinstance(district, str)) and (district.migun_time is not None):
|
||||||
ret_alem.embed.set_field_at(index=1, name='זמן מיגון', value=f'{district.migun_time} שניות', inline=False)
|
ret_alem.embed.insert_field_at(index=1, name='זמן מיגון', value=f'{district.migun_time} שניות', inline=False)
|
||||||
return ret_alem
|
return ret_alem
|
||||||
|
|
||||||
ret_alem.embed.set_field_at(index=1, name='זמן מיגון', value='שגיאה באחזרת המידע', inline=False)
|
ret_alem.embed.insert_field_at(index=1, name='זמן מיגון', value='שגיאה באחזרת המידע', inline=False)
|
||||||
return ret_alem
|
return ret_alem
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def auto_alert(cls, alert: Alert | dict, district: db_access.District | str) -> Self:
|
def auto_alert(cls, alert: Alert | dict, district: db_access.AreaDistrict | str) -> Self:
|
||||||
"""
|
"""
|
||||||
Tired of having to CHOOSE an alert type all the time? Well this is JUST for you!
|
Tired of having to CHOOSE an alert type all the time? Well this is JUST for you!
|
||||||
|
|
||||||
@ -302,21 +308,21 @@ class Notificator(commands.Cog):
|
|||||||
district_data = self.db.get_district_by_name(district)
|
district_data = self.db.get_district_by_name(district)
|
||||||
|
|
||||||
if district_data is not None:
|
if district_data is not None:
|
||||||
embed_ls.append(AlertEmbed.auto_alert(alert_data, district_data))
|
embed_ls.append(AlertEmbed.auto_alert(alert_data, AreaDistrict.from_district(district_data, self.db.get_area(district_data.area_id))))
|
||||||
else:
|
else:
|
||||||
embed_ls.append(AlertEmbed.auto_alert(alert_data, district))
|
embed_ls.append(AlertEmbed.auto_alert(alert_data, district))
|
||||||
|
|
||||||
for channel_tup in self.db.get_all_channels():
|
for channel_tup in self.db.get_all_channels():
|
||||||
channel = Channel.from_tuple(channel_tup)
|
channel = Channel.from_tuple(channel_tup)
|
||||||
if channel.server_id is not None:
|
if channel.server_id is not None:
|
||||||
dc_ch = self.bot.get_channel(channel.district_id)
|
dc_ch = self.bot.get_channel(channel.id)
|
||||||
else:
|
else:
|
||||||
dc_ch = self.bot.get_user(channel.district_id)
|
dc_ch = self.bot.get_user(channel.id)
|
||||||
|
|
||||||
for emb in embed_ls:
|
for emb in embed_ls:
|
||||||
if dc_ch is None:
|
if dc_ch is None:
|
||||||
continue
|
continue
|
||||||
if len(channel.locations) != 0 and emb.district_id not in channel.locations:
|
if len(channel.locations) != 0 and emb.district.district_id not in channel.locations:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
await dc_ch.send(embed=emb.embed, view=self.hfc_button_view())
|
await dc_ch.send(embed=emb.embed, view=self.hfc_button_view())
|
||||||
|
10
db_access.py
10
db_access.py
@ -38,6 +38,16 @@ class District:
|
|||||||
return self.district_id, self.name, self.area_id, self.migun_time
|
return self.district_id, self.name, self.area_id, self.migun_time
|
||||||
|
|
||||||
|
|
||||||
|
class AreaDistrict(District):
|
||||||
|
def __init__(self, id: int, name: str, area_id: int, migun_time: int, area: Area):
|
||||||
|
super().__init__(id, name, area_id, migun_time)
|
||||||
|
self.area = area
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_district(cls, district: District, area: Area):
|
||||||
|
return cls(district.district_id, district.name, district.area_id, district.migun_time, area)
|
||||||
|
|
||||||
|
|
||||||
class Channel:
|
class Channel:
|
||||||
def __init__(self, id: int, server_id: int | None, channel_lang: str, locations: list):
|
def __init__(self, id: int, server_id: int | None, channel_lang: str, locations: list):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
Loading…
Reference in New Issue
Block a user