4
4
from discord .ext import commands , tasks
5
5
from discord .utils import get as discord_get
6
6
7
- from europython_discord .configuration import Config
8
7
from europython_discord .program_notifications import session_to_embed
8
+ from europython_discord .program_notifications .config import ProgramNotificationsConfig
9
9
from europython_discord .program_notifications .livestream_connector import LivestreamConnector
10
10
from europython_discord .program_notifications .program_connector import ProgramConnector
11
11
12
12
_logger = logging .getLogger (__name__ )
13
13
14
14
15
15
class ProgramNotificationsCog (commands .Cog ):
16
- def __init__ (self , bot : Client , config : Config ) -> None :
16
+ def __init__ (self , bot : Client , config : ProgramNotificationsConfig ) -> None :
17
17
self .bot = bot
18
18
self .config = config
19
19
self .program_connector = ProgramConnector (
20
- api_url = self .config .PROGRAM_API_URL ,
21
- timezone_offset = self .config .TIMEZONE_OFFSET ,
22
- cache_file = self .config .SCHEDULE_CACHE_FILE ,
23
- simulated_start_time = self .config .SIMULATED_START_TIME ,
24
- fast_mode = self .config .FAST_MODE ,
20
+ api_url = self .config .api_url ,
21
+ timezone_offset = self .config .timezone_offset ,
22
+ cache_file = self .config .schedule_cache_file ,
23
+ simulated_start_time = self .config .simulated_start_time ,
24
+ fast_mode = self .config .fast_mode ,
25
25
)
26
26
27
- self .livestream_connector = LivestreamConnector (self .config .LIVESTREAM_URL_FILE )
27
+ self .livestream_connector = LivestreamConnector (self .config .livestream_url_file )
28
28
29
29
self .notified_sessions = set ()
30
30
_logger .info ("Cog 'Program Notifications' has been initialized" )
31
31
32
32
@commands .Cog .listener ()
33
33
async def on_ready (self ) -> None :
34
- if self .config .SIMULATED_START_TIME :
34
+ if self .config .simulated_start_time :
35
35
_logger .info ("Running in simulated time mode." )
36
36
_logger .info ("Will purge all room channels to avoid pile-up of test notifications." )
37
37
await self .purge_all_room_channels ()
38
- _logger .debug (f"Simulated start time: { self .config .SIMULATED_START_TIME } " )
39
- _logger .debug (f"Fast mode: { self .config .FAST_MODE } " )
38
+ _logger .debug (f"Simulated start time: { self .config .simulated_start_time } " )
39
+ _logger .debug (f"Fast mode: { self .config .fast_mode } " )
40
40
_logger .info ("Starting the session notifier..." )
41
41
self .notify_sessions .start ()
42
42
_logger .info ("Cog 'Program Notifications' is ready" )
@@ -49,7 +49,7 @@ async def cog_load(self) -> None:
49
49
self .fetch_schedule .start ()
50
50
self .fetch_livestreams .start ()
51
51
self .notify_sessions .change_interval (
52
- seconds = 2 if self .config .FAST_MODE and self .config .SIMULATED_START_TIME else 60
52
+ seconds = 2 if self .config .fast_mode and self .config .simulated_start_time else 60
53
53
)
54
54
_logger .info ("Schedule updater started and interval set for the session notifier" )
55
55
@@ -86,7 +86,7 @@ async def notify_sessions(self) -> None:
86
86
return
87
87
88
88
main_notification_channel = discord_get (
89
- self .bot .get_all_channels (), name = self .config .MAIN_NOTIFICATION_CANNEL_NAME
89
+ self .bot .get_all_channels (), name = self .config .main_notification_channel_name
90
90
)
91
91
await main_notification_channel .send (content = "# Sessions starting in 5 minutes:" )
92
92
@@ -116,13 +116,13 @@ async def notify_sessions(self) -> None:
116
116
117
117
async def purge_all_room_channels (self ) -> None :
118
118
_logger .info ("Purging all room channels..." )
119
- for channel_name in self .config .ROOMS_TO_CHANNEL_NAMES .values ():
119
+ for channel_name in self .config .rooms_to_channel_names .values ():
120
120
channel = discord_get (self .bot .get_all_channels (), name = channel_name )
121
121
await channel .purge ()
122
122
_logger .info ("Purged all room channels." )
123
123
124
124
def _get_room_channel (self , room_name : str ) -> TextChannel | None :
125
- channel_name = self .config .ROOMS_TO_CHANNEL_NAMES .get (room_name )
125
+ channel_name = self .config .rooms_to_channel_names .get (room_name )
126
126
if channel_name is None :
127
127
_logger .warning (f"No notification channel configured for room { room_name !r} " )
128
128
return None
0 commit comments