43 Commits

Author SHA1 Message Date
Logan Cusano
b528f2509c Update to latest (not working) 2022-11-26 21:52:04 -05:00
Logan Cusano
aba87e4072 Updated requirements.txt 2022-11-26 20:51:40 -05:00
Logan Cusano
361f88dc4e Updated to use intents
- fixed config bug when broken config was found
- more info logging
2022-11-26 20:51:25 -05:00
Logan Cusano
51ffb00dd6 Sledgehammer config approach 2022-11-26 20:18:42 -05:00
Logan Cusano
bc618982e9 //WIP v3
NoiseGate
- Changed to PCM audio
2022-04-30 21:53:28 -04:00
Logan Cusano
b01ec700f7 Merge branch 'master' into Noisegate_sounddevice_update 2022-04-23 01:46:34 -04:00
b2a73726a0 Merge pull request 'V3_GQRX_Improvements' (#11) from V3_GQRX_Improvements into master
Reviewed-on: http://git.vpn.cusano.net/Discord_Bot_Gang/Discord-Radio-Bot/pulls/11
2022-04-16 20:52:43 -04:00
Logan Cusano
a094ba581d //WIP v3
GQRX Changes
- Better error handling; GQRX config dupes some options for an unknown reason
2022-04-10 13:53:59 -04:00
Logan Cusano
62f9e1abaa //WIP v3
GQRX Changes
- Ensure AGC is enabled whenever the bot starts
2022-04-09 22:34:56 -04:00
Logan Cusano
e4e04e429f //WIP v3
GQRX Config Template
- Added switch to allow AGC
2022-04-09 22:27:26 -04:00
Logan Cusano
0db4f62afc //WIP v3
Clear Messages Changes
- Bug
- More error checking
- Limit the user to 100 messages
- More help text
2022-04-09 22:22:44 -04:00
Logan Cusano
4d5c1183d6 //WIP v3
Clear Messages Changes
- Bug
2022-04-09 22:15:37 -04:00
Logan Cusano
9dba89a60b //WIP v3
Clear Messages Changes
- Check for negative numbers... Gino
2022-04-09 22:14:21 -04:00
Logan Cusano
dcf0de8351 //WIP v3
Clear Messages Changes
- Added help message
2022-04-09 22:09:24 -04:00
Logan Cusano
bfb049e268 //WIP v3
Clear Messages Changes
- Default clear to 2 messages (instantiation and the previous message)
2022-04-09 22:05:32 -04:00
Logan Cusano
b0d83def35 //WIP v3
Clear Messages Changes
- No "#0000" in username output
2022-04-09 22:03:52 -04:00
Logan Cusano
8af7a70b65 //WIP v3
Clear Messages Changes
- Mentioning user ID not name
2022-04-09 22:02:04 -04:00
Logan Cusano
8d090c5c67 //WIP v3
Clear Messages Changes
- Better logging
- Better output
2022-04-09 21:58:34 -04:00
Logan Cusano
35e19ee83f //WIP v3
Clear Messages Changes
- New approach
2022-04-09 21:39:44 -04:00
Logan Cusano
44d027ab8c Merge branch 'master' into V3_GQRX_Improvements 2022-04-09 21:29:12 -04:00
Logan Cusano
3837f7abd6 //WIP V3
Update todo
2022-04-09 21:27:49 -04:00
Logan Cusano
b7f0939787 //WIP V3
GQRX Changes
- Sending output to devnull, except for error
2022-04-09 04:32:12 -04:00
Logan Cusano
cccd974adc //WIP V3
GQRX Changes
- Changed repeating log entry to debug
2022-04-09 03:39:45 -04:00
Logan Cusano
f4b14c26fc Merge branch 'master' into V3_GQRX_Improvements 2022-04-09 03:27:23 -04:00
Logan Cusano
a483f83b4b //WIP V3
Bot Changes
- Increased loop delay when waiting for GQRX to start
Noisegate Change
- Display whether the noisegate is active or not in the logs
2022-04-09 02:36:48 -04:00
Logan Cusano
458ab5be95 //WIP V3
Bot Changes
- Never used new radio config function when loading config
2022-04-09 02:25:46 -04:00
Logan Cusano
dbbd5b6fe3 //WIP V3
Bot Changes
- Awaiting new async 'use_current_radio_config' function
2022-04-09 02:23:46 -04:00
Logan Cusano
63b37d14cb //WIP V3
Bot Changes
- Improved handlers
- Added new function to use the newly set or loaded settings
- Any change to frequency, squelch, mode, or noisegate threshold will show no profile
    - The user is responsible for saving their changes

Readme Changes
- Update with notes on the bot change above
2022-04-09 02:21:53 -04:00
Logan Cusano
2dabf1c98d //WIP V3
GQRX Changes
- Resetting tel_conn when closing GQRX
2022-04-09 01:57:24 -04:00
Logan Cusano
5551aa6355 //WIP V3
Default Radio Settings Update
- One location for default radio settings

GQRX Changes
- Default settings
- Simpler check to see if GQRX is started
- Working process handler
2022-04-09 01:52:37 -04:00
Logan Cusano
7ee5d92852 forgot each item needed to be in the list, no spaces 2022-04-09 01:21:33 -04:00
Logan Cusano
5a3729627b GQRX Changes
- Checks for GQRX config file
    - If one exists, reset the 'crashed' option
    - If one does not, create one from the template
- New templates package
    - Useful for storing large files to be called on later
2022-04-09 01:13:06 -04:00
Logan Cusano
bb56566d37 Merge branch 'master' into V3_GQRX_Improvements 2022-04-08 21:35:07 -04:00
Logan Cusano
99ec1d07aa Merge remote-tracking branch 'origin/V3_GQRX_Improvements' into V3_GQRX_Improvements 2022-04-01 01:59:51 -04:00
Logan Cusano
bbca25ce3f Getting closer on the GQRX Handler. Doesn't close properly 2022-04-01 01:55:14 -04:00
Logan Cusano
676936eb6f More intelligent init of the handler 2022-04-01 01:10:12 -04:00
Logan Cusano
8debd690f1 Better logging 2022-04-01 01:08:54 -04:00
Logan Cusano
5d1a58ee87 Var got set before the error check 2022-04-01 01:07:23 -04:00
Logan Cusano
fd62da0c6f Silly bug 2022-04-01 01:05:57 -04:00
Logan Cusano
b972d09a65 Handling the delay in GQRX opening and being 'usable'
Handling the delay in GQRX opening and being 'usable'
2022-04-01 01:00:32 -04:00
Logan Cusano
21aacde130 Moved the main inits to when the bot is run 2022-04-01 00:51:34 -04:00
Logan Cusano
e26ae52399 Wrong location of the logger 2022-04-01 00:50:28 -04:00
Logan Cusano
319de5cf42 Initial changes to handle GQRX process 2022-04-01 00:46:34 -04:00
12 changed files with 406 additions and 76 deletions

View File

@@ -5,18 +5,37 @@ from datetime import date
from os.path import exists
from NoiseGatev2 import AudioStream, query_devices
# Handler configs
PDB_ACCEPTABLE_HANDLERS = {'gqrx': {
'Modes': ['wfm', 'fm']
},
'op25': {
'Modes': ['d', 'p25']
}}
# Known bot IDs
PDB_KNOWN_BOT_IDS = {756327271597473863: "Greada", 915064996994633729: "Jorn", 943742040255115304: "Brent"}
# Default value to set noisegate on new or unknown profiles
DEFAULT_NOISEGATE_THRESHOLD = 50
# Initialize the logger for this file
LOGGER = logging.getLogger('Discord_Radio_Bot.Bot_Resources')
# Location of the gqrx binary
GQRX_BIN_LOCATION = "/usr/bin/"
GQRX_BIN = "/usr/bin/gqrx"
# Default radio settings
DEFAULT_RADIO_SETTINGS = {
'profile_name': None,
'freq': "104700000",
'mode': "wfm",
'squelch': 0,
'noisegate_sensitivity': DEFAULT_NOISEGATE_THRESHOLD,
}
def check_if_config_exists():
if exists('./config.ini'):
@@ -34,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):
@@ -103,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

