- Args
- Better configs
- Other shit too, idr
This commit is contained in:
Logan Cusano
2022-02-27 13:40:21 -05:00
parent c68cdf9d7b
commit 62968654d2
5 changed files with 146 additions and 62 deletions

73
main.py
View File

@@ -30,35 +30,96 @@ def main(**passed_config):
print('Checking config file...')
if not check_if_config_exists():
print("No config file exists, please enter this information now")
write_config_file(init=True, **passed_config)
write_config_file(init=True)
config = read_config_file()
# Overwrite config options if they were passed
for sub in config:
# checking if key present in other dictionary
if sub in passed_config:
if sub in passed_config and passed_config[sub]:
config[sub] = passed_config[sub]
print('Starting Bot...')
discord_bot_client = bot.Bot(Token=config['Bot Token'], Device_ID=config['Device ID'], Device_Name=config['Device Name'],
Mention_Group=config['Mention Group'], Channel_ID=config['Channel ID'], Handler=config['Handler'])
discord_bot_client = bot.Bot(Token=config['Bot Token'], Device_ID=config['Device ID'],
Device_Name=config['Device Name'], Mention_Group=config['Mention Group'],
Channel_ID=config['Channel ID'], Handler=config['Handler'])
print(f"Verifying audio device:\t{config['Device Name']}")
if not discord_bot_client.check_device():
if not discord_bot_client.check_device(_override=bool("Device ID" in passed_config.keys())):
raise BotDeviceNotFound(config['Device Name'])
discord_bot_client.start_bot()
def cmd_arguments():
parser = argparse.ArgumentParser(description='Discord Bot Gang - Premium Discord Bot\n'
'The more you listen, the less you can see')
# Add the arguments
# Arg to override bot token
parser.add_argument('-t', '--token',
metavar='Bot Token',
dest='Bot Token',
type=str,
help='Override saved bot token')
# Arg to override the input device in the config
parser.add_argument('-i', '--input_device_id',
metavar='Device ID',
dest='Device ID',
type=int,
help='Override saved input device')
# Arg to override mention group
parser.add_argument('-m', '--mention',
metavar='Mention Group',
dest='Mention Group',
type=str,
help='Override saved mention group')
# Arg to override default channel to send messages
parser.add_argument('-c', '--channel',
metavar='Channel ID',
dest='Channel ID',
type=int,
help='Override saved sending channel')
# Arg to override handler
parser.add_argument('-u', '--handler',
metavar='Handler',
dest='Handler',
type=str,
help='Override saved SDR handler')
# Arg to save the overridden arguments
#parser.add_argument('-s', '--save',
# metavar='save_overrides',
# dest='save_overrides',
# type=str,
# help='Save the overridden arguments passed')
# Retrieve the args
args = vars(parser.parse_args())
return args
if __name__ == '__main__':
args = cmd_arguments()
if not all(args.values()):
print("Passed arguments:")
for arg in args:
if args[arg]:
print(f"\t{arg}:\t{args[arg]}")
try:
print('Starting...')
while True:
try:
main()
main(**args)
except BotDeviceNotFound:
print("Restarting...")
time.sleep(2)