Last active
August 29, 2015 14:22
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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