View File

@@ -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():
@@ -88,7 +89,10 @@ class NoiseGate(AudioStream):
if not voice_connection.is_playing():
LOGGER.debug(f"Playing stream to discord")
voice_connection.play(self.NGStream, after=self.core)
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")
@@ -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)

View File

@@ -23,4 +23,9 @@ Voicemeeter is **highly** recommended for this bot. See a detailed guide on how
To change the audio source, simply delete the ```config.ini``` that was generated and restart the bot.
It will re-do the setup and allow you to select a new device.
### [To-Do](https://git.vpn.cusano.net/Discord_Bot_Gang/Discord-Radio-Bot/src/branch/master/TODO.md)
### [To-Do](https://git.vpn.cusano.net/Discord_Bot_Gang/Discord-Radio-Bot/src/branch/master/TODO.md)
**Notes for readme leter on**
- Users need to save profile after any change in discord
-

View File

@@ -3,6 +3,7 @@
### Main Development
#### Core
- [ ] Add new handlers for GQRX: https://github.com/gqrx-sdr/gqrx/blob/master/resources/remote-control.txt
- [ ] Add logging for Elasticstack https://www.elastic.co/guide/en/ecs-logging/python/master/installation.html
- [ ] Add a process handler to start/stop gqrx
- [ ] Fix the bug where they *disconnect* after a period of time and must be manually moved out and back in to hear them
- *May* have been fixed with the noise gate?

