134 lines
3.4 KiB
Markdown
134 lines
3.4 KiB
Markdown
# Rust Wipe Countdown Discord Webhook <a href='https://ko-fi.com/cjgameslive' target='_blank'><img height='35' align='right' style='border:0px;height:46px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||
|
||
A lightweight Python script that automatically posts or updates a Discord embed showing the **next Rust monthly wipe**, including:
|
||
|
||
- A DST‑safe UK timestamp (auto‑adjusts GMT/BST)
|
||
- A relative timestamp (`in 3 weeks`, `in 2 days`, etc.)
|
||
- A dynamic colour indicator (green/yellow/red)
|
||
- A 10‑segment emoji progress bar
|
||
- A “Last updated” footer timestamp
|
||
- Automatic create/edit mode for Discord webhooks
|
||
|
||
Perfect for Rust community servers that want a clean, automated countdown updated via cron.
|
||
|
||
---
|
||
|
||
## How It Works
|
||
|
||
The script calculates the **first Thursday of next month** — the official Rust wipe day — and sets the wipe time to **19:00 UK time**.
|
||
|
||
### DST‑Safe Date Handling
|
||
|
||
The script uses:
|
||
|
||
- `pytz.timezone("Europe/London")`
|
||
- `tz.localize(...)`
|
||
- UTC conversion only when generating the UNIX timestamp
|
||
|
||
This ensures the embed always shows **19:00 UK time**, even when the UK switches between GMT and BST.
|
||
|
||
### Dynamic Colour Logic
|
||
|
||
The embed colour changes based on how many days remain:
|
||
|
||
| Days Left | Colour | Meaning |
|
||
|----------|--------|---------|
|
||
| > 7 | Green | Plenty of time |
|
||
| 3–7 | Yellow | Getting close |
|
||
| < 3 | Red | Imminent wipe |
|
||
|
||
### Emoji Progress Bar
|
||
|
||
The script calculates the time between:
|
||
|
||
- **Last wipe** (previous first Thursday @ 19:00)
|
||
- **Next wipe**
|
||
|
||
Then fills a 10‑segment bar with:
|
||
|
||
- 🟩 (green)
|
||
- 🟨 (yellow)
|
||
- 🟥 (red)
|
||
|
||
depending on how close the wipe is.
|
||
|
||
Example:
|
||
🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜ 30%
|
||
|
||
|
||
### Webhook Create/Edit
|
||
|
||
The script supports two modes:
|
||
|
||
- `"create"` — posts a new message
|
||
- `"edit"` — updates an existing message using its ID
|
||
|
||
This allows you to run the script via cron without spamming your channel.
|
||
|
||
---
|
||
|
||
## Configuration
|
||
|
||
Before running the script, update the following fields:
|
||
|
||
```python
|
||
WEBHOOK_URL = ""
|
||
MODE = "create"
|
||
MESSAGE_ID = ""
|
||
```
|
||
|
||
### 1. WEBHOOK_URL
|
||
Paste your Discord webhook URL:
|
||
```WEBHOOK_URL = "https://discord.com/api/webhooks/XXXX/XXXX"```
|
||
|
||
### 2. MODE
|
||
- First run:
|
||
```MODE = "create"```
|
||
- After the message is created, copy its ID and switch to:
|
||
```MODE = "edit"```
|
||
|
||
### 3. MESSAGE_ID
|
||
Only required in edit mode.
|
||
|
||
Right‑click the message → Copy Message Link → extract the ID at the end.
|
||
|
||
Example:
|
||
```https://discord.com/channels/.../1555000080555554444```
|
||
|
||
So:
|
||
```MESSAGE_ID = "1555000080555554444"```
|
||
|
||
## Installation
|
||
Install dependencies:
|
||
```pip install requests pytz```
|
||
|
||
## Running the Script
|
||
Manual Run:
|
||
```python updater.py```
|
||
|
||
Cron Automation (Recommended)
|
||
Example: update every hour
|
||
```0 * * * * /usr/bin/python3 /home/pi/discord-bot/updater.py```
|
||
|
||
## File Overview
|
||
|
||
| Function | Purpose |
|
||
|----------|--------|
|
||
| next_first_thursday() | Calculates next Rust wipe date/time (DST‑safe) |
|
||
| get_dynamic_color() | Chooses embed colour based on days remaining |
|
||
| build_progress_bar() | Generates emoji progress bar |
|
||
| create_message() | Sends a new webhook message |
|
||
| edit_message() | Updates an existing webhook message |
|
||
| Main block | Chooses create/edit mode and sends the embed |
|
||
|
||
## Example Output
|
||
|
||
```
|
||
Next server wipe:
|
||
Thursday, 4 June 2026 19:00
|
||
Relative: in a month
|
||
|
||
🟩🟩⬜⬜⬜⬜⬜⬜⬜⬜ 20%
|
||
Last updated: 2026-05-07 20:47:27
|
||
```
|