<commit_before>#!/usr/bin/env python3

'''D&D manager bot for discord based RPGs

Note:
Any parameter value that has spaces in it needs to be wrapped in quotes "
unless it is the final parameter
Certain commands are only usable by the @DM role
'''

import re
import argparse
import asyncio
import logging
from collections import OrderedDict
from contextlib import closing

from discord.ext import commands
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

import model as m
from util import NoCharacterError, ItemNotFoundError
from util.equations import EquationError


async def get_prefix(bot, message):
    '''
    Hack to prevent the bot from complaining about messages like `!!!`
    '''
    if re.match(r'!\w', message.content):
        return '!'
    else:
        return '\0'  # return an invalid prefix since None isn't valid

bot = commands.Bot(
    command_prefix=get_prefix,
    description=__doc__,
    loop=asyncio.new_event_loop())


@bot.event
async def on_ready():
    '''
    Sets up the bot
    '''
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


@bot.before_invoke
async def before_any_command(ctx):
    '''
    Set up database connection
    '''
    ctx.session = bot.Session()


@bot.after_invoke
async def after_any_command(ctx):
    '''
    Tear down database connection
    '''
    ctx.session.close()
    ctx.session = None


@bot.event
async def on_command_error(ctx, error):
    if (isinstance(error, commands.CommandInvokeError)):
        error = error.original

    if isinstance(error, commands.CheckFailure):
        await ctx.send(
            'Error: You do not meet the requirements to use this command')
    elif isinstance(error, commands.CommandNotFound):
        if error.args:
            await ctx.send(error.args[0])
        else:<commit_msg>Changed command prefix to ;<commit_after>#!/usr/bin/env python3

'''D&D manager bot for discord based RPGs

Note:
Any parameter value that has spaces in it needs to be wrapped in quotes "
unless it is the final parameter
Certain commands are only usable by the @DM role
'''

import re
import argparse
import asyncio
import logging
from collections import OrderedDict
from contextlib import closing

import discord
from discord.ext import commands
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

import model as m
from util import NoCharacterError, ItemNotFoundError
from util.equations import EquationError

bot = commands.Bot(
    command_prefix=';',
    description=__doc__,
    loop=asyncio.new_event_loop())


@bot.event
async def on_ready():
    '''
    Sets up the bot
    '''
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
    bot.change_presence(game=discord.Game(name='Type {}help for command list'.format(bot.command_prefix)))


@bot.before_invoke
async def before_any_command(ctx):
    '''
    Set up database connection
    '''
    ctx.session = bot.Session()


@bot.after_invoke
async def after_any_command(ctx):
    '''
    Tear down database connection
    '''
    ctx.session.close()
    ctx.session = None


@bot.event
async def on_command_error(ctx, error):
    if (isinstance(error, commands.CommandInvokeError)):
        error = error.original

    if isinstance(error, commands.CheckFailure):
        await ctx.send(
            'Error: You do not meet the requirements to use this command')
    elif isinstance(error, commands.CommandNotFound):
        if error.args:
            await ctx.send(error.args[0])
        else:
{'fraction_non_alphanumeric': 0.09324399776661083, 'fraction_numerical': 0.0013958682300390843, 'mean_word_length': 3.396319018404908, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2838125', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1018, 'n_words': 347}