73
bot.py
View File

@@ -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")
@@ -40,11 +42,11 @@ class Bot(commands.Bot):
self.Devices_List = NoiseGatev2.query_devices().items()
# Init radio parameters
self.profile_name = None
self.freq = "104700000"
self.mode = "wfm"
self.squelch = 0
self.noisegate_sensitivity = BotResources.DEFAULT_NOISEGATE_THRESHOLD
self.profile_name = BotResources.DEFAULT_RADIO_SETTINGS['profile_name']
self.freq = BotResources.DEFAULT_RADIO_SETTINGS['freq']
self.mode = BotResources.DEFAULT_RADIO_SETTINGS['mode']
self.squelch = BotResources.DEFAULT_RADIO_SETTINGS['squelch']
self.noisegate_sensitivity = BotResources.DEFAULT_RADIO_SETTINGS['noisegate_sensitivity']
# Init SDR Variables
self.system_os_type = None
@@ -171,8 +173,12 @@ class Bot(commands.Bot):
f"{self.streamHandler.THRESHOLD} to {_threshold}")
self.streamHandler.THRESHOLD = _threshold
self.noisegate_sensitivity = _threshold
if self.sdr_started:
await self.set_activity()
# Reset the profile name since we have made a change
self.profile_name = None
# If the SDR is started, restart it with the updates
await self.use_current_radio_config()
# Add commands for GQRX and OP25
if self.Handler in BotResources.PDB_ACCEPTABLE_HANDLERS.keys():
@@ -223,13 +229,11 @@ class Bot(commands.Bot):
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the mode to "
f"{str(self.mode).upper()} and frequency to {self.freq}")
# Reset the profile name since we have made a change to the freq
# Reset the profile name since we have made a change
self.profile_name = None
# If the SDR is started, restart it with the updates
if self.sdr_started:
self.start_sdr()
await self.set_activity()
await self.use_current_radio_config()
else:
await ctx.send(f"{str(member).capitalize()}, {mode} is not valid."
f" You may only enter {self.possible_modes}")
@@ -252,9 +256,11 @@ class Bot(commands.Bot):
self.squelch = squelch
await ctx.send(f"Ok {str(member).capitalize()}, I'm changing the squelch to {self.squelch}")
# Reset the profile name since we have made a change
self.profile_name = None
# If the SDR is started, restart it with the updates
if self.sdr_started:
self.start_sdr()
await self.use_current_radio_config()
# Hidden admin commands
@self.command(name='saveprofile', hidden=True)
@@ -336,6 +342,7 @@ class Bot(commands.Bot):
self.logger.info("Starting GQRX handler")
from gqrxHandler import GQRXHandler
self.GQRXHandler = GQRXHandler()
self.GQRXHandler.start()
self.possible_modes = BotResources.PDB_ACCEPTABLE_HANDLERS['gqrx']['Modes']
elif self.Handler == 'op25':
@@ -433,7 +440,9 @@ class Bot(commands.Bot):
if self.Handler == 'gqrx':
# Set the settings in GQRX
self.GQRXHandler.set_all_settings(self.mode, self.squelch, self.freq)
self.GQRXHandler.set_gqrx_parameters(_frequency=self.freq, _squelch=self.squelch,
_fm_mode=self.mode, _output_device_name=self.DEVICE_NAME,
_start=True)
elif self.Handler == 'op25':
self.OP25Handler.set_op25_parameters(self.freq, _start=True, _output_device_name=self.DEVICE_NAME)
@@ -445,11 +454,16 @@ class Bot(commands.Bot):
def stop_sdr(self):
if self.sdr_started:
# Wait for the running processes to close
# Close the GQRX handler
if self.Handler == 'gqrx':
self.GQRXHandler.set_gqrx_parameters(_stop=True)
# Close the OP25 handler
if self.Handler == 'op25':
self.OP25Handler.set_op25_parameters(_stop=True)
# self.OP25Handler.join()
# Need a way to 'close' GQRX
self.sdr_started = False
# Set the activity of the bot
@@ -495,8 +509,19 @@ class Bot(commands.Bot):
self.profile_name = profile_name
await self.use_current_radio_config()
async def use_current_radio_config(self):
if self.sdr_started:
self.start_sdr()
# Set the loaded profile settings into GQRX
if self.Handler == "gqrx":
self.GQRXHandler.set_gqrx_parameters(_frequency=self.freq, _squelch=self.squelch,
_fm_mode=self.mode)
# Restart OP25 to use the loaded profile
if self.Handler == "op25":
self.start_sdr()
# Set the activity to reflect the loaded profile
await self.set_activity()
# Load a saved profile into the current settings
@@ -519,10 +544,7 @@ class Bot(commands.Bot):
self.noisegate_sensitivity = BotResources.DEFAULT_NOISEGATE_THRESHOLD
await self.save_radio_config(self.profile_name)
if self.sdr_started:
self.start_sdr()
await self.set_activity()
await self.use_current_radio_config()
return True
else:
return False
@@ -558,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

