Update: Profile update
This commit is contained in:
64
bot.py
64
bot.py
@@ -81,7 +81,7 @@ class Bot(commands.Bot):
|
||||
# Create an audio stream from selected device
|
||||
stream = sound.PCMStream()
|
||||
channel = ctx.author.voice.channel
|
||||
await ctx.send(f"Ok {member}, I'm joining {channel}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I'm joining {channel}")
|
||||
|
||||
# Ensure the selected device is available and start the audio stream
|
||||
stream.change_device(self.DEVICE_ID)
|
||||
@@ -125,16 +125,16 @@ class Bot(commands.Bot):
|
||||
# Check to make sure the selected mode is valid
|
||||
if mode in possible_modes:
|
||||
self.mode = mode
|
||||
await ctx.send(f"Ok {member}, I'm changing the mode to {str(self.mode).upper()} and frequency to"
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the mode to {str(self.mode).upper()} and frequency to"
|
||||
f" {self.freq}")
|
||||
# If the SDR is started, restart it with the updates
|
||||
if self.sdr_started:
|
||||
self.start_sdr()
|
||||
self.set_activity()
|
||||
await self.set_activity()
|
||||
else:
|
||||
await ctx.send(f"{member}, {mode} is not valid. You may only enter 'fm' or 'wbfm'")
|
||||
await ctx.send(f"{str(member).capitalize()}, {mode} is not valid. You may only enter 'fm' or 'wbfm'")
|
||||
else:
|
||||
await ctx.send(f"{member}, {freq} is not valid. please refer to the help page '@ help chfreq'")
|
||||
await ctx.send(f"{str(member).capitalize()}, {freq} is not valid. please refer to the help page '@ help chfreq'")
|
||||
|
||||
@self.command(name='chsquelch', help="Use this command to change the squelch for the frequency"
|
||||
"the bot is listening to",
|
||||
@@ -142,7 +142,7 @@ class Bot(commands.Bot):
|
||||
async def chsquelch(ctx, squelch: int, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
self.squelch = squelch
|
||||
await ctx.send(f"Ok {member}, I'm changing the squelch to {self.squelch}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the squelch to {self.squelch}")
|
||||
|
||||
# If the SDR is started, restart it with the updates
|
||||
if self.sdr_started:
|
||||
@@ -153,7 +153,7 @@ class Bot(commands.Bot):
|
||||
async def chgain(ctx, gain: int, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
self.gain = gain
|
||||
await ctx.send(f"Ok {member}, I have changed the gain to {self.gain}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I have changed the gain to {self.gain}")
|
||||
|
||||
# If the SDR is started, restart it with the updates
|
||||
if self.sdr_started:
|
||||
@@ -182,35 +182,38 @@ class Bot(commands.Bot):
|
||||
self.sample_rate = sample_rate
|
||||
self.play_sample_rate = "32k"
|
||||
|
||||
await ctx.send(f"Ok {member}, I'm changing the sample rate to {self.sample_rate}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the sample rate to {self.sample_rate}")
|
||||
|
||||
# If the SDR is started, restart it with the updates
|
||||
if self.sdr_started:
|
||||
self.start_sdr()
|
||||
else:
|
||||
await ctx.send(f"{member}, {sample_rate} is not valid. please refer to the help page '@ help chbw'")
|
||||
await ctx.send(f"{str(member).capitalize()}, {sample_rate} is not valid. please refer to the help page '@ help chbw'")
|
||||
|
||||
# Hidden admin commands
|
||||
@self.command(name='saveprofile', hidden=True)
|
||||
async def _saveprofile(ctx, profile_name: str, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
self.save_radio_config(profile_name)
|
||||
await ctx.send(f"Ok {member}, I saved the current settings as {profile_name}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I saved the current settings as {profile_name}")
|
||||
|
||||
@self.command(name='loadprofile', hidden=True)
|
||||
async def _loadprofile(ctx, profile_name: str, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
self.load_radio_config(profile_name)
|
||||
await ctx.send(f"Ok {member}, I loaded the settings saved as {profile_name}")
|
||||
config_loaded = self.load_radio_config(profile_name)
|
||||
if config_loaded:
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I loaded the settings saved as {profile_name}")
|
||||
else:
|
||||
await ctx.send(f"{str(member).capitalize()}, there is no profile with the name '{profile_name}'")
|
||||
|
||||
@self.command(name='reload', hidden=True)
|
||||
async def _reload(ctx, module: str, member: discord.Member = None):
|
||||
"""Reloads a module."""
|
||||
member = member or ctx.author.display_name
|
||||
if self.reload_modules(module):
|
||||
await ctx.send(f"Ok {member}, I reloaded {module}")
|
||||
await ctx.send(f"Ok {str(member).capitalize()}, I reloaded {module}")
|
||||
else:
|
||||
await ctx.send(f"{member}, something went wrong. Please check the console")
|
||||
await ctx.send(f"{str(member).capitalize()}, something went wrong. Please check the console")
|
||||
|
||||
@self.command(name='startsdr', hidden=True)
|
||||
async def _startsdr(ctx, member: discord.Member = None):
|
||||
@@ -347,18 +350,25 @@ class Bot(commands.Bot):
|
||||
|
||||
def load_radio_config(self, profile_name):
|
||||
config = configparser.ConfigParser()
|
||||
config.read('./profiles.ini')
|
||||
if os.path.exists('./profiles.ini'):
|
||||
config.read('./profiles.ini')
|
||||
if config.has_section(str(profile_name)):
|
||||
self.profile_name = profile_name
|
||||
self.freq = config[str(profile_name)]['Frequency']
|
||||
self.mode = config[str(profile_name)]['Mode']
|
||||
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']
|
||||
|
||||
self.freq = config[str(profile_name)]['Frequency']
|
||||
self.mode = config[str(profile_name)]['Mode']
|
||||
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']
|
||||
self.profile_name = profile_name
|
||||
if self.sdr_started:
|
||||
self.start_sdr()
|
||||
loop = asyncio.get_event_loop()
|
||||
coroutine = self.set_activity()
|
||||
loop.run_until_complete(coroutine)
|
||||
|
||||
if self.sdr_started:
|
||||
self.start_sdr()
|
||||
loop = asyncio.get_event_loop()
|
||||
coroutine = self.set_activity()
|
||||
loop.run_until_complete(coroutine)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user