Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mak8427 committed May 20, 2021
1 parent cdc072b commit 9652834
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 48 deletions.
106 changes: 58 additions & 48 deletions Discord_Bot.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import discord
import numpy as np
import random
from discord.ext import commands
from discord.utils import get
import os
from discord.ext.commands import cooldown, BucketType, CommandOnCooldown, Context, CommandNotFound, BadArgument
from discord.ext.commands import Bot as Botbase

import config
import pandas as pd
import requests as rq
from bs4 import BeautifulSoup
import csv
import json
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import time
import asyncio

import config
IGNORE_EXCEPTIONS = (CommandNotFound, BadArgument)
client = commands.Bot(command_prefix=',')


client.remove_command('help')
@commands.Cog.listener()
async def on_command_error(self, ctx, exc):
if isinstance(exc, CommandOnCooldown):
Expand All @@ -38,13 +28,24 @@ async def on_ready():


@client.command()
@cooldown(1,15, BucketType.user)
async def ping(ctx):
await ctx.send(f'pong {round(client.latency * 1000)}ms')


@client.command()
async def help1(ctx):
await ctx.send(f'if you want to make graphs use this format: \n ,graphs Skanderbeg_Save_ID \n Ex: ,graphs d852c8 ')
@client.command(pass_context=True)
@cooldown(1,15, BucketType.user)
async def help(ctx):
author=ctx.message.author
embed=discord.Embed(colour=discord.Colour.dark_blue())
embed.set_author(name='Help')
embed.add_field(name='Description',value='The Goal of this bot is to make graphs for Europa universalis 4,by using the Skanderbeg save data',inline=False)
embed.add_field(name=',ping',value='returns pong!',inline=False)
embed.add_field(name=',graphs',value=f'if you want to make graphs use this format: \n ,graphs Skanderbeg_Save_ID \n Ex: ,graphs d852c8 \n you can get the Skanderbeg_Save_ID in the skanderbeg site in the ID column in My Maps (https://skanderbeg.pm/maps.php)',inline=False)
embed.add_field(name=',creator', value='returns the discord id of me:the creator', inline=False)
await ctx.send(embed=embed)




@client.command()
Expand All @@ -71,7 +72,7 @@ async def graphs(ctx, *, code):
folder = ''
if folder == '':
print('please indicate the location of the folder where you want to store your graphs')
folder = r'C:\Users\dadoi\PycharmProjects\eugraphs'
folder = ''
with open('folder.txt', 'wt') as z:
z.write(str(folder))

Expand Down Expand Up @@ -374,7 +375,6 @@ def prova(listadf):
resp = ''
y = str(massimo)
print('how many nation do you want ot print? the max is ' + str(massimo) + resp)
y = str(20)
y = int(y)
f = 100 / y
alpha1 = 0.8
Expand Down Expand Up @@ -425,7 +425,7 @@ def prova(listadf):
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre
ax1.text(i - len(str(round(v, 1))) * sz, v + 0.5, str(round(v, 1)), color='black', fontweight='bold',
size=sizes)
plt.savefig(folder + '/dev')
plt.savefig(folder + 'dev.png')
plt.close()
if k == 1: # income
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -471,35 +471,42 @@ def prova(listadf):
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre
ax1.text(i - len(str(round(v))) * sz, v + 0.5, str(round(v)), color='black', fontweight='bold',
size=sizes)
plt.savefig(folder + '/income')
plt.savefig(folder + 'income.png')
plt.close()
if k == 2: # valore immobili
plt.figure(figsize=[19.2, 10.8])
s = s.sort_values(by=(len(s) - 1), axis=1, ascending=False)
hj = s.iloc[:, range(10, y)]
s = s.iloc[:, range(0, 10)]

others = 0
counting = 0
coloriar = []
hh = hj.values.tolist()
for value in hh[0]:
others = others + value
counting = counting + 1
s['Others'] = others
if y>10:
hj = s.iloc[:, range(10, y)]
s = s.iloc[:, range(0, 10)]
others = 0
counting = 0
coloriar = []
hh = hj.values.tolist()
for value in hh[0]:
others = others + value
counting = counting + 1
s['Others'] = others