View File

@@ -1,22 +1,195 @@
import configparser
import shutil
import logging
import threading
import subprocess
import time
from pathlib import Path
from telnetlib import Telnet
from BotResources import check_negative
from BotResources import *
from time import sleep
class GQRXHandler():
def __init__(self, hostname: str = "localhost", port: int = 7356):
def reset_crashed(_config_path):
config = configparser.SafeConfigParser()
config.read(_config_path)
if config.has_section('General'):
if config.getboolean('General', 'crashed'):
config['General']['crashed'] = 'false'
with open(_config_path, 'w') as config_file:
config.write(config_file)
return True
else:
return False
def enable_agc(_config_path):
config = configparser.SafeConfigParser()
config.read(_config_path)
if config.has_option('receiver', 'agc_off'):
config.remove_option('receiver', 'agc_off')
with open(_config_path, 'w') as config_file:
config.write(config_file)
return True
class GQRXHandler(threading.Thread):
def __init__(self):
super().__init__()
self.GQRX_Config_Path = Path(f"{Path.home()}/.config/gqrx/drb_defaults.conf")
self.GQRXDir: str = GQRX_BIN_LOCATION
self.GQRXEXE: str = shutil.which(GQRX_BIN)
self.GQRXProc = None
self.GQRX_Started = False
self.logger = logging.getLogger("Discord_Radio_Bot.GQRXHandler")
self.hostname = hostname
self.port = port
self.Frequency = None
self.Mode = DEFAULT_RADIO_SETTINGS['mode']
self.Frequency = DEFAULT_RADIO_SETTINGS['freq']
self.Squelch = DEFAULT_RADIO_SETTINGS['squelch']
self.Start_GQRX = False
self.Stop_GQRX = False
self.Output_Device_Name = None
self.hostname = "localhost"
self.port = 7356
self.tel_conn = None
self.create_telnet_connection()
def run(self) -> None:
while True:
if self.Start_GQRX:
self.open_gqrx()
self.Start_GQRX = False
self.Stop_GQRX = False
self.logger.debug("GQRX is open, waiting for it to close")
while not self.Stop_GQRX:
sleep(1)
self.logger.debug('Request to close GQRX')
self.close_gqrx()
sleep(.5)
def set_gqrx_parameters(self, _frequency: str = False, _start: bool = False, _stop: bool = False,
_output_device_name: str = None, _fm_mode: str = None, _squelch: float = None,
_hostname: str = None, _port: int = None, _start_dsp: bool = None):
if _frequency:
self.Frequency = _frequency
if self.GQRX_Started:
self.change_freq(_frequency)
if _output_device_name:
self.Output_Device_Name = _output_device_name
if _fm_mode:
self.Mode = _fm_mode
if self.GQRX_Started:
self.change_mode(_fm_mode)
if _squelch:
self.Squelch = _squelch
if self.GQRX_Started:
self.change_squelch(_squelch)
if _hostname:
self.hostname = _hostname
self.Start_GQRX = True
if _port:
self.port = _port
self.Start_GQRX = True
if _start_dsp:
self.start_dsp()
if _start:
self.Start_GQRX = _start
if _stop:
self.Stop_GQRX = _stop
def open_gqrx(self):
if self.GQRX_Started:
self.close_gqrx()
gqrx_kwargs = [f"gqrx", "-c", "drb_defaults.conf"]
self.logger.info(f"Resetting 'crashed' option in the GQRX config")
self.reset_or_create_config()
self.logger.info(f"Starting GQRX")
self.logger.debug(f"GQRX Keyword Args: {gqrx_kwargs}")
self.GQRXProc = subprocess.Popen(gqrx_kwargs, executable=self.GQRXEXE, shell=False)
while not self.tel_conn:
self.create_telnet_connection()
sleep(2)
self.logger.debug(f"Waiting for GQRX to start")
self.GQRX_Started = True
self.start_dsp()
self.set_all_settings(_squelch=self.Squelch, _mode=self.Mode, _freq=self.Frequency)
self.logger.debug('Finished opening GQRX')
def close_gqrx(self):
self.logger.info(f"Closing GQRX")
try:
self.GQRXProc.kill()
seconds_waited = 0
while self.GQRXProc.poll() is None:
# Terminate the process every 5 seconds
if seconds_waited % 5 == 0:
self.logger.info("Terminating GQRX")
self.GQRXProc.terminate()
sleep(1)
self.logger.debug(f"Waited {seconds_waited} seconds")
seconds_waited += 1
self.logger.debug("GQRX Closed")
self.GQRX_Started = False
self.tel_conn = None
except Exception as e:
self.logger.error(e)
def create_telnet_connection(self):
self.logger.info("Creating connection")
self.tel_conn = Telnet(self.hostname, self.port)
self.tel_conn.open(self.hostname, self.port)
self.logger.debug("Creating connection")
try:
self.tel_conn = Telnet(self.hostname, self.port)
self.tel_conn.open(self.hostname, self.port)
self.logger.debug(f"GQRX is open")
return True
except Exception as err:
self.logger.warning(err)
self.tel_conn = None
return False
def check_dsp(self):
self.logger.debug(f"Checking if DSP is running on GQRX")
self.tel_conn.write(bytes(f"u DSP", 'utf-8'))
if self.tel_conn.read_some() == b"1":
return True
else:
return False
def start_dsp(self):
if not self.check_dsp():
self.logger.debug(f"Starting DSP on GQRX")
self.tel_conn.write(bytes(f"U DSP 1", 'utf-8'))
self.tel_conn.read_until(b'RPRT 0')
def change_freq(self, freq):
self.logger.debug(f"Changing freq to {freq}")
@@ -35,8 +208,32 @@ class GQRXHandler():
self.tel_conn.write(bytes(f"M {str(mode)}", 'utf-8'))
self.tel_conn.read_until(b'RPRT 0')
def set_all_settings(self, mode, squelch, freq):
def set_all_settings(self, _mode, _squelch, _freq):
self.change_squelch(0)
self.change_mode(mode)
self.change_freq(freq)
self.change_squelch(squelch)
self.change_mode(_mode)
self.change_freq(_freq)
self.change_squelch(_squelch)
def creat_config(self):
from templates.gqrx_config_template import drb_defaults
config = drb_defaults
try:
with open(self.GQRX_Config_Path, 'w+') as config_file:
config_file.write(config)
except OSError as err:
self.logger.error(err)
def reset_or_create_config(self):
if self.GQRX_Config_Path.is_file():
try:
self.logger.debug(f"Enabling AGC in the GQRX config")
enable_agc(_config_path=self.GQRX_Config_Path)
self.logger.debug(f"GQRX Config exists, resetting 'crashed' setting")
reset_crashed(_config_path=self.GQRX_Config_Path)
except configparser.DuplicateOptionError as err:
self.logger.warning(err)
self.creat_config()
else:
self.logger.debug(f"GQRX config does not exist, creating it from template")
self.creat_config()

