ThiaudioTT / hoi4-presence

Hearts of Iron IV presence for Discord!
MIT License
14 stars 11 forks source link

Set the large_image via web #12

Closed ThiaudioTT closed 1 year ago

ThiaudioTT commented 1 year ago

We can set any image to large_image:

https://stackoverflow.com/questions/64417184/how-does-pypresence-work-where-do-i-get-the-image-key

Maybe we can upload the images on GitHub and use it as a source of flags instead of modifying in discord developer portal.

ThiaudioTT commented 1 year ago

Example of an image in GitHub:

https://raw.githubusercontent.com/ThiaudioTT/ThiaudioTT/main/img/reisen.jpg

It seems that it follows a pattern, probably we can use it.

Wolfmyths commented 1 year ago

Maybe we can use a JSON file on the github repo where the key would be the country and the value would be the link to the image?

I could be wrong, but I think we can request a raw version of files like JSON.

We could use a request.get on the JSON and get the link of the image from there

Wolfmyths commented 1 year ago

Quick update:

It is possible

https://stackoverflow.com/questions/60219180/importing-json-file-from-github-into-python-getting-error-jsondecodeerror-exp

ThiaudioTT commented 1 year ago

Maybe we can use a JSON file on the github repo where the key would be the country and the value would be the link to the image?

That's a possible way of doing it, but I think that uploading the image on the web and setting it on the countries.py should be enough

Wolfmyths commented 1 year ago

That's a possible way of doing it, but I think that uploading the image on the web and setting it on the countries.py should be enough

Oh like a dictionary in countries.py instead of the repo? That would be an easier way to do it.

ThiaudioTT commented 1 year ago

Oh like a dictionary in countries.py instead of the repo? That would be an easier way to do it.

Yes! It can be a hash table, currently we are doing using the match condition:

   match country:
      case "GER":
         country = "Germany"
         flag = "german_reich"
      case "ITA":
         country = "Italy"
         flag = "italy"
      case "JAP":
         country = "Japan"
         flag = "japan"
      case "EXAMPLE"
         country = "country example"
         flag = "https://sourceForCountryExample.jpg"

But I don't know if using hash table would be better:

country = countries[countryInput]
flag = country['flag']

There's several ways to do it, but I wanna go with the simplest and efficient one.

Wolfmyths commented 1 year ago

What if the dictionary had a tuple in it like this:

_dict = {
  "GER"  : ("Germany", "german_reich"), 
  "ITA"  : ("Italy", "italy")
}

# Accessing dict
country = _dict[countryInput][0]
flag = _dict[countryInput][1]

This would remove the switch statement completely

Edit:

I made changes to my fork to show what it would look like, I would have made a pull request but I don't have the link to the assets so for now theres placeholders where the img link is supposed to be.

https://github.com/Wolfmyths/hoi4-presence/commit/66a43d2e9dbe4dcb5e0961a95cc70ae2e8216b72

ThiaudioTT commented 1 year ago

I made changes to my fork to show what it would look like, I would have made a pull request but I don't have the link to the assets so for now theres placeholders where the img link is supposed to be.

Nice, lgtm.

I don't have the link to the assets For these countries already added, I don't think we need to set new ones

For others though: https://hoi4.paradoxwikis.com/Countries

We can use the source on the wiki.

ThiaudioTT commented 1 year ago

We can go that way:

Use that tuple and set the image not in github, but instead on imgurl (for cases where is fictional country) or hoi4 wiki ("built-in countries").

Wolfmyths commented 1 year ago

I think Hoi4 wiki is a nice start, I'm not sure how we'd add fictional countries without manually doing so.

I'm a little confused. On the wiki there are two tables listing countries, do we want to add the 2nd table too? Or just the 1st.

ThiaudioTT commented 1 year ago

I'm not sure how we'd add fictional countries without manually doing so.

Fictional countries we need to add manually. These countries are mods, I'm saying this because we probably want to add in the future.

On the wiki there are two tables listing countries, do we want to add the 2nd table too? Or just the 1st.

You are talking about "releasable countries"? We need to add them too.

These releasable countries are countries that at the early of the game does not exist. As the game advances, these countries may appear.

Wolfmyths commented 1 year ago

Okay, working on it now. The only issue I am seeing is that some countries have more than one tag like Bulgaria and Italy.

I'm not sure what this looks like in-game or in the save file. So I'm not sure if this is something we should be worried about.

There are also some countries that have the tag D## such as Vojvodina and Dalmatia.

I'm unsure what to do about those countries either.

We could make a switch-case for these special cases but there's no way to differentiate countries with the same tag like Vojvodina and Dalmatia because of getCountry()'s parameters.

ThiaudioTT commented 1 year ago

I'm not sure what this looks like in-game or in the save file. So I'm not sure if this is something we should be worried about.

I think the main script care about this part, the caller function needs to send the correct tag and deal with picking it and the getCountry only update the image and the flag based on it.

If you hover the mouse on the tag, it will say the country's name image

I've never seen these additional tags personally and I could be wrong but I think that the main tag should be enough. Even the wiki apparently doesn't know about it.

If you have anymore doubts about it, see: https://forum.paradoxplaza.com/forum/threads/hoi4-resource-history-spreadsheet-updated-to-include-barbarossa-1-11-5.1509285/

There are also some countries that have the tag D## such as Vojvodina and Dalmatia.

Indeed, it seems that these tags are for civil war countries and I don't know how the game differentiates it, but this is a very special case, rarely someone play as one.

I think that we can just ignore for now and create an issue to investigate it.

Wolfmyths commented 1 year ago

Okay so update, I made a web scraper and automated the process of adding every country in the game.

https://github.com/Wolfmyths/hoi4-presence/commit/5be25827c848a13551a9bda63776423133da38ce

This adds up to 259 countries total. The hashmap was very much needed lmao.

As the commit description says, there are some countries that don't have a wiki page at all. The thumbnail images of those countries are probably too small to use. So I'm guessing we're going to use imgur for these?

The dictionary is really big so if you want to put it in a separate file or put it somewhere else in the script let me know.

ThiaudioTT commented 1 year ago

Okay so update, I made a web scraper and automated the process of adding every country in the game.

Nice

As the commit description says, there are some countries that don't have a wiki page at all. The thumbnail images of those countries are probably too small to use. So I'm guessing we're going to use imgur for these?

Yes

The dictionary is really big so if you want to put it in a separate file or put it somewhere else in the script let me know.

Put in the end of the file. I think exporting to another file would be bad because python treat as a module. But you tell me, if putting in another file is better, go in this way.

Wolfmyths commented 1 year ago

Alright I was able to find even more flags on the wiki. Almost all countries have image links. But some came out to be like in a super small resolution. And some flags I was just not able to find at all on imgur and the wiki.

The flags I found on imgur may also be different than the game's since the country's flag may have changed since WW2.

Put in the end of the file.

I forgot to put this in the commit description but I also moved the dictionary to the bottom of the script

https://github.com/Wolfmyths/hoi4-presence/commit/7ccf945015f7686a4f48b4a56bf25604cce8638f

ThiaudioTT commented 1 year ago

But some came out to be like in a super small resolution. And some flags I was just not able to find at all on imgur and the wiki.

You can upload it on imgur or just use the image on wikipedia.

ThiaudioTT commented 1 year ago

Closed: #27