2024-06-29 23:16:03 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# Kaikout: Kaiko Out anti-spam bot for XMPP
|
|
|
|
# Copyright (C) 2024 Schimon Zackary
|
|
|
|
# This file is part of Kaikout.
|
|
|
|
# See the file LICENSE for copying permission.
|
|
|
|
|
|
|
|
# from kaikout.about import Documentation
|
2024-11-21 11:11:11 +01:00
|
|
|
from kaikout.utilities import Config, Toml
|
2024-06-29 23:16:03 +02:00
|
|
|
# from kaikout.xmpp.chat import XmppChat
|
|
|
|
from kaikout.xmpp.client import XmppClient
|
|
|
|
from getpass import getpass
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
import logging
|
2024-11-21 11:11:11 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2024-06-29 23:16:03 +02:00
|
|
|
# import slixmpp
|
|
|
|
# import sys
|
|
|
|
|
|
|
|
def main():
|
2024-11-21 11:11:11 +01:00
|
|
|
|
|
|
|
directory = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
# Copy data files
|
|
|
|
directory_data = Config.get_default_config_directory()
|
|
|
|
# TODO Utilize the actual data directory
|
|
|
|
#directory_data = Config.get_default_data_directory()
|
|
|
|
if not os.path.exists(directory_data):
|
|
|
|
directory_assets = os.path.join(directory, 'assets')
|
|
|
|
directory_assets_new = shutil.copytree(directory_assets, directory_data)
|
|
|
|
print(f'Data directory {directory_assets_new} has been created and populated.')
|
|
|
|
|
|
|
|
# Copy settings files
|
|
|
|
directory_settings = Config.get_default_config_directory()
|
|
|
|
if not os.path.exists(directory_settings):
|
|
|
|
directory_configs = os.path.join(directory, 'configs')
|
|
|
|
directory_settings_new = shutil.copytree(directory_configs, directory_settings)
|
|
|
|
print(f'Configuration directory {directory_settings_new} has been created and populated.')
|
|
|
|
|
2024-06-29 23:16:03 +02:00
|
|
|
# Setup the command line arguments.
|
|
|
|
parser = ArgumentParser(description=XmppClient.__doc__)
|
|
|
|
|
|
|
|
# Output verbosity options.
|
|
|
|
parser.add_argument("-q", "--quiet", help="set logging to ERROR",
|
|
|
|
action="store_const", dest="loglevel",
|
|
|
|
const=logging.ERROR, default=logging.INFO)
|
|
|
|
parser.add_argument("-d", "--debug", help="set logging to DEBUG",
|
|
|
|
action="store_const", dest="loglevel",
|
|
|
|
const=logging.DEBUG, default=logging.INFO)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Setup logging.
|
|
|
|
logging.basicConfig(level=args.loglevel,
|
|
|
|
format='%(levelname)-8s %(message)s')
|
|
|
|
|
2024-11-21 11:11:11 +01:00
|
|
|
# Configure settings file
|
|
|
|
file_settings = os.path.join(directory_settings, 'accounts.toml')
|
|
|
|
if not os.path.exists(file_settings):
|
|
|
|
directory_configs = os.path.join(directory, 'configs')
|
|
|
|
file_settings_empty = os.path.join(directory_configs, 'accounts.toml')
|
|
|
|
shutil.copyfile(file_settings_empty, file_settings)
|
2024-07-30 09:02:27 +02:00
|
|
|
|
2024-11-21 11:11:11 +01:00
|
|
|
data_settings = Toml.open_file(file_settings)
|
|
|
|
|
|
|
|
# Configure account
|
|
|
|
data_settings_account = data_settings['xmpp']['client']
|
|
|
|
|
|
|
|
settings_account = {
|
|
|
|
'alias': 'Set an Alias',
|
|
|
|
'jid': 'Set a Jabber ID',
|
|
|
|
'password': 'Input Password'
|
|
|
|
}
|
|
|
|
|
|
|
|
for key in settings_account:
|
|
|
|
data_settings_account_value = data_settings_account[key]
|
|
|
|
if not data_settings_account_value:
|
|
|
|
settings_account_message = settings_account[key]
|
|
|
|
while not data_settings_account_value:
|
|
|
|
if key == 'password':
|
|
|
|
data_settings_account_value = getpass(f'{settings_account_message}: ')
|
|
|
|
else:
|
|
|
|
data_settings_account_value = input(f'{settings_account_message}: ')
|
|
|
|
data_settings_account[key] = data_settings_account_value
|
|
|
|
|
|
|
|
Toml.save_file(file_settings, data_settings)
|
2024-06-29 23:16:03 +02:00
|
|
|
|
|
|
|
# Try configuration file
|
2024-11-21 12:40:43 +01:00
|
|
|
jid = data_settings_account['jid']
|
|
|
|
password = data_settings_account['password']
|
|
|
|
alias = data_settings_account['alias']
|
|
|
|
# TODO
|
|
|
|
#hostname = account_xmpp_client['hostname'] if 'hostname' in account_xmpp_client else None
|
|
|
|
#port = account_xmpp_client['port'] if 'port' in account_xmpp_client else None
|
|
|
|
hostname = port = None
|
|
|
|
XmppClient(jid, password, hostname, port, alias)
|
2024-06-29 23:16:03 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|