Skip to content

Commit

Permalink
Merge pull request #241 from ppfeufer/discordproxy-config
Browse files Browse the repository at this point in the history
[ADD] Optional settings for Discord Proxy (#240)
  • Loading branch information
ppfeufer authored Dec 5, 2024
2 parents 55f3f07 + b0d6075 commit c8dee81
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Section Order:
### Added

- Proper JS settings override
- Optional settings for Discord Proxy. Comes in handy when used in a Docker environment. (#240)

### Changed

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ______________________________________________________________________
- [Step 4: Preload Eve Universe Data](#step-4-preload-eve-universe-data)
- [Step 5: Setting up Permissions](#step-5-setting-up-permissions)
- [Step 6: (Optional) Import From Built-in SRP Module](#step-6-optional-import-from-built-in-srp-module)
- [Step 7: (Optional) Settings for Discord Proxy (If Used)](#step-7-optional-settings-for-discord-proxy-if-used)
- [Permissions](#permissions)
- [Changelog](#changelog)
- [Translation Status](#translation-status)
Expand Down Expand Up @@ -165,6 +166,15 @@ To import your SRP information from the built-in SRP module, run the following c
python manage.py aasrp_migrate_srp_data
```

### Step 7: (Optional) Settings for Discord Proxy (If Used)<a name="step-7-optional-settings-for-discord-proxy-if-used"></a>

If you are using [Discord Proxy] to send Discord messages, you can configure the host and port in your `local.py` settings.

| Name | Description | Default |
| ------------------- | ------------------------------------------------ | ----------- |
| `DISCORDPROXY_HOST` | Hostname used to communicate with Discord Proxy. | `localhost` |
| `DISCORDPROXY_PORT` | Port used to communicate with Discord Proxy. | `50051` |

## Permissions<a name="permissions"></a>

| ID | Description | Notes |
Expand Down
10 changes: 10 additions & 0 deletions aasrp/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

# Django
from django.apps import apps
from django.conf import settings

# Port used to communicate with Discord Proxy
DISCORDPROXY_PORT = getattr(settings, "DISCORDPROXY_PORT", 50051)

# Host used to communicate with Discord Proxy
DISCORDPROXY_HOST = getattr(settings, "DISCORDPROXY_HOST", "localhost")

# Timeout for Discord Proxy communication
DISCORDPROXY_TIMEOUT = getattr(settings, "DISCORDPROXY_TIMEOUT", 300)


def allianceauth_discordbot_installed() -> bool:
Expand Down
11 changes: 9 additions & 2 deletions aasrp/discord/channel_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

# AA SRP
from aasrp import __title__
from aasrp.app_settings import allianceauth_discordbot_installed, discordproxy_installed
from aasrp.app_settings import (
DISCORDPROXY_HOST,
DISCORDPROXY_PORT,
DISCORDPROXY_TIMEOUT,
allianceauth_discordbot_installed,
discordproxy_installed,
)
from aasrp.constants import DISCORD_EMBED_COLOR_MAP

logger = LoggerAddTag(get_extension_logger(__name__), __title__)
Expand Down Expand Up @@ -106,7 +112,8 @@ def _discordproxy_send_channel_message(
from discordproxy.client import DiscordClient
from discordproxy.exceptions import DiscordProxyException

client = DiscordClient()
target = f"{DISCORDPROXY_HOST}:{DISCORDPROXY_PORT}"
client = DiscordClient(target=target, timeout=DISCORDPROXY_TIMEOUT)

try:
logger.debug(msg="Trying to send a channel message via discordproxy")
Expand Down

0 comments on commit c8dee81

Please sign in to comment.