Compare commits
2 Commits
65dad89f5e
...
5c22f69953
Author | SHA1 | Date |
---|---|---|
Rachel Fae Fox (foxiepaws) | 5c22f69953 | |
Rachel Fae Fox (foxiepaws) | 08d41aa70f |
|
@ -1,40 +1,37 @@
|
|||
defmodule Discordirc.ChannelMap do
|
||||
@cmap Application.fetch_env!(:discordirc, :channels)
|
||||
def discord(network, channel) do
|
||||
cmap = Application.fetch_env!(:discordirc, :channels)
|
||||
|
||||
id =
|
||||
cmap
|
||||
@cmap
|
||||
|> Enum.filter(&(&1.ircnetwork == network and &1.ircchannel == channel))
|
||||
|> List.first()
|
||||
|
||||
case id do
|
||||
x when is_map(x) ->
|
||||
{:ok, Map.get(x, :discordid)}
|
||||
%{discordid: discordid, ircnetwork: ^network, ircchannel: ^channel} ->
|
||||
{:ok, discordid}
|
||||
|
||||
nil ->
|
||||
_ ->
|
||||
{:error, "no mapping"}
|
||||
end
|
||||
end
|
||||
|
||||
def irc(id) do
|
||||
cmap = Application.fetch_env!(:discordirc, :channels)
|
||||
|
||||
channel =
|
||||
cmap
|
||||
@cmap
|
||||
|> Enum.filter(&(&1.discordid == id))
|
||||
|> List.first()
|
||||
|
||||
case channel do
|
||||
x when is_map(x) ->
|
||||
{:ok, channel.ircnetwork, channel.ircchannel}
|
||||
%{discordid: ^id, ircnetwork: net, ircchannel: chan} ->
|
||||
{:ok, net, chan}
|
||||
|
||||
nil ->
|
||||
_ ->
|
||||
{:error, "no mapping"}
|
||||
end
|
||||
end
|
||||
|
||||
def getircchannels(network) do
|
||||
Application.fetch_env!(:discordirc, :channels)
|
||||
@cmap
|
||||
|> Enum.filter(&(&1.ircnetwork == network))
|
||||
|> Enum.map(& &1.ircchannel)
|
||||
end
|
||||
|
|
|
@ -114,6 +114,16 @@ defmodule Discordirc.IRC do
|
|||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(:disconnected, state) do
|
||||
if state.ssl? do
|
||||
Client.connect_ssl!(state.client, state.server, state.port)
|
||||
else
|
||||
Client.connect!(state.client, state.server, state.port)
|
||||
end
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
def handle_info(_event, state) do
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue