Exemplo n.º 1
0
async def profile(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        try:

            with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                data = json.load(f)
                for n in data['nations']:
                    if n['name'] == titleCase(nation):
                        if 'descrip' in n:
                            embed = discord.Embed(title=nation.upper(),
                                                  description=n['descrip'],
                                                  color=0xeee657)
                        else:
                            embed = discord.Embed(
                                title=nation.upper(),
                                description=wiki.getSummary(
                                    titleCase(nation).replace(' ', '%20')),
                                color=0xeee657)
                        embed.add_field(name="Head of State",
                                        value=idToName(ctx, n['hos']),
                                        inline=False)
                        embed.add_field(name="Capital City",
                                        value=n['cap'],
                                        inline=False)
                        embed.add_field(name="ISO Code",
                                        value=n['iso'],
                                        inline=False)
                        embed.add_field(name="Central Bank",
                                        value=n['bank'],
                                        inline=False)
                        embed.add_field(name="Population",
                                        value=str(len(n['members'])) +
                                        '; use `.citizens "' +
                                        titleCase(nation) +
                                        '"` to see citizens',
                                        inline=False)
                        embed.add_field(name="Cities",
                                        value=str(len(n['cities'])) +
                                        '; use `.cities "' +
                                        titleCase(nation) + '"` to see cities',
                                        inline=False)
                        await ctx.send(embed=embed)
                        return
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
        except ValueError:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 2
0
async def leave(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        if valExists(ctx, 'name', titleCase(nation)):
            if valExists(ctx, 'members', ctx.message.author.id):
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(nation):
                            if ctx.message.author.id in n['members']:
                                n['members'].remove(ctx.message.author.id)
                                if n['hos'] == ctx.message.author.id:
                                    if len(n['members']) >= 1:
                                        n['hos'] = n['members'][0]
                                        await ctx.send(
                                            ctx.message.author.display_name +
                                            '! You are the Head of State. You will be preceded by '
                                            + idToName(n['members'][0]) + '.')
                                    else:
                                        data['nations'].remove(n)
                                        await ctx.send(
                                            ctx.message.author.display_name +
                                            '! You are the last member of this nation. '
                                            + titleCase(nation) +
                                            ' will be disbanded.')
                            else:
                                await ctx.send(
                                    ctx.message.author.display_name +
                                    '! You are not a member of that nation.')
                                return
                os.remove('game/data' + str(ctx.guild.id) + '.json')
                with open('game/data' + str(ctx.guild.id) + '.json', 'w') as f:
                    json.dump(data, f, indent=4)
                await ctx.send(ctx.message.author.display_name +
                               ' left the nation of ' + titleCase(nation) +
                               '.')
            else:
                await ctx.send(ctx.message.author.display_name +
                               '! You are currently stateless.')
        else:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 3
0
async def join(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        if valExists(ctx, 'name', titleCase(nation)):
            if not valExists(ctx, 'members', ctx.message.author.id):
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(nation):
                            n['members'].append(ctx.message.author.id)
                os.remove('game/data' + str(ctx.guild.id) + '.json')
                with open('game/data' + str(ctx.guild.id) + '.json', 'w') as f:
                    json.dump(data, f, indent=4)
                await ctx.send(ctx.message.author.display_name +
                               ' joined the nation of ' + titleCase(nation) +
                               '.')
            else:
                await ctx.send(ctx.message.author.display_name +
                               '! You are already in a nation.')
        else:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 4
0
async def cities(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        try:
            stage = '```CITIES OF ' + nation.upper() + '\n'
            with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                data = json.load(f)
                for n in data['nations']:
                    if n['name'] == titleCase(nation):
                        for cit in n['cities']:
                            stage += ' - ' + cit + '\n'
                        stage += '```'
                        await ctx.send(stage)
                        return
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
        except ValueError:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 5
0
async def establish(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        if not valExists(ctx, 'name', titleCase(nation)):
            if not valExists(ctx, 'members', ctx.message.author.id):
                currISO = [
                    line.rstrip('\n')
                    for line in open('game/isolog' + str(ctx.guild.id) +
                                     '.txt')
                ]
                iso = setISO(nation, currISO)
                city = titleCase(nation) + random.choice([
                    ' City', 'shire', ' Town', 'berg', 'borough', 'grad',
                    'jing', 'kyo', 'ville', 'field', 'view', 'town', 'fast'
                ])
                bank = 'Bank of ' + titleCase(nation)
                if ctx.message.author.bot:
                    hos = ctx.message.author.display_name
                else:
                    hos = ctx.message.author.id
                try:
                    with open('game/data' + str(ctx.guild.id) + '.json',
                              'r') as f:
                        data = json.load(f)
                        data['nations'].append({
                            'name':
                            titleCase(nation),
                            'iso':
                            iso,
                            'hos':
                            hos,
                            'members': [ctx.message.author.id],
                            'cap':
                            city,
                            'cities': [city],
                            'bank':
                            bank
                        })
                except ValueError:
                    data = {}
                    data['nations'] = []
                    data['nations'].append({
                        'name': titleCase(nation),
                        'iso': iso,
                        'hos': hos,
                        'members': [ctx.message.author.id],
                        'cap': city,
                        'cities': [city],
                        'bank': bank
                    })
                f = open('game/isolog' + str(ctx.guild.id) + '.txt', 'a')
                f.write(iso + '\n')
                f.close()
                os.remove('game/data' + str(ctx.guild.id) + '.json')
                with open('game/data' + str(ctx.guild.id) + '.json', 'w') as f:
                    json.dump(data, f, indent=4)
                await ctx.send(ctx.message.author.display_name +
                               ' established the growing nation of ' +
                               titleCase(nation) + '.')
            else:
                await ctx.send(ctx.message.author.display_name +
                               '! You are already in a nation.')
        else:
            await ctx.send(ctx.message.author.display_name +
                           '! That nation has already been established.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 6
0
async def bank(ctx, nation: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        try:
            total = 0
            total_e = 0
            stage = ''
            with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                data = json.load(f)
                for n in data['nations']:
                    if n['name'] == titleCase(nation):
                        stage = '```' + n['bank'] + '\n'
                        if 'usd' in n and 'eur' in n and 'curr' in n:
                            stage += '1 USD is ' + str(
                                n['usd']
                            ) + ' ' + n['curr'] + '.\n1 EUR is ' + str(
                                n['eur']) + ' ' + n['curr'] + '\n'
                        with open('game/users' + str(ctx.guild.id) + '.json',
                                  'r') as f:
                            data = json.load(f)
                            for u in data['users']:
                                if u['id'] in n['members']:
                                    with open('data/dataRecord.json',
                                              'r') as rf:
                                        rates = json.load(rf)
                                        networth = 0
                                        networth_e = 0
                                        ratelist = list(u['balance'].keys())
                                        for r in range(len(ratelist)):
                                            if ratelist[r] != 'USD':
                                                networth += u['balance'][
                                                    ratelist[r]] / rates['usd'][
                                                        len(rates['usd']) -
                                                        1]['rates'][
                                                            ratelist[r]]
                                            else:
                                                networth += u['balance'][
                                                    ratelist[r]]
                                            if ratelist[r] != 'EUR':
                                                networth_e += u['balance'][
                                                    ratelist[r]] / rates['eur'][
                                                        len(rates['eur']) -
                                                        1]['rates'][
                                                            ratelist[r]]
                                            else:
                                                networth_e += u['balance'][
                                                    ratelist[r]]
                                        total += networth
                                        total_e += networth_e
                        stage += 'National net worth (USD): ' + str(
                            "%.2f" %
                            total) + '\nNational net worth (EUR): ' + str(
                                "%.2f" % total_e) + '```'
                        await ctx.send(stage)
                        return
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
        except ValueError:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')
Exemplo n.º 7
0
async def set(ctx, item: str, nation: str, content: str):
    if os.path.exists('game/data' + str(ctx.guild.id) + '.json'):
        if valExists(ctx, 'name', titleCase(nation)):
            if item == 'description':
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(
                                nation) and n['hos'] == ctx.message.author.id:
                            n['descrip'] = content
                            f.close()
                            os.remove('game/data' + str(ctx.guild.id) +
                                      '.json')
                            with open(
                                    'game/data' + str(ctx.guild.id) + '.json',
                                    'w') as f:
                                json.dump(data, f, indent=4)
                            await ctx.send(ctx.message.author.display_name +
                                           ' changed the national desription.')
                            return
                await ctx.send(
                    ctx.message.author.display_name +
                    '! You are not the Head of State of that nation.')
            elif item == 'iso':
                currISO = [
                    line.rstrip('\n')
                    for line in open('game/isolog' + str(ctx.guild.id) +
                                     '.txt')
                ]
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(
                                nation) and n['hos'] == ctx.message.author.id:
                            if content not in currISO:
                                if (len(content) == 2 or
                                        len(content) == 3) and content.isalpha(
                                        ) and content == content.upper():
                                    n['iso'] = content
                                    f.close()
                                    f = open(
                                        'game/isolog' + str(ctx.guild.id) +
                                        '.txt', 'a')
                                    f.write(content + '\n')
                                    f.close()
                                    os.remove('game/data' + str(ctx.guild.id) +
                                              '.json')
                                    with open(
                                            'game/data' + str(ctx.guild.id) +
                                            '.json', 'w') as f:
                                        json.dump(data, f, indent=4)
                                    await ctx.send(
                                        ctx.message.author.display_name +
                                        ' changed the ISO code.')
                                else:
                                    await ctx.send(
                                        ctx.message.author.display_name +
                                        '! That is an incorrect ISO code format. ISO codes must be 2 to 3 uppercase Latin letters.'
                                    )
                            else:
                                await ctx.send(
                                    ctx.message.author.display_name +
                                    '! That ISO code already exists.')
                            return
                await ctx.send(
                    ctx.message.author.display_name +
                    '! You are not the Head of State of that nation.')
            elif item == 'capital':
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(nation) and n[
                                'hos'] == ctx.message.author.id and titleCase(
                                    content) in n['cities']:
                            n['cap'] = titleCase(content)
                            f.close()
                            os.remove('game/data' + str(ctx.guild.id) +
                                      '.json')
                            with open(
                                    'game/data' + str(ctx.guild.id) + '.json',
                                    'w') as f:
                                json.dump(data, f, indent=4)
                            await ctx.send(ctx.message.author.display_name +
                                           ' changed the capital city.')
                            return
                await ctx.send(
                    ctx.message.author.display_name +
                    '! You are not the Head of State of that nation.')
            elif item == 'bank':
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(
                                nation) and n['hos'] == ctx.message.author.id:
                            n['bank'] = titleCase(content)
                            f.close()
                            os.remove('game/data' + str(ctx.guild.id) +
                                      '.json')
                            with open(
                                    'game/data' + str(ctx.guild.id) + '.json',
                                    'w') as f:
                                json.dump(data, f, indent=4)
                            await ctx.send(ctx.message.author.display_name +
                                           ' changed the central bank.')
                            return
                await ctx.send(
                    ctx.message.author.display_name +
                    '! You are not the Head of State of that nation.')
            elif item == 'city':
                with open('game/data' + str(ctx.guild.id) + '.json', 'r') as f:
                    data = json.load(f)
                    for n in data['nations']:
                        if n['name'] == titleCase(
                                nation) and n['hos'] == ctx.message.author.id:
                            if len(n['members']) // 3 >= len(n['cities']):
                                if titleCase(content) not in n['city']:
                                    n['city'].append(titleCase(content))
                                    f.close()
                                    os.remove('game/data' + str(ctx.guild.id) +
                                              '.json')
                                    with open(
                                            'game/data' + str(ctx.guild.id) +
                                            '.json', 'w') as f:
                                        json.dump(data, f, indent=4)
                                    await ctx.send(
                                        ctx.message.author.display_name +
                                        ' added the city of ' +
                                        titleCase(content) + '.')
                                    return
                                await ctx.send(
                                    ctx.message.author.display_name +
                                    '! That city already exists.')
                                return
                            await ctx.send(
                                ctx.message.author.display_name +
                                '! You need a population of at least ' +
                                str(len(n['cities']) * 3) +
                                ' to establish another city')
                            return
                await ctx.send(
                    ctx.message.author.display_name +
                    '! You are not the Head of State of that nation.')
                return
        else:
            await ctx.send(ctx.message.author.display_name +
                           '! This nation does not exist.')
    else:
        await ctx.send(ctx.message.author.display_name +
                       '! Civilization has yet to be dawned.')