for nomej in s.columns:
try:
coloriar.append(colornazioni[nomej])
except:
coloriar.append('gray')
for nomej in s.columns:
try:
coloriar.append(colornazioni[nomej])
except:
coloriar.append('gray')
else:
coloriar = []
for nomej in s.columns:
try:
coloriar.append(colornazioni[nomej])
except:
coloriar.append('gray')

ax2 = s.loc[len(s) - 1].plot.pie(autopct=lambda pct: func(pct, s.loc[len(s) - 1]), startangle=90,
radius=1.3, colors=coloriar)
plt.grid(axis='y', alpha=alphagrid)

ax2.text(-0.3, 1.5, 'Buildings Value', color='black', fontweight='bold', size=sizes)
plt.savefig(folder + '/Buildings Value')
plt.savefig(folder + 'Buildings Value.png')
plt.close()
if k == 3: # province
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -534,7 +541,7 @@ def prova(listadf):
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre.
ax1.text(i - len(str(round(v, 1))) * sz, v + 0.5, str(round(v, 1)), color='black', fontweight='bold',
size=sizes)
plt.savefig(folder + '/provinces')
plt.savefig(folder + 'provinces.png')
plt.close()
if k == 4:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -579,7 +586,7 @@ def prova(listadf):
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.5, str(round(v / 1000, 1)) + 'k',
color='black', fontweight='bold', size=sizes)

plt.savefig(folder + '/Battle casualities')
plt.savefig(folder + 'Battle casualities.png')
plt.close()
if k == 5:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -623,7 +630,7 @@ def prova(listadf):
ax2.text(i - 0.10, v + 1, str(round(v)) + '%', color='black', fontweight='bold', size=sizes)
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre
ax1.text(i - len(str(int(v))) * sz, v + 0.5, str(int(v)), color='black', fontweight='bold', size=sizes)
plt.savefig(folder + '/armies')
plt.savefig(folder + 'armies.png')
plt.close()
if k == 7:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -658,7 +665,7 @@ def prova(listadf):
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.5, str(round(v / 1000, 1)) + 'k',
color='black',
fontweight='bold', size=sizes)
plt.savefig(folder + '/Mana spent on devving')
plt.savefig(folder + 'Mana spent on devving.png')
plt.close()
if k == 8:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -696,7 +703,7 @@ def prova(listadf):
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.5, str(round(v / 1000, 1)) + 'k',
color='black',
fontweight='bold', size=sizes)
plt.savefig(folder + '/Mana spent on teching up')
plt.savefig(folder + 'Mana spent on teching up.png')
plt.close()
if k == 9:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -724,7 +731,7 @@ def prova(listadf):
else:
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.5, str(round(v / 1000, 1)) + 'k',
color='black', fontweight='bold', size=sizes)
plt.savefig(folder + '/moneyspent')
plt.savefig(folder + 'moneyspent.png')
plt.close()
if k == 10:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -774,7 +781,7 @@ def prova(listadf):
else:
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.5, str(round(v / 1000, 1)) + 'k',
color='black', fontweight='bold', size=sizes)
plt.savefig(folder + '/max manpower')
plt.savefig(folder + 'max manpower.png')
plt.close()
if k == 11:
plt.figure(figsize=[19.2, 10.8])
Expand Down Expand Up @@ -810,7 +817,7 @@ def prova(listadf):
ax2.text(i - 0.10, v + 1, str(round(v)) + '%', color='black', fontweight='bold', size=sizes)
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre
ax1.text(i - len(str(int(v))) * sz, v + 0.5, str(int(v)), color='black', fontweight='bold', size=sizes)
plt.savefig(folder + '/total navy')
plt.savefig(folder + 'total navy.png')
plt.close()
if k == 13:
try:
Expand Down Expand Up @@ -848,7 +855,7 @@ def prova(listadf):
for i, v in enumerate(s.loc[len(s) - 1]): # testo su barre
ax1.text(i - len(str(int(v))) * sz, v + 0.5, str(int(v)), color='black', fontweight='bold',
size=sizes)
plt.savefig(folder + '/dev clicks')
plt.savefig(folder + 'dev clicks.png')
plt.close()
except:
pass
Expand Down Expand Up @@ -914,7 +921,7 @@ def boh(lista):
ax1.text(i - len(str(round(v, 1))) * sz, v + 0.005, str(round(v, 1)), color='black', fontweight='bold',
size=sizes)
plt.title('avg dev')
plt.savefig(folder + '/avg dev')
plt.savefig(folder + 'avg dev.png')
plt.close()
plt.figure(figsize=[19.2, 10.8])

