Skip to content

Commit

Permalink
updated the readme, version on main.py and fixed one silly mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
Otakubuns committed Dec 1, 2024
1 parent b02fdee commit a1013a3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
5 changes: 2 additions & 3 deletions My Script Mods/Sims4DRP/Scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def LoadDefaultConfig():
'showModeIcon': 'True'
}


def IsConfigMissing():
"""Checks if the config file is missing."""
path = os.path.join(os.path.dirname(__file__), os.path.pardir, 'discordRPC.cfg')
Expand All @@ -47,6 +46,6 @@ def IsConfigMissing():
def IsHouseholdFundsUsed(config):
"""Checks if the config file uses the household funds placeholder."""
for value in config.values():
if "{Household_Funds}" in value:
return True
if "{Household_Funds}" in value:
return True
return False
14 changes: 3 additions & 11 deletions My Script Mods/Sims4DRP/Scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

# Sims 4 Discord Rich Presence
# Created by: Otakubuns
# Version: 1.0.5
# Last Updated: 2024-11-28
# Version: 1.0.7
# Last Updated: 2024-11-30
# Description: Adds Discord Rich Presence to The Sims 4 with injection methods for CAS, Build/Buy, and Live Mode.
# Also adds world icons, household funds & name.
# Also adds world icons, household funds & name. Configurable through the discordRPC.cfg file

# DRP Variables
client_id = '971558123531804742'
Expand Down Expand Up @@ -178,7 +178,6 @@ def GetHouseholdFunds():
return None
return f"§{services.active_household().funds.money:,}"


def GetWorldName():
if services.current_zone_id() is None:
return None
Expand Down Expand Up @@ -253,10 +252,3 @@ def ResolveConfigValueFunctions(config_value):
config_value = config_value.replace(placeholder, "")
logger.error(f"Error resolving placeholder {placeholder}: {e}")
return config_value

def IsHouseholdFundsUsed():
"""Checks if the config file uses the household funds placeholder."""
for value in raw_config.values():
if "{Household_Funds}" in value:
return True
return False
20 changes: 11 additions & 9 deletions My Script Mods/Sims4DRP/Scripts/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, client_id):
try:
self.client_id = client_id
self.connection_established = False
self.connection_attempts = 0 # Counter for connection attempts(if the connection is broken/lost even if Discord is open)
self.connection_attempts = 0 # Counter for connection attempts(if the connection is broken/lost even if Discord is open)
self._connect_and_handshake()
except Exception as e:
self.connection_established = False
Expand Down Expand Up @@ -145,14 +145,20 @@ def recv(self) -> (int, "JSON"):
data = json.loads(payload.decode('utf-8'))
return op, data

reconnect_notification = False # So it doesnt log the reconnect message multiple times
discord_open_notification = False # So it doesnt log the discord not open message multiple times
reconnect_notification = False # So it doesnt log the reconnect message multiple times
discord_open_notification = False # So it doesnt log the discord not open message multiple times

# Edited from pypresence for convenience(https://github.com/qwertyquerty/pypresence/blob/master/pypresence/presence.py)
def set_activity(self, state=None, details=None, start=None, large_image=None, large_text=None,
small_image=None, small_text=None):
"""Set activity for the user, reconnecting only if Discord is open."""
if not self._is_discord_open():
if not self.discord_open_notification:
logger.error("Discord is not running. Please open Discord and try again.")
self.discord_open_notification = True
return

