fork/Slippi-Presence

git clone https://git.julia.blue/fork/Slippi-Presence

MiguelFix linux compability issues and lets put code lowercase4a1f07c

maybe-final
2.1 KiB67 linesraw
1import time
2import configparser
3import glob
4import os
5from slippi import Game
6from pypresence import Presence
7
8config = configparser.ConfigParser()
9config.read('config.ini')
10path = config['Variables']['path']
11code = config['Variables']['code'].upper()
12
13support_dict = {"CAPTAIN_FALCON":['falcon','Captain Falcon'], "ICE_CLIMBERS": ['iceclimbers', "Ice Climbers"], "DONKEY_KONG": ["donkeykong", "Donkey Kong"], "GAME_AND_WATCH": ['gaw', "Mr. Game and Watch"], "YOUNG_LINK": ['younglink', "Young Link"], "DR_MARIO": ['drmario',"Doctor Mario"]}
14stages_dict = {"POKEMON_STADIUM": ['ps','Pokemon Stadium'], "FOUNTAIN_OF_DREAMS": ['fod', 'Fountain of Dreams'], "YOSHIS_STORY": ["yoshis", "Yoshi's Story"], "DREAM_LAND_N64": ['dl', 'Dreamland'], "BATTLEFIELD": ['bf',"Battlefield"], "FINAL_DESTINATION": ['fd','Final Destination']}
15
16client_id = '638163525029724180' 
17RPC = Presence(client_id) 
18RPC.connect() 
19
20while True:
21    list_of_files = glob.glob(path + "/*")
22    sorted_files = sorted(list_of_files, key=os.path.getctime)
23    game = Game(sorted_files[-2])
24    stage = str(game.start.stage)[6:]
25    playing_with = []
26    for player in game.metadata.players:
27        if player is None:
28            pass
29        else:
30            if str(player.netplay.code) == code:
31                char = str(list(player.characters.keys())[0])[16:]
32            else:
33                playing_with.append(player.netplay.code)
34    
35    if len(playing_with) == 1:
36        melee_type = "Melee Singles"
37    else:
38        melee_type = "Melee Doubles"
39
40
41    playing_with_str = "vs."
42    for person in playing_with:
43        playing_with_str += " " + person
44
45    try:
46        if char in support_dict.keys():
47            char_image, char_text = support_dict[char]
48        else:
49            char_image = char.lower()
50            char_text = char.capitalize()
51    
52    except:
53        continue
54
55    try:
56        stage_image, stage_text = stages_dict[stage]
57
58    except:
59        pass
60
61
62    print(RPC.update(state=playing_with_str, details=melee_type, large_image=stage_image, small_image=char_image, large_text=stage_text, small_text=char_text))
63    time.sleep(10)
64
65
66
67