Made it work
Updated console output Improved checks for config file
This commit is contained in:
@@ -4,7 +4,11 @@ from os.path import exists
|
||||
|
||||
def check_if_config_exists():
|
||||
if exists('./config.ini'):
|
||||
return True
|
||||
config = configparser.SafeConfigParser()
|
||||
if config.has_section('Bot_Info') and config.has_section('Device'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -35,30 +39,34 @@ def write_config_file(**kwargs):
|
||||
if not config.has_section('Device'):
|
||||
config.add_section('Device')
|
||||
|
||||
if kwargs['token']:
|
||||
config['Bot_Info']['Token'] = kwargs['token']
|
||||
if 'token' in kwargs.keys():
|
||||
config['Bot_Info']['Token'] = str(kwargs['token'])
|
||||
elif kwargs['init']:
|
||||
config['Bot_Info']['Token'] = get_user_token()
|
||||
config['Bot_Info']['Token'] = str(get_user_token())
|
||||
|
||||
if kwargs['device_id'] or kwargs['device_name']:
|
||||
config['Device']['ID'] = kwargs['device_id']
|
||||
config['Device']['Name'] = kwargs['device_name']
|
||||
if 'device_id' in kwargs.keys() or 'device_name' in kwargs.keys():
|
||||
config['Device']['ID'] = str(kwargs['device_id'])
|
||||
config['Device']['Name'] = str(kwargs['device_name'])
|
||||
elif kwargs['init']:
|
||||
config['Device']['ID'], config['Device']['Name'] = get_user_device_selection()
|
||||
device_id, device_name = get_user_device_selection()
|
||||
config['Device']['ID'] = str(device_id)
|
||||
config['Device']['Name'] = str(device_name)
|
||||
|
||||
if kwargs['mention_group']:
|
||||
config['Bot_Info']['Mention_Group'] = kwargs['mention_group']
|
||||
if 'mention_group' in kwargs.keys():
|
||||
config['Bot_Info']['Mention_Group'] = str(kwargs['mention_group'])
|
||||
elif kwargs['init']:
|
||||
config['Bot_Info']['Mention_Group'] = get_user_mention_group()
|
||||
config['Bot_Info']['Mention_Group'] = str(get_user_mention_group())
|
||||
|
||||
if kwargs['channel_id']:
|
||||
config['Bot_Info']['Channel_ID'] = kwargs['channel_id']
|
||||
if 'channel_id' in kwargs.keys():
|
||||
config['Bot_Info']['Channel_ID'] = str(kwargs['channel_id'])
|
||||
elif kwargs['init']:
|
||||
config['Bot_Info']['Channel_ID'] = str(get_user_mention_channel_id())
|
||||
|
||||
with open('./config.ini', 'w') as config_file:
|
||||
config.write(config_file)
|
||||
|
||||
print("Config Saved")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -122,7 +130,7 @@ def get_user_mention_group():
|
||||
def get_user_mention_channel_id():
|
||||
channel_id = None
|
||||
while not channel_id:
|
||||
channel_id = int(input(f"Please enter the channel ID of the the default channel you would like messages to be sent in"))
|
||||
channel_id = int(input(f"Please enter the channel ID of the the default channel you would like messages to be sent in:\t"))
|
||||
if len(str(channel_id)) == len('757379843792044102'):
|
||||
return channel_id
|
||||
else:
|
||||
|
||||
16
bot.py
16
bot.py
@@ -7,14 +7,14 @@ from main import write_config_file
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self, **kwargs): # bot_token, device_id, device_name, command_prefix='>!'):
|
||||
if not kwargs['command_prefix']:
|
||||
if 'command_prefix' not in kwargs.keys():
|
||||
kwargs['command_prefix'] = '>!'
|
||||
commands.Bot.__init__(self, command_prefix=commands.when_mentioned_or(kwargs['command_prefix']))
|
||||
self.DEVICE_ID = int(kwargs['Device_ID'])
|
||||
self.DEVICE_NAME = str(kwargs['Device_Name'])
|
||||
self.BOT_TOKEN = str(kwargs['Token'])
|
||||
self.Default_Channel_ID = int(kwargs['Channel_ID'])
|
||||
self.Default_Mention_Group = str(kwargs['Mention_Group'])
|
||||
self.DEVICE_ID = kwargs['Device_ID']
|
||||
self.DEVICE_NAME = kwargs['Device_Name']
|
||||
self.BOT_TOKEN = kwargs['Token']
|
||||
self.Default_Channel_ID = kwargs['Channel_ID']
|
||||
self.Default_Mention_Group = kwargs['Mention_Group']
|
||||
self.Devices_List = sound.query_devices().items()
|
||||
|
||||
self.add_commands()
|
||||
@@ -67,6 +67,8 @@ class Bot(commands.Bot):
|
||||
|
||||
def check_for_modules(self):
|
||||
for folder_name in os.listdir("modules"):
|
||||
if os.path.exists(os.path.join("modules", folder_name, "cog.py")):
|
||||
if str(folder_name)[0] == '.':
|
||||
continue
|
||||
elif os.path.exists(os.path.join("modules", folder_name, "cog.py")):
|
||||
print(f"Loaded extension: {folder_name}")
|
||||
self.load_extension(f"modules.{folder_name}.cog")
|
||||
|
||||
6
main.py
6
main.py
@@ -32,8 +32,8 @@ def main():
|
||||
|
||||
print('Starting Bot...')
|
||||
|
||||
discord_bot_client = bot.Bot(config['Bot Token'], config['Device ID'], config['Device Name'],
|
||||
config['Mention Group'], config['Channel ID'])
|
||||
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'])
|
||||
|
||||
print(f"Verifying audio device:\t{config['Device Name']}")
|
||||
|
||||
@@ -46,8 +46,6 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
#main()
|
||||
#atexit.register()
|
||||
try:
|
||||
print('Starting...')
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user