View File

@@ -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:

View File

@@ -1,30 +1,51 @@
import logging
from discord.ext import commands
import asyncio
LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop")
class ClearMessages(commands.Cog):
def __init__(self, bot):
self.Bot = bot
@commands.command()
async def clear(self, ctx, amount=0):
if amount == 0:
fail = await ctx.send("Please enter an amount to delete!")
await asyncio.sleep(6)
await fail.delete()
@commands.command(name='clear',
help="Use this command to clear a given number of messages from the channel it is called in.\n"
"There is a limit of 100 messages. Please be patient, it may take a while to process a large request."
"Example command:\n"
"\t@ clear\n"
"\t@ clear 10",
breif="Clear x messages in the channel it's called in")
async def clear(self, ctx, amount=2):
member = ctx.author.display_name
member_id = ctx.author.id
mtn_member = f"<@{member_id}>"
if amount < 3:
await ctx.channel.purge(limit=amount)
sucess = await ctx.send(
f"{amount} messages has been deleted <a:Verified:878231325469974599>") # sending success msg
await asyncio.sleep(6) # wait 6 seconds
await sucess.delete() # deleting the success msg
if isinstance(amount, int):
if not amount > 0:
ctx.channel.send(f"{member}, the number needs to be positive...")
else:
LOGGER.info(f"Clear {amount} messages requested by {member}")
authors = {}
async for message in ctx.channel.history(limit=amount):
if message.author not in authors:
authors[message.author] = 1
else:
authors[message.author] += 1
await message.delete()
msg = f"{mtn_member}, I deleted {sum(authors.values())} messages from {len(authors.keys())} users:\n"
LOGGER.debug(f"Deleted {sum(authors.values())} messages from {ctx.message.channel}")
for author in authors.keys():
msg += f"\t{str(author).split('#', 1)[0]}: {authors[author]}\n"
LOGGER.debug(f"Deleted {authors[author]} messages from {author}")
await ctx.channel.send(msg)
else:
if amount == 0:
fail = await ctx.send("Please enter an amount to delete!")
await asyncio.sleep(6)
await fail.delete()
ctx.channel.send(f"{member}, you should check out the 'help' section...")
def setup(bot: commands.Bot):

