Examples
Every example is type-checked against the same SDK as this reference.
Warn button with a reason list
Section titled “Warn button with a reason list”A button on the player card that warns with a reason chosen from a list.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', inputs: { reason: { kind: 'option', options: ['Teamkill', 'Toxic chat', 'Wrong role'], required: true }, }, name: 'Warn', async run(ctx) { await ctx.rcon(`AdminBroadcast Warning: ${ctx.input.reason}`) await ctx.note(`Warned: ${ctx.input.reason}`) }, trigger: { kind: 'button', label: 'Warn', on: 'player' },})Timed ban button
Section titled “Timed ban button”A button that bans for a number of hours typed by the moderator.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', inputs: { hours: { kind: 'number', required: true }, reason: { kind: 'text' }, }, name: 'Timed ban', async run(ctx) { const result = await ctx.ban({ for: `${ctx.input.hours}h`, reason: ctx.input.reason ?? 'Banned by a moderator', servers: 'all', })
if (!result.ok) { await ctx.note(`Ban failed: ${result.error}`) } }, trigger: { kind: 'button', label: 'Timed ban', on: 'player' },})Teamkill escalation with a pause
Section titled “Teamkill escalation with a pause”Escalates a teamkill to a permanent ban for players with earlier bans.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', name: 'Teamkill escalation', pause: { for: '10m', per: 'player' }, async run(ctx) { const bans = Number(await ctx.player.bansCount())
if (bans >= 3) { await ctx.ban({ for: 'permanent', reason: 'Repeat teamkiller', servers: 'all' }) return }
await ctx.note('Teamkill recorded') await ctx.rcon('AdminBroadcast Teamkilling is a bannable offence.') }, trigger: { event: 'teamkill', kind: 'event' },})Note on a young Steam account
Section titled “Note on a young Steam account”Leaves a note on players who join with a young Steam account.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', name: 'Young account note', async run(ctx) { const age = Number(await ctx.player.steamAccountAgeDays())
if (age < 30) { await ctx.note(`Steam account is ${age} days old`) } }, trigger: { event: 'join', kind: 'event' },})Webhook on join
Section titled “Webhook on join”Posts every join to an external endpoint.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', name: 'Join webhook', async run(ctx) { const country = await ctx.player.country() const sent = await ctx.fetch('https://example.com/hooks/joins', { body: JSON.stringify({ country, tags: await ctx.player.tags() }), headers: { 'content-type': 'application/json' }, method: 'POST', })
if (!sent.ok) { await ctx.note(`Webhook failed: ${sent.error}`) } else if (sent.status >= 400) { await ctx.note(`Webhook answered ${sent.status}`) } }, trigger: { event: 'join', kind: 'event' },})Scheduled broadcast
Section titled “Scheduled broadcast”Broadcasts a message to every server every half hour.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', name: 'Scheduled broadcast', async run(ctx) { await ctx.rcon('AdminBroadcast Join our Discord for rules and events.') }, trigger: { every: '30m', for: 'server', kind: 'schedule' },})Per-player sweep on a cron schedule
Section titled “Per-player sweep on a cron schedule”Checks every online player on a cron schedule and caps its own bans.
import { defineAutomation } from '@heliana/automation'
export default defineAutomation({ game: 'squad', limits: { bansPerMinute: 2 }, name: 'Patron sweep', async run(ctx) { const status = await ctx.player.patronStatus() const lists = await ctx.player.accessLists()
if (status === 'active' && !lists.includes('Whitelist')) { await ctx.note('Active patron missing from the Whitelist') } }, trigger: { cron: '0 */6 * * *', for: 'player', kind: 'schedule' },})