Compare commits
4 Commits
bc618982e9
...
b528f2509c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b528f2509c | ||
|
|
aba87e4072 | ||
|
|
361f88dc4e | ||
|
|
51ffb00dd6 |
@@ -53,20 +53,24 @@ def read_config_file():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('./config.ini')
|
||||
|
||||
config_return = {
|
||||
'Bot Token': config['Bot_Info']['Token'],
|
||||
'Device ID': int(config['Device']['ID']),
|
||||
'Device Name': str(config['Device']['Name']),
|
||||
'Mention Group': str(config['Bot_Info']['Mention_Group']),
|
||||
'Channel ID': int(config['Bot_Info']['Channel_ID']),
|
||||
'Handler': str(config['Config']['Handler'])
|
||||
}
|
||||
try:
|
||||
config_return = {
|
||||
'Bot Token': config['Bot_Info']['Token'],
|
||||
'Device ID': int(config['Device']['ID']),
|
||||
'Device Name': str(config['Device']['Name']),
|
||||
'Mention Group': str(config['Bot_Info']['Mention_Group']),
|
||||
'Channel ID': int(config['Bot_Info']['Channel_ID']),
|
||||
'Handler': str(config['Config']['Handler'])
|
||||
}
|
||||
|
||||
LOGGER.debug("Found config options:")
|
||||
for key in config_return.keys():
|
||||
LOGGER.debug(f"\t{key} : {config_return[key]}")
|
||||
LOGGER.debug("Found config options:")
|
||||
for key in config_return.keys():
|
||||
LOGGER.debug(f"\t{key} : {config_return[key]}")
|
||||
|
||||
return config_return
|
||||
return config_return
|
||||
except Exception as err:
|
||||
LOGGER.warning(err)
|
||||
return None
|
||||
|
||||
|
||||
def write_config_file(**kwargs):
|
||||
@@ -122,6 +126,7 @@ def write_config_file(**kwargs):
|
||||
|
||||
def get_device_list():
|
||||
list_of_devices = query_devices().items()
|
||||
LOGGER.info("Returning queried device list:")
|
||||
LOGGER.debug(list_of_devices)
|
||||
return list_of_devices
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ class NoiseGate(AudioStream):
|
||||
|
||||
def core(self, error=None):
|
||||
if error:
|
||||
LOGGER.info('Error in the core')
|
||||
LOGGER.warning(error)
|
||||
|
||||
while not voice_connection.is_connected():
|
||||
@@ -90,6 +91,9 @@ class NoiseGate(AudioStream):
|
||||
LOGGER.debug(f"Playing stream to discord")
|
||||
voice_connection.play(discord.PCMAudio(self.NGStream), after=self.core)
|
||||
|
||||
def list_devices(self):
|
||||
return query_devices()
|
||||
|
||||
async def close(self):
|
||||
LOGGER.debug(f"Closing")
|
||||
await voice_connection.disconnect()
|
||||
@@ -107,10 +111,11 @@ class NoiseGateStream(discord.AudioSource):
|
||||
self.NG_fadeout_count = 0 # A count set when the noisegate is triggered and was de-triggered
|
||||
self.process_set_count = 0 # Counts how many processes have been made
|
||||
|
||||
def read(self):
|
||||
def read(self, num_bytes):
|
||||
num_frames = num_bytes / 4
|
||||
try:
|
||||
while voice_connection.is_connected():
|
||||
curr_buffer = bytearray(self.stream.stream.read(960))
|
||||
curr_buffer = bytearray(self.stream.stream.read(num_frames))
|
||||
buffer_rms = audioop.rms(curr_buffer, 2)
|
||||
if buffer_rms > 0:
|
||||
buffer_decibel = 20 * math.log10(buffer_rms)
|
||||
|
||||
13
bot.py
13
bot.py
@@ -14,9 +14,11 @@ class Bot(commands.Bot):
|
||||
def __init__(self, **kwargs):
|
||||
# If there is no custom command prefix (!help, ?help, etc.), use '>!' but also accept @ mentions
|
||||
if 'command_prefix' not in kwargs.keys():
|
||||
bot_intents = set_server_intents()
|
||||
kwargs['command_prefix'] = '>!'
|
||||
commands.Bot.__init__(self, command_prefix=commands.when_mentioned_or(kwargs['command_prefix']),
|
||||
activity=discord.Game(name=f"@ me"), status=discord.Status.idle)
|
||||
activity=discord.Game(name=f"@ me"), status=discord.Status.idle,
|
||||
intents=bot_intents)
|
||||
|
||||
# Create the logger for the bot
|
||||
self.logger = logging.getLogger("Discord_Radio_Bot.Bot")
|
||||
@@ -578,3 +580,12 @@ class Bot(commands.Bot):
|
||||
message_body += f"\tSquelch:\t\t\t\t{config[section]['Squelch']}\n"
|
||||
|
||||
return message_body
|
||||
|
||||
|
||||
# Set discord intents and return the intent object
|
||||
def set_server_intents():
|
||||
bot_intents = discord.Intents.default()
|
||||
#bot_intents.messages = True
|
||||
#bot_intents.message_content = True
|
||||
#bot_intents.members = True
|
||||
return bot_intents
|
||||
5
main.py
5
main.py
@@ -39,6 +39,11 @@ def main(**passed_config):
|
||||
|
||||
config = BotResources.read_config_file()
|
||||
|
||||
if not config:
|
||||
LOGGER.warning("No config file exists, please enter this information now")
|
||||
BotResources.write_config_file(init=True)
|
||||
config = BotResources.read_config_file()
|
||||
|
||||
# Overwrite config options if they were passed
|
||||
if len(passed_config.keys()) == 0:
|
||||
for sub in config:
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
discord~=1.7.3
|
||||
numpy==1.22.3
|
||||
scipy==1.8.0
|
||||
matplotlib~=3.5.1
|
||||
pyrtlsdr~=0.2.92
|
||||
PyAudio~=0.2.11
|
||||
discord==2.1.0
|
||||
numpy==1.23.5
|
||||
PyAudio==0.2.12
|
||||
sounddevice==0.4.5
|
||||
|
||||
Reference in New Issue
Block a user