diff options
Diffstat (limited to '')
-rw-r--r-- | lib/lsg_irc/alcolog_plugin.ex | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/lib/lsg_irc/alcolog_plugin.ex b/lib/lsg_irc/alcolog_plugin.ex index f61b237..145e4fc 100644 --- a/lib/lsg_irc/alcolog_plugin.ex +++ b/lib/lsg_irc/alcolog_plugin.ex @@ -1,4 +1,4 @@ -defmodule LSG.IRC.AlcoologPlugin do +defmodule Nola.IRC.AlcoologPlugin do require Logger @moduledoc """ @@ -49,8 +49,8 @@ defmodule LSG.IRC.AlcoologPlugin do @default_user_meta %{weight: 77.4, sex: true, loss_factor: 15} def data_state() do - dets_filename = (LSG.data_path() <> "/" <> "alcoolisme.dets") |> String.to_charlist - dets_meta_filename = (LSG.data_path() <> "/" <> "alcoolisme_meta.dets") |> String.to_charlist + dets_filename = (Nola.data_path() <> "/" <> "alcoolisme.dets") |> String.to_charlist + dets_meta_filename = (Nola.data_path() <> "/" <> "alcoolisme_meta.dets") |> String.to_charlist %{dets: dets_filename, meta: dets_meta_filename, ets: __MODULE__.ETS} end @@ -59,10 +59,10 @@ defmodule LSG.IRC.AlcoologPlugin do for sub <- @pubsub ++ triggers do {:ok, _} = Registry.register(IRC.PubSub, sub, plugin: __MODULE__) end - dets_filename = (LSG.data_path() <> "/" <> "alcoolisme.dets") |> String.to_charlist + dets_filename = (Nola.data_path() <> "/" <> "alcoolisme.dets") |> String.to_charlist {:ok, dets} = :dets.open_file(dets_filename, [{:type,:bag}]) ets = :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}]) - dets_meta_filename = (LSG.data_path() <> "/" <> "alcoolisme_meta.dets") |> String.to_charlist + dets_meta_filename = (Nola.data_path() <> "/" <> "alcoolisme_meta.dets") |> String.to_charlist {:ok, meta} = :dets.open_file(dets_meta_filename, [{:type,:set}]) traverse_fun = fn(obj, dets) -> case obj do @@ -102,7 +102,7 @@ defmodule LSG.IRC.AlcoologPlugin do @eau ["santo", "santeau"] def handle_info({:irc, :trigger, santeau, m = %IRC.Message{trigger: %IRC.Trigger{args: _, type: :bang}}}, state) when santeau in @eau do - LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.santo") + Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.santo") {:noreply, state} end @@ -221,14 +221,14 @@ defmodule LSG.IRC.AlcoologPlugin do end def handle_info({:irc, :trigger, "alcoolog", m = %IRC.Message{trigger: %IRC.Trigger{args: [], type: :plus}}}, state) do - {:ok, token} = LSG.Token.new({:alcoolog, :index, m.sender.network, m.channel}) - url = LSGWeb.Router.Helpers.alcoolog_url(LSGWeb.Endpoint, :index, m.network, LSGWeb.format_chan(m.channel), token) + {:ok, token} = Nola.Token.new({:alcoolog, :index, m.sender.network, m.channel}) + url = NolaWeb.Router.Helpers.alcoolog_url(NolaWeb.Endpoint, :index, m.network, NolaWeb.format_chan(m.channel), token) m.replyfun.("-> #{url}") {:noreply, state} end def handle_info({:irc, :trigger, "alcoolog", m = %IRC.Message{trigger: %IRC.Trigger{args: [], type: :bang}}}, state) do - url = LSGWeb.Router.Helpers.alcoolog_url(LSGWeb.Endpoint, :index, m.network, LSGWeb.format_chan(m.channel)) + url = NolaWeb.Router.Helpers.alcoolog_url(NolaWeb.Endpoint, :index, m.network, NolaWeb.format_chan(m.channel)) m.replyfun.("-> #{url}") {:noreply, state} end @@ -330,9 +330,9 @@ defmodule LSG.IRC.AlcoologPlugin do cond do cl == nil -> m.replyfun.(cl_extra) deg == nil -> m.replyfun.(comment) - cl >= 500 || deg >= 100 -> LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_toohuge") - cl == 0 || deg == 0 -> LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_zero") - cl < 0 || deg < 0 -> LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_negative") + cl >= 500 || deg >= 100 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_toohuge") + cl == 0 || deg == 0 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_zero") + cl < 0 || deg < 0 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_negative") true -> points = Alcool.units(cl, deg) now = m.at || DateTime.utc_now() @@ -347,7 +347,7 @@ defmodule LSG.IRC.AlcoologPlugin do :ok = :dets.insert(state.dets, {m.account.id, now, points, if(old_stats, do: old_stats.active, else: 0), cl, deg, name, comment, meta}) true = :ets.insert(state.ets, {{m.account.id, now}, points, if(old_stats, do: old_stats.active, else: 0),cl, deg, name, comment, meta}) #sante = @santai |> Enum.map(fn(s) -> String.trim(String.upcase(s)) end) |> Enum.shuffle() |> Enum.random() - sante = LSG.IRC.TxtPlugin.random("alcoolog.santai") + sante = Nola.IRC.TxtPlugin.random("alcoolog.santai") k = if user_meta.sex, do: 0.7, else: 0.6 weight = user_meta.weight peak = Float.round((10*points||0.0)/(k*weight), 4) @@ -449,7 +449,7 @@ defmodule LSG.IRC.AlcoologPlugin do end if miss do - miss = LSG.IRC.TxtPlugin.random("alcoolog.#{to_string(miss)}") + miss = Nola.IRC.TxtPlugin.random("alcoolog.#{to_string(miss)}") if miss do for {net, chan} <- IRC.Membership.notify_channels(m.account) do user = IRC.UserTrack.find_by_account(net, m.account) @@ -532,7 +532,7 @@ defmodule LSG.IRC.AlcoologPlugin do rising_file_key = if rising, do: "_rising", else: "" txt_file = "alcoolog." <> "user_" <> to_string(user_state) <> rising_file_key - user_status = LSG.IRC.TxtPlugin.random(txt_file) + user_status = Nola.IRC.TxtPlugin.random(txt_file) meta = get_user_meta(state, nick) minutes_til_sober = h1/((meta.loss_factor/100)/60) @@ -831,11 +831,11 @@ defmodule LSG.IRC.AlcoologPlugin do put_user_meta(state, m.account.id, meta) cond do old_meta.weight < meta.weight -> - LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.fatter") + Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.fatter") old_meta.weight == meta.weight -> m.replyfun.("aucun changement!") true -> - LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.thinner") + Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.thinner") end end @@ -848,7 +848,7 @@ defmodule LSG.IRC.AlcoologPlugin do :dets.delete_object(state.dets, obj) :ets.delete(state.ets, {m.account.id, date}) m.replyfun.("supprimé: #{m.sender.nick} #{points} #{type} #{descr}") - LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.delete") + Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.delete") notify = IRC.Membership.notify_channels(m.account) -- [{m.network,m.channel}] for {net, chan} <- notify do user = IRC.UserTrack.find_by_account(net, m.account) |