View File

@@ -3,6 +3,7 @@ import shutil
import subprocess
import threading
import time
from BotResources import DEFAULT_RADIO_SETTINGS
class OP25Handler(threading.Thread):
@@ -12,7 +13,7 @@ class OP25Handler(threading.Thread):
self.OP25EXE: str = shutil.which("/home/pi/op25/op25/gr-op25_repeater/apps/rx.py")
self.OP25Proc = None
self.Frequency = None
self.Frequency = DEFAULT_RADIO_SETTINGS['freq']
self.HTTP_ENABLED = False
@@ -70,7 +71,8 @@ class OP25Handler(threading.Thread):
self.logger.debug(f"OP25 Keyword Args: {p25_kwargs}")
self.OP25Proc = subprocess.Popen(p25_kwargs, executable=self.OP25EXE, shell=False, cwd=self.OP25Dir)
self.OP25Proc = subprocess.Popen(p25_kwargs, executable=self.OP25EXE, shell=False, cwd=self.OP25Dir,
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
def close_op25(self):
self.logger.info(f"Closing OP25")
@@ -81,7 +83,7 @@ class OP25Handler(threading.Thread):
while self.OP25Proc.poll() is None:
# Terminate the process every 5 seconds
if seconds_waited % 5 == 0:
self.logger.debug("Terminating OP25")
self.logger.info("Terminating OP25")
self.OP25Proc.terminate()
time.sleep(1)
self.logger.debug(f"Waited {seconds_waited} seconds")

View File

@@ -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

0
templates/__init__.py Normal file
View File

View File

@@ -0,0 +1,41 @@
drb_defaults = """[General]
configversion=2
crashed=false
[audio]
gain=-20
udp_host=localhost
[dxcluster]
DXCAddress=localhost
DXCFilter=
DXCPort=7300
DXCSpotTimeout=10
DXCUsername=nocall
[fft]
averaging=85
fft_window=5
waterfall_span=1
[gui]
geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x3\0\0\0\0\x4t\0\0\0$\0\0\a\x7f\0\0\x3\x12\0\0\x4v\0\0\0\x42\0\0\a\x7f\0\0\x3\x12\0\0\0\0\0\0\0\0\a\x80\0\0\x4v\0\0\0\x42\0\0\a\x7f\0\0\x3\x12)
state=@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\x1\0\0\x1G\0\0\x2t\xfc\x2\0\0\0\x2\xfc\0\0\0\x42\0\0\x1\x89\0\0\x1\x89\0\b\0!\xfa\0\0\0\x1\x2\0\0\0\x3\xfb\0\0\0\x18\0\x44\0o\0\x63\0k\0I\0n\0p\0u\0t\0\x43\0t\0l\x1\0\0\0\0\xff\xff\xff\xff\0\0\x1P\0\xff\xff\xff\xfb\0\0\0\x12\0\x44\0o\0\x63\0k\0R\0x\0O\0p\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\x1g\0\a\xff\xff\xfb\0\0\0\xe\0\x44\0o\0\x63\0k\0\x46\0\x66\0t\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\xc8\0\a\xff\xff\xfc\0\0\x1\xd1\0\0\0\xe5\0\0\0\xc3\0\xff\xff\xff\xfa\0\0\0\0\x2\0\0\0\x2\xfb\0\0\0\x12\0\x44\0o\0\x63\0k\0\x41\0u\0\x64\0i\0o\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\xc3\0\xff\xff\xff\xfb\0\0\0\xe\0\x44\0o\0\x63\0k\0R\0\x44\0S\0\0\0\0\0\xff\xff\xff\xff\0\0\0h\0\xff\xff\xff\0\0\0\x3\0\0\0\0\0\0\0\0\xfc\x1\0\0\0\x1\xfb\0\0\0\x1a\0\x44\0o\0\x63\0k\0\x42\0o\0o\0k\0m\0\x61\0r\0k\0s\0\0\0\0\0\xff\xff\xff\xff\0\0\x1\x42\0\xff\xff\xff\0\0\x1\xbd\0\0\x2t\0\0\0\x1\0\0\0\x2\0\0\0\b\0\0\0\x2\xfc\0\0\0\x1\0\0\0\x2\0\0\0\x1\0\0\0\x16\0m\0\x61\0i\0n\0T\0o\0o\0l\0\x42\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)
[input]
dc_cancel=true
device="rtl=0"
frequency=154785000
gains=@Variant(\0\0\0\b\0\0\0\x1\0\0\0\x6\0L\0N\0\x41\0\0\0\x2\0\0\x1P)
sample_rate=1800000
[receiver]
demod=3
filter_high_cut=2500
filter_low_cut=-2500
offset=-590400
sql_level=-50
[remote_control]
allowed_hosts=localhost, 127.0.0.1, ::1
enabled=true"""