summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/alcolog_plugin.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-01 23:50:41 +0200
committerhref <href@random.sh>2021-09-01 23:50:51 +0200
commit8da091655dde321feea56a75ab61e2750ddad73f (patch)
tree4eb569ecc4399b7e732ce664672398070795e349 /lib/lsg_irc/alcolog_plugin.ex
parenttxt: allow _ in file, try jaro distance (diff)
alcoolog: use txt
Diffstat (limited to 'lib/lsg_irc/alcolog_plugin.ex')
-rw-r--r--lib/lsg_irc/alcolog_plugin.ex227
1 files changed, 36 insertions, 191 deletions
diff --git a/lib/lsg_irc/alcolog_plugin.ex b/lib/lsg_irc/alcolog_plugin.ex
index 0812874..35aa206 100644
--- a/lib/lsg_irc/alcolog_plugin.ex
+++ b/lib/lsg_irc/alcolog_plugin.ex
@@ -24,128 +24,16 @@ defmodule LSG.IRC.AlcoologPlugin do
Annotation: champ libre!
- """
+ ---
- @user_states %{
- :sober => %{
- false => ["n'a pas encore bu", "est actuellement sobre"],
- true => ["commence a peine... santé"],
- },
- :low => %{
- false => ["est quasiment sobre", "est entrain de redescendre et devrait reboire"],
- true => ["commence a monter"],
- },
- :legal => %{
- true => ["peut encore conduire, mais plus pour longtemps"],
- false => ["peut reconduire", "est en route vers la sobriété"],
- },
- :legalhigh => %{
- true => ["est bientôt bourraide", "peut plus conduire"],
- false => ["commence a débourrai"],
- },
- :high => %{
- true => ["est bourraide!", "est raide"],
- false => ["est bourraide mais redescend!"],
- },
- :toohigh => ["est totalement bourraide", "est raiiideeeeee"],
- :sick => ["est BEAUCOUP trop bourraide"],
- }
-
-
- @santai [
- "SANTÉ",
- "SANTAIIII",
- "SANTAI",
- "A LA TIENNE",
- "CUL SEC CUL SEC",
- "TCHIN TCHIN",
- "LONGUE VIE",
- "ZUM WOHL", "PROST",
- "Կէնաձդ",
- "Наздраве",
- "SANTAIIIIIIIIII",
- "AGLOU",
- "AUNG MYIN PAR SAY",
- "SALUD",
- "SANTAIIIIII",
- "ΥΓΕΙΑ",
- "Å’KåLÀ MA’LUNA",
- "EGÉSZSÉGEDRE",
- "FENÉKIG",
- "乾杯",
- "KANPAI",
- "TULGATSGAAYA",
- "AGLOU AGLOU",
- "БУДЕМ ЗДОРОВЫ",
- "НА ЗДОРОВЬЕ",
- "SANTAIIIIIIIIIIIII",
- "MỘT HAI BA, YO",
- "SKÅL",
- "NA ZDRAVJE",
- "AGLOUUUU AGLOUUU AGLOUUUUUUU",
- "فى صحتك",
- "GESONDHEID",
- "ZHU NIN JIANKANG",
- "祝您健康",
- "SANTÉ",
- "CHEERS",
- "Nuş olsun",
- "Živjeli",
- "Biba",
- "Pura vida",
- "Terviseks",
- "Mabuhay",
- "Kippis",
- "Sláinte",
- "건배",
- "į sveikatą",
- "Эрүүл мэндийн төлөө",
- "Saúde",
- "Sanatate",
- "živeli",
- "Proscht",
- "Chai yo",
- "Choc tee",
- "Şerefe",
- "будьмо",
- "Budmo",
- "Iechyd da",
- "Sei gesund",
- "за наш", # Russe original. --kienma
- ]
+ ## `!txt`s
- @bad_drinks %{
- :negative => [
- "on peut pas boire en négatif...",
- "tu crois que ça marche comme ça ? :s",
- "e{{'u' | rrepeat}}h"
- ],
- :null => [
- "tu me prends pas un peu pour un con là ?",
- "zéro ? agis comme un homme et bois une pinte de whisky",
- "gros naze",
- "FATAL ERROR: java.lang.ArithmeticException (cannot divide by zero)",
- "?!?!",
- "votre médecin vous conseille de boire une bouteille de rouge cul sec plutôt"
- ],
- :huge => [
- "tu veux pas aller à l'hopital plutôt ?",
- "tu me prends pas un peu pour un con là ?",
- "ok; j'ai appelé le SAMU, ils arrivent",
- "j'accepterais le !santai quand tu m'auras envoyé la preuve vidéo"
- ],
- :eau => [
- "Le barman, c'est moi ! C'est moi qui suis barman ! Vous êtes la police républicaine ou une bande ? Vous savez qui je suis ? Enfoncez la bouteille, camarades !",
- "L'alcool est notre pire ennemi, fuir est lâche !",
- "attention... l'alcool permet de rendre l'eau potable",
- "{{'QUOI ?' | bold}}",
- "QUO{{'I' | rrepeat}}?",
- "{{\"COMMENT ÇA DE L'EAU ?\" | red}}",
- "resaisis toi et va ouvrir une bonne teille de rouge...",
- "bwais tu veux pas un \"petit\" rhum plutôt ?"
- ]
+ * status utilisateur: `alcoolog.user_(sober|legal|legalhigh|high|toohigh|sick)(|_rising)`
+ * mauvaises boissons: `alcoolog.drink_(negative|zero|negative)`
+ * santo: `alcoolog.santo`
+ * santai: `alcoolog.santai`
- }
+ """
def irc_doc, do: @moduledoc
@@ -189,7 +77,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
- m.replyfun.(Tmpl.render(Enum.random(Enum.shuffle(Map.get(@bad_drinks, :eau))), m))
+ LSG.IRC.TxtPlugin.reply_random(m, "alcoolog.santo")
{:noreply, state}
end
@@ -417,9 +305,9 @@ defmodule LSG.IRC.AlcoologPlugin do
cond do
cl == nil -> m.replyfun.(cl_extra)
deg == nil -> m.replyfun.(comment)
- cl >= 500 || deg >= 100 -> m.replyfun.(Tmpl.render(Enum.random(Enum.shuffle(Map.get(@bad_drinks, :huge))), m))
- cl == 0 || deg == 0 -> m.replyfun.(Tmpl.render(Enum.random(Enum.shuffle(Map.get(@bad_drinks, :null))), m))
- cl < 0 || deg < 0 -> m.replyfun.(Tmpl.render(Enum.random(Enum.shuffle(Map.get(@bad_drinks, :negative))), m))
+ 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")
true ->
points = Alcool.units(cl, deg)
now = m.at || DateTime.utc_now()
@@ -433,7 +321,8 @@ defmodule LSG.IRC.AlcoologPlugin do
meta = Map.put(meta, "sex", user_meta.sex)
: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 = @santai |> Enum.map(fn(s) -> String.trim(String.upcase(s)) end) |> Enum.shuffle() |> Enum.random()
+ sante = LSG.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)
@@ -519,7 +408,7 @@ defmodule LSG.IRC.AlcoologPlugin do
end
miss = cond do
- points <= 0.6 -> :blague
+ points <= 0.6 -> :small
stats.active30m >= 2.9 && stats.active30m < 3 -> :miss3
stats.active30m >= 1.9 && stats.active30m < 2 -> :miss2
stats.active30m >= 0.9 && stats.active30m < 1 -> :miss1
@@ -534,56 +423,16 @@ defmodule LSG.IRC.AlcoologPlugin do
true -> nil
end
- miss = case miss do
- :blague -> [
- "c'est une blague ?!"
- ]
- :miss025 -> [
- "si peu ?"
- ]
- :miss05 -> [
- "tu pourras encore conduire, faut boire plus!"
- ]
- :miss1 -> [
- "alerte, tu vas rater le gramme !"
- ]
- :miss2 -> [
- "petit joueur ? rater deux grammes de si peu c'est pas sérieux"
- ]
- :miss3 -> [
- "même pas 3 grammes ? allez ! dernière ligne droite!"
- ]
- :small025 -> [
- "tu vas quand même pas en rester là si ?"
- ]
- :small05 -> [
- "c'est un bon début, faut continuer sur cette lancée !"
- ]
- :small1 -> [
- "un peu plus de motivation sur le gramme et c'est parfait !"
- ]
- :small15 -> [
- "essaie de garder ton gramme et demi plus longtemps !"
- ]
- :small2 -> [
- "même pas une demi heure de deux grammes ? allez, fait un effort !",
- "installe toi mieux aux deux grammes !"
- ]
- :small3 -> [
- "ALLAIIIII CONTINUE FAUT MAINTENIR !",
- "tu vas quand même pas en rester là ?"
- ]
- _ -> nil
- end
if miss do
- msg = Enum.random(Enum.shuffle(miss))
- for {net, chan} <- IRC.Membership.notify_channels(m.account) do
- user = IRC.UserTrack.find_by_account(net, m.account)
- nick = if(user, do: user.nick, else: m.account.name)
- IRC.Connection.broadcast_message(net, chan, "#{nick}: #{msg}")
+ miss = LSG.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)
+ nick = if(user, do: user.nick, else: m.account.name)
+ IRC.Connection.broadcast_message(net, chan, "#{nick}: #{msg}")
+ end
end
end
-
end
end
@@ -654,14 +503,13 @@ defmodule LSG.IRC.AlcoologPlugin do
active <= 2.5 -> :high
active < 3 -> :toohigh
true -> :sick
- end
- states = Map.get(@user_states, user_state)
- list = if is_list(states) do
- states
- else
- Map.get(states, rising)
- end
- meta = get_user_meta(state, nick)
+ end
+
+ 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)
+
+ meta = get_user_meta(state, nick)
minutes_til_sober = h1/((meta.loss_factor/100)/60)
minutes_til_sober = cond do
active < 0 -> 0
@@ -689,9 +537,6 @@ defmodule LSG.IRC.AlcoologPlugin do
since_duration = if since, do: Timex.Duration.from_minutes(since_diff)
since_s = if since, do: Timex.Format.Duration.Formatter.lformat(since_duration, "fr", :humanized)
- user_status = list
- |> Enum.shuffle()
- |> Enum.random()
{total_volumes, total_gl} = user_stats(state, nick)
@@ -959,14 +804,14 @@ defmodule LSG.IRC.AlcoologPlugin do
old_meta = get_user_meta(state, m.account.id)
meta = Map.merge(@default_user_meta, %{sex: h, weight: weight, loss_factor: factor})
put_user_meta(state, m.account.id, meta)
- fat = ["t'as grossi...", "bientôt la tonne ?", "t'as encore abusé du fromage ?"]
- thin = ["en route vers l'anorexie ?", "t'as vomi...", "t'as grossi...", "faut manger plus de fromage!"]
- msg = cond do
- old_meta.weight < meta.weight -> Enum.random(Enum.shuffle(fat))
- old_meta.weight == meta.weight -> "ok"
- true -> Enum.random(Enum.shuffle(thin))
+ cond do
+ old_meta.weight < meta.weight ->
+ LSG.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")
end
- m.replyfun.(msg)
end
{:noreply, state}
@@ -978,7 +823,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}")
- m.replyfun.("faudrait quand même penser à boire")
+ LSG.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)