if line.strip() != "":
                c.execute("INSERT INTO names VALUES(?);", [line.strip()])
                count += 1
    log.debug("Added {} names.".format(count))

    rows = c.execute("SELECT * FROM names;")
    found_count = 0
    for row in rows:
        found_count += 1
    log.debug("Found {} names.".format(found_count))

    db.commit()
    c.close()
    log.debug("All changes committed.")

    if count != found_count:
        log.warn(
            "Looks like some names have not gotten added. Perhaps duplicates? This should be investigated.")
    log.success("Database created and set up successfully!")
    return True


if __name__ == '__main__':
    log = Logger('db_setup', log_folder=Path(LOG_FOLDER).resolve(),
                 log_level='info', output_level='debug')
    success = setup_db(log)
    if success:
        log.debug("Success!")
    else:
        log.error("Could not setup database!")
Beispiel #2
0
from discord.ext.commands import has_role
import discord.ext.commands.errors as discord_errors
import typing

from simple_logging import Logger
from db_setup import setup_db
from config import *

log = Logger('ug_bot', log_folder=Path(LOG_FOLDER).resolve(),
             log_level='debug', output_level='debug')

log.debug("Loaded all modules.")
log.info("Starting the bot...")

if not setup_db(log):
    log.error("Unable to setup the database.")
    sys.exit(1)

DB_URL = os.environ['DATABASE_URL']
db = psycopg2.connect(DB_URL)
log.debug("Connected to database.")

TOKEN = os.environ['DISCORD_TOKEN']
log.info("Token:", TOKEN)

bot = commands.Bot(command_prefix=COMMAND_PREFIX)
log.info("Bot created with prefix {}.".format(COMMAND_PREFIX))


def get_users(db, name, *, is_full_name=False):
    c = db.cursor()