diff --git a/bot.py b/bot.py index 0a32ac7..01bf6e3 100644 --- a/bot.py +++ b/bot.py @@ -28,6 +28,7 @@ class Bot(commands.Bot): self.Devices_List = sound.query_devices().items() # Init radio parameters + self.profile_name = None self.freq = "104.7M" self.freq_re = re.compile('(\d+\.?\d*M)') self.mode = "wbfm" @@ -92,10 +93,8 @@ class Bot(commands.Bot): self.start_sdr() # Change the activity to the channel and band-type being used - await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, - name=f"{self.freq[:-1]}" - f" {str(self.mode).upper()}"), - status=discord.Status.online) + self.set_activity() + else: # Return that the opus library would not load await ctx.send("Opus won't load") @@ -106,7 +105,7 @@ class Bot(commands.Bot): # Disconnect the client from the voice channel await ctx.voice_client.disconnect() # Change the presence to away and '@ me' - await self.change_presence(activity=discord.Game(name=f"@ me"), status=discord.Status.idle) + self.set_activity(False) # Stop the SDR so it can cool off self.stop_sdr() @@ -130,10 +129,7 @@ class Bot(commands.Bot): # If the SDR is started, restart it with the updates if self.sdr_started: self.start_sdr() - await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, - name=f"{self.freq[:-1]}" - f" {str(self.mode).upper()}"), - status=discord.Status.online) + self.set_activity() else: await ctx.send(f"{member}, {mode} is not valid. You may only enter 'fm' or 'wbfm'") else: @@ -309,6 +305,20 @@ class Bot(commands.Bot): self.sdr_started = False + def set_activity(self, connected=True): + if connected: + if self.profile_name is None: + await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, + name=f"{self.freq[:-1]}" + f" {str(self.mode).upper()}"), + status=discord.Status.online) + elif type(self.profile_name) == str: + await self.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, + name=f"{str(self.profile_name).upper()}"), + status=discord.Status.online) + elif not connected: + await self.change_presence(activity=discord.Game(name=f"@ me"), status=discord.Status.idle) + def save_radio_config(self, profile_name): config = configparser.SafeConfigParser() @@ -328,7 +338,9 @@ class Bot(commands.Bot): with open('./profiles.ini', 'w+') as config_file: config.write(config_file) - + if self.sdr_started: + self.start_sdr() + self.set_activity() def load_radio_config(self, profile_name): config = configparser.ConfigParser() @@ -339,4 +351,8 @@ class Bot(commands.Bot): self.gain = int(config[str(profile_name)]['Gain']) self.squelch = int(config[str(profile_name)]['Squelch']) self.sample_rate = config[str(profile_name)]['Sample Rate'] - self.play_sample_rate = config[str(profile_name)]['Player Sample Rate'] \ No newline at end of file + self.play_sample_rate = config[str(profile_name)]['Player Sample Rate'] + + if self.sdr_started: + self.start_sdr() + self.set_activity()