Skip to content

drogers0/random_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Server

A small Python script that randomly starts or stops a game via Steam, and notifies you via a Discord webhook.


Table of Contents

  1. Features
  2. Requirements
  3. Setup
    1. Clone the repo
    2. Create & activate a virtual environment
    3. Install dependencies
    4. Create env.py
  4. Usage
  5. Scheduling with Windows Task Scheduler
  6. License

Features

  • Detects whether a given process (your game) is running.
  • Starts the game via its Steam URL if it’s not already running.
  • Stops the game after a 2-minute delay, if it is running.
  • Sends “Game started” / “Stopping game in 2 minutes” notifications to a Discord webhook.
  • Randomly chooses between starting or stopping each time it runs.

Requirements

  • Windows (script uses os.startfile to launch Steam URLs).
  • Python 3.x
  • A valid Discord webhook URL.
  • The Steam protocol URL for your game (e.g. steam://rungameid/570).
  • The process name of your game’s executable (e.g. dota2.exe).

Setup

Clone the repo

git clone https://github.com/drogers0/random_server.git
cd random_server

Create & activate a virtual environment

# Using built-in venv (Python 3.x)
python -m venv venv

# On Windows PowerShell:
.\venv\Scripts\Activate.ps1

# On Windows CMD:
.\venv\Scripts\activate.bat

Install dependencies

pip install -r requirements.txt

Create env.py

In the project root, create a file named:

env.py

Populate it with these three variables:

# env.py

# 1) Your Discord webhook URL.
#    Create one in your server: Server Settings → Integrations → Webhooks → New Webhook.
WEBHOOK_URL = "https://discord.com/api/webhooks/…"

# 2) The process name (EXE) of your game. Start the game, and then use ps in powershell and look for the ProcessName of your game.
#    e.g., "PalServer", etc.
PROCESS_NAME = "your_game_executable"

# 3) The Steam protocol URL for launching the game.
#    You can find it in Steam by right-clicking the game → Properties → General → Launch Options.
#    Or use your game’s AppID: steam://rungameid/##### 
STEAM_URL = "steam://rungameid/123456"

Usage

Once your venv is active and env.py is configured, just run:

python random_server.py

Each run will randomly choose to start or stop the game, and will send an appropriate Discord notification.


Scheduling with Windows Task Scheduler

To run this script hourly:

# 1) Open PowerShell **as Administrator** and cd into your repo:
cd C:\path\to\random_server

# 2) Run the scheduler script to create/update the task:
.\schedule_task.ps1

# You should see:
# Scheduled task 'RandomServer' created: runs random_server.py every hour.

# 3) Verify it exists (optional):
Get-ScheduledTask -TaskName RandomServer | Format-List *

# 4) To cancel and remove the task entirely:
Unregister-ScheduledTask -TaskName RandomServer -Confirm:$false

# 5) (Optional) Double-check removal:
Get-ScheduledTask -TaskName RandomServer
# → Should return “No scheduled tasks found.”

About

Randomly starts or stops a game via steam, and notifies you via a discord webhook.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published