Skip to content

Instantly share code, notes, and snippets.

@DTSCode
Last active August 29, 2015 14:22
Show Gist options
  • Save DTSCode/7bbcf0c8cd40dd7c8d89 to your computer and use it in GitHub Desktop.
Save DTSCode/7bbcf0c8cd40dd7c8d89 to your computer and use it in GitHub Desktop.
simple timeout script written in nim for a ZNC bouncer. After 10 minutes of inactivity it sends "AWAY :<nick> is currently afk (set by timeoutbot)". After becoming active again it sends "AWAY" to the server. To change it to suit your needs, edit all of the top const variables to their appropriate values.
import irc, asyncdispatch, posix
const
time: cint = 600
server: string = "dtscode.io"
port: int = 3038
nick: string = "dtscode"
user: string = "dtscode"
real: string = "nchambers - dtscode.io"
pass: string = "REDACTED_PASSWORD"
channels: seq[string] = @[]
var away: bool = false
proc onIrcEvent(client: PAsyncIrc, event: TIrcEvent) {.async.} =
case event.typ
of EvConnected:
nil
of EvDisconnected, EvTimeout:
await client.reconnect()
of EvMsg:
if len(event.params) > 1 and event.params[1] == "You have been marked as being away":
away = true
discard alarm(0)
elif event.host == "dtscode.io":
await send(client, "AWAY")
away = false
discard alarm(time)
elif len(event.params) > 1 and event.params[1] == "You are no longer marked as being away":
away = false
discard alarm(time)
echo(event.raw)
var client = newAsyncIrc(server, port.Port, nick, user, real, pass, channels, true, onIrcEvent)
proc make_away(signal: cint) {.noconv.} =
if not away:
asyncCheck client.send("AWAY :" & nick & " is currently afk (set by timeoutbot)")
away = true
signal(SIGALRM, make_away)
discard alarm(time)
asyncCheck client.run()
runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment