Created
May 15, 2015 15:23
-
-
Save michaelowens/c6328df17d3131a294a2 to your computer and use it in GitHub Desktop.
This file contains 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
defmodule Plugin do | |
alias Plugin | |
use XikBot.Database | |
def everyX(name, ms, cb) do | |
IO.puts "--- everyX ---" | |
Amnesia.transaction do | |
selection = Timer.where cmd == name | |
IO.puts selection | |
if selection == nil do | |
t = %Timer{cmd: name, interval: 0, last_run: 0} | |
|> Timer.write | |
cb.() | |
Stream.timer(ms) |> Enum.take(1) |> deleteTimer(name, t) | |
end | |
end | |
end | |
def deleteTimer(s, name, t) do | |
IO.puts "Deleting timer: " <> name | |
Amnesia.transaction do | |
resp = Timer.delete!(t) | |
IO.puts resp | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment