diff --git a/BotResources.py b/BotResources.py index 2f2f141..f9a6501 100644 --- a/BotResources.py +++ b/BotResources.py @@ -152,3 +152,14 @@ def get_user_mention_channel_id(): print("Length error in ID, please try again") channel_id = None continue + + +def check_negative(s): + try: + f = float(s) + if (f < 0): + return True + # Otherwise return false + return False + except ValueError: + return False diff --git a/bot.py b/bot.py index df8e95d..77f4ee6 100644 --- a/bot.py +++ b/bot.py @@ -6,6 +6,8 @@ import sound import configparser from discord.ext import commands from subprocess import Popen, PIPE +from gqrxHandler import GQRXHandler +from BotResources import check_negative # Init class for bot @@ -29,21 +31,14 @@ class Bot(commands.Bot): # Init radio parameters self.profile_name = None - self.freq = "104.7M" - self.freq_re = re.compile('(\d+\.?\d*M)') + self.freq = "104700000" self.mode = "wbfm" - self.gain = 40 self.squelch = 0 - self.sample_rate = "200k" - self.play_sample_rate = '32k' - self.sample_rate_re = re.compile('(\d+\.?\d*k)') - self.sdr_filters = ["dc"] # Init SDR Variables - self.sdr_process = None self.system_os_type = None - self.sdr_output_process = None self.sdr_started = False + self.GQRXHandler = GQRXHandler() # Set linux or windows self.check_os_type() @@ -114,24 +109,18 @@ class Bot(commands.Bot): "is required\nExample command: '@ chfreq wbfm 104.7M\n" "Example command: '@ chfreq fm 154.785M", brief="Changes radio frequency") - async def chfreq(ctx, mode: str, freq: str, sdr_filter: str = None, member: discord.Member = None): + async def chfreq(ctx, mode: str, freq: str, member: discord.Member = None): # Possible band-types that can be used possible_modes = ['wbfm', 'fm'] - possible_filters = ['dc', 'deemp'] member = member or ctx.author.display_name # Check to make sure the frequency input matches the syntax needed - if self.freq_re.search(freq): + if len(freq) >= 6: self.freq = freq # Check to make sure the selected mode is valid if mode in possible_modes: self.mode = mode - if sdr_filter in possible_filters: - self.sdr_filters = [sdr_filter] - else: - self.sdr_filters = ['deemp'] - await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the mode to {str(self.mode).upper()} and frequency to" f" {self.freq}") @@ -150,8 +139,14 @@ class Bot(commands.Bot): @self.command(name='chsquelch', help="Use this command to change the squelch for the frequency" "the bot is listening to", brief="Changes radio squelch") - async def chsquelch(ctx, squelch: int, member: discord.Member = None): + async def chsquelch(ctx, squelch: float, member: discord.Member = None): member = member or ctx.author.display_name + + print(f"Squelch = {squelch}") + if not check_negative(squelch): + squelch = float(-abs(squelch)) + print(f"Squelch = {squelch}") + self.squelch = squelch await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the squelch to {self.squelch}") @@ -159,48 +154,6 @@ class Bot(commands.Bot): if self.sdr_started: self.start_sdr() - @self.command(name='chgain', help="Use this command to change the radio gain for the bot", - brief="Changes radio gain") - 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 {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: - self.start_sdr() - - @self.command(name='chbw', help="Use this command to change the center frequency bandwidth for the bot." - "Note: 'k' is required\nExample Command: '@ chbw