def get_rarity():
    chances = Config.get_by_key("rarity")
    probab = sorted([int(i) for i in chances.keys()])
    roll = random.random() * 100
    for chance in probab:
        if (roll < chance):
            return chances[str(chance)]
    def __init__(self):
        host = Config.get_by_key('db_host')
        user = Config.get_by_key('db_user')
        passwd = Config.get_by_key('db_pass')
        
        if DatabaseHandler.__handle == None:
            try:
                DatabaseHandler.__handle = MySQLdb.connect(host = host, user = user, passwd = passwd)
            except Exception as e:
                print('Error connecting to database: ' + str(e))

            test_db_name = Config.get_by_key('test_db_name')
            try:
                DatabaseHandler.__handle.query('USE ' + test_db_name + ";")
            except Exception as e:
                print('Error setting the database we are going to use: ' + str(e))
Beispiel #3
0
                    await author.send("There are " + str(cnt) + " monsters in this region")
                    for ir in irs:
                        sql = f"SELECT * FROM monsters WHERE id = {ir['id_monster']}"
                        assert db.get_query(sql)
                        c = db.last_cursor
                        assert c.rowcount == 1
                        item = c.fetchone()

                        await author.send(f"    {item['name']} with stats hp: {item['starthp']} deffense: {item['defense']} attack: {item['attack']}")

                
            if p.get_command() == 'help':
                msg = Langs.get_text("tutorial_confirm")
                
                await message.channel.send(msg)
            # Should split on regex with multiple spaces
            parts = message.content.strip().split(' ')
            if len(parts) == 1:
                response = "What " + parts[0] + "??"
            else:
                command = parts[0]
                arg = parts[1]
                response = CmdInterpreter.interact(player.discord_id,command,arg)
            await message.author.send(response)

if __name__ == "__main__":
    Config.load_from('config.json')
    Langs.load_json(Path("res","langs","eng.json"))
    client = MyClient()
    client.run(Config.get_by_key('token'))