diff options
author | Jordan Bracco <href@random.sh> | 2022-12-20 03:27:32 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-20 19:29:42 +0100 |
commit | a2e3a9e6fcab2e32e0ca208d8242e8d6812a67df (patch) | |
tree | 4dd596a3a8a9025137d7723107d794ec9e329d06 /lib/irc | |
parent | Finish moving things from IRC. to Nola., refs T77 (diff) |
Rename IRC.{Message,Trigger} to Nola.{Message,Trigger}, refs T77.
Diffstat (limited to '')
-rw-r--r-- | lib/irc/admin_handler.ex | 2 | ||||
-rw-r--r-- | lib/irc/connection.ex | 16 | ||||
-rw-r--r-- | lib/irc/irc.ex | 20 | ||||
-rw-r--r-- | lib/irc/puppet_connection.ex | 2 |
4 files changed, 10 insertions, 30 deletions
diff --git a/lib/irc/admin_handler.ex b/lib/irc/admin_handler.ex index 282f3c2..a462789 100644 --- a/lib/irc/admin_handler.ex +++ b/lib/irc/admin_handler.ex @@ -18,7 +18,7 @@ defmodule Nola.Irc.AdminHandler do {:ok, client} end - def handle_info({:irc, :trigger, "op", m = %IRC.Message{trigger: %IRC.Trigger{type: :bang}, sender: sender}}, client) do + def handle_info({:irc, :trigger, "op", m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}, sender: sender}}, client) do if IRC.admin?(sender) do m.replyfun.({:mode, "+o"}) else diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex index 9bb09ed..037b7d6 100644 --- a/lib/irc/connection.ex +++ b/lib/irc/connection.ex @@ -24,9 +24,9 @@ defmodule IRC.Connection do * `triggers` -- all triggers * `trigger:TRIGGER` -- any message with a trigger `TRIGGER` - ## Replying to %IRC.Message{} + ## Replying to %Nola.Message{} - Each `IRC.Message` comes with a dedicated `replyfun`, to which you only have to pass either: + Each `Nola.Message` comes with a dedicated `replyfun`, to which you only have to pass either: """ def irc_doc, do: nil @@ -294,7 +294,7 @@ defmodule IRC.Connection do if !Map.get(user.options, :puppet) do reply_fun = fn(text) -> irc_reply(state, {chan, sender}, text) end account = Nola.Account.lookup(sender) - message = %IRC.Message{id: FlakeId.get(), transport: :irc, at: NaiveDateTime.utc_now(), text: text, network: state.network, + message = %Nola.Message{id: FlakeId.get(), transport: :irc, at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: chan, replyfun: reply_fun, trigger: extract_trigger(text)} message = case Nola.UserTrack.messaged(message) do @@ -311,7 +311,7 @@ defmodule IRC.Connection do def handle_info({:received, text, sender}, state) do reply_fun = fn(text) -> irc_reply(state, {sender.nick, sender}, text) end account = Nola.Account.lookup(sender) - message = %IRC.Message{id: FlakeId.get(), transport: :irc, text: text, network: state.network, at: NaiveDateTime.utc_now(), + message = %Nola.Message{id: FlakeId.get(), transport: :irc, text: text, network: state.network, at: NaiveDateTime.utc_now(), account: account, sender: sender, replyfun: reply_fun, trigger: extract_trigger(text)} message = case Nola.UserTrack.messaged(message) do :ok -> message @@ -401,11 +401,11 @@ defmodule IRC.Connection do def publish(pub), do: publish(pub, []) - def publish(m = %IRC.Message{trigger: nil}, keys) do + def publish(m = %Nola.Message{trigger: nil}, keys) do dispatch(["messages"] ++ keys, {:irc, :text, m}) end - def publish(m = %IRC.Message{trigger: t = %IRC.Trigger{trigger: trigger}}, keys) do + def publish(m = %Nola.Message{trigger: t = %Nola.Trigger{trigger: trigger}}, keys) do dispatch(["triggers", "#{m.network}/#{m.channel}:triggers", "trigger:"<>trigger], {:irc, :trigger, trigger, m}) end @@ -445,7 +445,7 @@ defmodule IRC.Connection do def extract_trigger(unquote(trigger)<>text) do text = String.strip(text) [trigger | args] = String.split(text, " ") - %IRC.Trigger{type: unquote(name), trigger: String.downcase(trigger), args: args} + %Nola.Trigger{type: unquote(name), trigger: String.downcase(trigger), args: args} end end @@ -463,7 +463,7 @@ defmodule IRC.Connection do |> List.flatten() outputs = for line <- lines do ExIRC.Client.msg(client, :privmsg, target, line) - {:irc, :out, %IRC.Message{id: FlakeId.get(), transport: :irc, network: network, + {:irc, :out, %Nola.Message{id: FlakeId.get(), transport: :irc, network: network, channel: target, text: line, sender: %ExIRC.SenderInfo{nick: state.conn.nick}, at: NaiveDateTime.utc_now(), meta: %{self: true}}} end for f <- outputs, do: dispatch(["irc:outputs", "#{network}/#{target}:outputs"], f) diff --git a/lib/irc/irc.ex b/lib/irc/irc.ex index 93525e4..a1d97a2 100644 --- a/lib/irc/irc.ex +++ b/lib/irc/irc.ex @@ -1,25 +1,5 @@ defmodule IRC do - defmodule Message do - @derive {Poison.Encoder, except: [:replyfun]} - defstruct [:id, - :text, - {:transport, :irc}, - :network, - :account, - :sender, - :channel, - :trigger, - :replyfun, - :at, - {:meta, %{}} - ] - end - defmodule Trigger do - @derive Poison.Encoder - defstruct [:type, :trigger, :args] - end - def send_message_as(account, network, channel, text, force_puppet \\ false) do connection = IRC.Connection.get_network(network) if connection && (force_puppet || IRC.PuppetConnection.whereis(account, connection)) do diff --git a/lib/irc/puppet_connection.ex b/lib/irc/puppet_connection.ex index 75a06f3..2604876 100644 --- a/lib/irc/puppet_connection.ex +++ b/lib/irc/puppet_connection.ex @@ -152,7 +152,7 @@ defmodule IRC.PuppetConnection do reply_fun = fn(text) -> IRC.Connection.broadcast_message(state.network, channel, text) end - message = %IRC.Message{id: FlakeId.get(), at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(text), meta: meta} + message = %Nola.Message{id: FlakeId.get(), at: NaiveDateTime.utc_now(), text: text, network: state.network, account: account, sender: sender, channel: channel, replyfun: reply_fun, trigger: IRC.Connection.extract_trigger(text), meta: meta} message = case Nola.UserTrack.messaged(message) do :ok -> message {:ok, message} -> message |