delay(0.5) # Added to add a delay as too fast breaks the presence update
# delay(0.5) # Added to add a delay as too fast breaks the presence update
# Even if connection boolean is set to true, it may not be connected if an error occurs so make sure to check connection_attempts
if self.connection_attempts >= 3:
if not self.reconnect_notification:
Expand All @@ -163,11 +169,6 @@ def set_activity(self, state=None, details=None, start=None, large_image=None, l

try:
if not self.connection_established:
if not self._is_discord_open():
if not self.discord_open_notification:
logger.error("Discord is not running. Please open Discord and try again.")
self.discord_open_notification = True
return
self._connect_and_handshake() # Attempt to reconnect if connection isn't established

data = {
Expand Down Expand Up @@ -218,6 +219,7 @@ def _is_discord_open(self):
print(f"Error checking if Discord is open: {e}")
return False


# Taken from pypresence(https://github.com/qwertyquerty/pypresence/blob/master/pypresence/utils.py)
def remove_none(d: dict): # Made by https://github.com/LewdNeko ;^)
for item in d.copy():
Expand Down
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
# Sims 4 Discord Rich Presence

This is a mod for The Sims 4 utilizing Discord Rich Presence.
The Sims 4 mod utilizing Discord Rich Presence.
<br>**Compatible with World Rename Mod**

It currently:
## Features
- Shows current world & Household Name
- Shows when in Build/Buy (with small images for gamemode(build/buy & live))
- Shows household money and updates when it changes
- Shows when in CAS in game(not New Game(yet))
- Shows when in Build/Buy (with small images for gamemode (build/buy & live))
- Shows household funds and updates when it changes
- Shows when in CAS in game(not New Game or modded CAS(MCCC))
- Config file for customizing what is shown

![preview_gif](https://github.com/Otakubuns/Sims4-DRP/assets/77337386/7cca21f3-935d-4d47-b710-f40e1f436b6c)





### Compatibility
Mac has not been tested but should work fine.

## Getting Started
### Installing
Make sure you have Rich Presence enabled in: Discord -> User Settings -> Activity Privacy -> Display current activity as a status message.<br><br>
Go to [releases](https://github.com/Otakubuns/Sims4-DRP/releases) and download the latest release.

## Future Plans for it are:
- ~~Show when in CAS(have no clue on this yet).~~ Have it working for in Game CAS(mirror, testingcheats) but New Game CAS is still a mystery.
- Configuration file for choosing to show household name, funds etc(already started just been lazy).
- ~~Allow Discord to be open after TS4 and still update presence.~~ Implemented in [1.0.6](https://github.com/Otakubuns/Sims4-DRP/releases/tag/1.0.6)
1. Make sure you have Rich Presence enabled in: Discord -> User Settings -> Activity Privacy -> Display current activity as a status message.
2. Go to [releases](https://github.com/Otakubuns/Sims4-DRP/releases) and download the latest release.
3. I have included a folder to easier drop into your mods folder with the config file, but if you so choose you can just drop the the files into your mods folder.

### Configuration
The configuration file should be in the same folder as the `.ts4script`. It is called `discordRPC.cfg`. There are instructions in the file as well as here. If the file is not there, the mod will just use the default settings built into the mod.

```
[Config]
details = {World_Name}
state = {Household_Name} | {Household_Funds}
largeIconText = {Lot_Name}
showWorldIcon = true
showModeIcon = true
```

There are some built in variables that can be used in the config file:
- `{World_Name}` - The name of the world the household is in.
- `{Household_Name}` - The name of the household.
- `{Household_Funds}` - The amount of money the household has.
- `{Lot_Name}` - The name of the lot the household is on.

### Issues
These are a list of issues that I am aware of ATM and either cannot fix or have no plans to:
- ~~Switching from build/buy to live very quickly will cause the presence to not update those states(everything else will still change accordingly). There is no way to fix this as it's just a matter of the presence update not being sent quick enough as it's changing so quick.~~ Haven't come across these issues anymore but i'll leave here in case it does pop up again.
- If using Better Exceptions, when an exception occurs and it is scanning your mods folder, the presence will break. It will come back once Better Exceptions is done scanning your mods folder.

### Disclaimer
I am not well versed in Sims 4 modding and my Python knowledge as well is not amazing(C# lover) so there may be better ways to do this. If you do notice something wrong feel free to let me know.
I am not well versed in Sims 4 modding and my Python knowledge as well is not amazing so there may be better ways to do this. If you do notice something wrong feel free to let me know.

## Acknowledgments
I would have never had this done without the **amazing** Sims 4 Modding community and their posts/documentation.
Expand Down

0 comments on commit a1013a3

Please sign in to comment.