Expand All @@ -934,7 +941,7 @@ def boh(lista):
ax1.text(i - len(str(round(v / 1000, 1)) + 'k') * sz, v + 0.05, str(round(v / 1000, 1)) + 'k', color='black',
fontweight='bold', size=sizes)
plt.title('manpower per province')
plt.savefig(folder + '/manpower per province')
plt.savefig(folder + 'manpower per province.png')
plt.close()
plt.figure(figsize=[19.2, 10.8])
avgincome = [(a - 2) / b for a, b in zip(income.loc[0], dev.loc[0])]
Expand All @@ -952,7 +959,7 @@ def boh(lista):
for i, v in enumerate(dfavgincome.loc[len(dfavgincome) - 1]): # testo su barre
ax1.text(i - len(str(round(v, 2))) * sz, v, str(round(v, 2)), color='black', fontweight='bold', size=sizes)
plt.title('income per dev(nation efficency)')
plt.savefig(folder + '/income per dev(nation efficency)')
plt.savefig(folder + 'income per dev(nation efficency).png')
plt.close()

# diff income %
Expand Down Expand Up @@ -1027,12 +1034,15 @@ def differenza(playerincome, cosa):
png = jf + '.png'
with open(png, 'rb') as f:
picture = discord.File(f)

await ctx.send(file=picture)

print('check your graphs folder(Press ENTER to close)')
await ctx.send('Spam limiter: 2 minutes in Cooldown')


@client.command()
@cooldown(1,15, BucketType.user)
async def creator(ctx):
await ctx.send('My creator is mak84271#3674,and he is the best eu4 player')

Expand Down
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"NED":[{"inc_no_subs":"382.917","total_development":"1081","buildings_value":"38000","provinces":"59","total_army":"226","qualityScore":"146.2917365","total_mana_spent_on_deving":"6843","total_mana_on_teching_up":"30184","spent_total":"188739.422","fdp":"0.36","battleCasualties":"193130","max_manpower":"200000","continents":"eu as af na ","dev_clicks":"155","total_navy":"161","hex":"#dc8a39","player":"Quget","countryName":"Netherlands"}],"TTS":[{"inc_no_subs":"80.634","total_development":"739","buildings_value":"14800","provinces":"53","total_army":"120","qualityScore":"141.339459","total_mana_spent_on_deving":"3693","total_mana_on_teching_up":"23167","spent_total":"90501.118","fdp":"0.26","battleCasualties":"230330","max_manpower":"121000","continents":"eu af ","dev_clicks":"95","total_navy":"86","hex":"#9a999d","player":"Third Tier Gaming","countryName":"Two Sicilies"}],"PRU":[{"inc_no_subs":"69.953","total_development":"519","buildings_value":"19600","provinces":"32","total_army":"60","qualityScore":"154.803457","total_mana_spent_on_deving":"3972","total_mana_on_teching_up":"30330","spent_total":"64190.466","fdp":"0.4","battleCasualties":"175535","max_manpower":"99000","continents":"eu ","dev_clicks":"97","total_navy":"37","hex":"#8f8d80","player":"Luna Lupus","countryName":"Prussia"}],"GBR":[{"inc_no_subs":"230.8","total_development":"1331","buildings_value":"47100","provinces":"169","total_army":"111","qualityScore":"146.2767","total_mana_spent_on_deving":"81","total_mana_on_teching_up":"24926","spent_total":"167761.447","fdp":"0.14","battleCasualties":"231319","max_manpower":"92000","continents":"eu as af na sa ","dev_clicks":"41","total_navy":"87","hex":"#990000","player":"Viking_Nephilim","countryName":"Great Britain"}],"HAB":[{"inc_no_subs":"180.047","total_development":"1457","buildings_value":"63900","provinces":"101","total_army":"203","qualityScore":"150.833093","total_mana_spent_on_deving":"9495","total_mana_on_teching_up":"25609","spent_total":"189009.397","fdp":"0.49","battleCasualties":"622779","max_manpower":"361000","continents":"eu ","dev_clicks":"310","total_navy":"8","hex":"#dcdcdc","player":"vicdomen","countryName":"Austria"}]}

1 comment on commit 9652834

@vercel
Copy link

@vercel vercel bot commented on 9652834 May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.