summaryrefslogtreecommitdiff
path: root/lib/plugins/radio_france.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/radio_france.ex')
-rw-r--r--lib/plugins/radio_france.ex59
1 files changed, 41 insertions, 18 deletions
diff --git a/lib/plugins/radio_france.ex b/lib/plugins/radio_france.ex
index d95c54a..e9adc4e 100644
--- a/lib/plugins/radio_france.ex
+++ b/lib/plugins/radio_france.ex
@@ -23,27 +23,45 @@ defmodule Nola.Plugins.RadioFrance do
regopts = [plugin: __MODULE__]
{:ok, _} = Registry.register(Nola.PubSub, "trigger:radiofrance", regopts)
{:ok, _} = Registry.register(Nola.PubSub, "trigger:rf", regopts)
+
for s <- @shortcuts do
{:ok, _} = Registry.register(Nola.PubSub, "trigger:#{s}", regopts)
end
+
{:ok, nil}
end
- def handle_info({:irc, :trigger, "rf", m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}}}, state) do
+ def handle_info(
+ {:irc, :trigger, "rf", m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}}},
+ state
+ ) do
handle_info({:irc, :trigger, "radiofrance", m}, state)
end
- def handle_info({:irc, :trigger, @trigger, m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: []}}}, state) do
+ def handle_info(
+ {:irc, :trigger, @trigger,
+ m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: []}}},
+ state
+ ) do
m.replyfun.("radiofrance: prΓ©cisez la station!")
{:noreply, state}
end
- def handle_info({:irc, :trigger, @trigger, m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: args}}}, state) do
+ def handle_info(
+ {:irc, :trigger, @trigger,
+ m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: args}}},
+ state
+ ) do
now(args_to_station(args), m)
{:noreply, state}
end
- def handle_info({:irc, :trigger, trigger, m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: args}}}, state) when trigger in @shortcuts do
+ def handle_info(
+ {:irc, :trigger, trigger,
+ m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: args}}},
+ state
+ )
+ when trigger in @shortcuts do
now(args_to_station([trigger | args]), m)
{:noreply, state}
end
@@ -56,7 +74,7 @@ defmodule Nola.Plugins.RadioFrance do
end
def handle_info(info, state) do
- Logger.debug("unhandled info: #{inspect info}")
+ Logger.debug("unhandled info: #{inspect(info)}")
{:noreply, state}
end
@@ -67,7 +85,7 @@ defmodule Nola.Plugins.RadioFrance do
song? = !!get_in(json, ["now", "song"])
station = reformat_station_name(get_in(json, ["now", "stationName"]))
now_title = get_in(json, ["now", "firstLine", "title"])
- now_subtitle = get_in(json, ["now", "secondLine", "title"])
+ now_subtitle = get_in(json, ["now", "secondLine", "title"])
next_title = get_in(json, ["next", "firstLine", "title"])
next_subtitle = get_in(json, ["next", "secondLine", "title"])
next_song? = !!get_in(json, ["next", "song"])
@@ -76,21 +94,25 @@ defmodule Nola.Plugins.RadioFrance do
now = format_title(song?, now_title, now_subtitle)
prefix = if song?, do: "🎢", else: "🎀"
m.replyfun.("#{prefix} #{station}: #{now}")
-
+
next = format_title(song?, next_title, next_subtitle)
+
if next do
- next_prefix = if next_at do
- next_date = DateTime.from_unix!(next_at)
- in_seconds = DateTime.diff(next_date, DateTime.utc_now())
- in_minutes = ceil(in_seconds / 60)
- if in_minutes >= 5 do
- if next_song?, do: "#{in_minutes}m πŸ”œ", else: "dans #{in_minutes} minutes:"
+ next_prefix =
+ if next_at do
+ next_date = DateTime.from_unix!(next_at)
+ in_seconds = DateTime.diff(next_date, DateTime.utc_now())
+ in_minutes = ceil(in_seconds / 60)
+
+ if in_minutes >= 5 do
+ if next_song?, do: "#{in_minutes}m πŸ”œ", else: "dans #{in_minutes} minutes:"
+ else
+ if next_song?, do: "πŸ”œ", else: "suivi de:"
+ end
else
- if next_song?, do: "πŸ”œ", else: "suivi de:"
+ if next_song?, do: "πŸ”œ", else: "Γ  suivre:"
end
- else
- if next_song?, do: "πŸ”œ", else: "Γ  suivre:"
- end
+
m.replyfun.("#{next_prefix} #{next}")
end
@@ -117,9 +139,11 @@ defmodule Nola.Plugins.RadioFrance do
defp format_title(_, nil, nil) do
nil
end
+
defp format_title(true, title, artist) do
[artist, title] |> Enum.filter(& &1) |> Enum.join(" - ")
end
+
defp format_title(false, show, section) do
[show, section] |> Enum.filter(& &1) |> Enum.join(": ")
end
@@ -129,5 +153,4 @@ defmodule Nola.Plugins.RadioFrance do
|> String.replace("france", "france ")
|> String.replace("_", " ")
end
-
end