fix warnings where possible.

master
Rachel Fae Fox 2022-11-10 13:10:04 -05:00
parent bd396dc3d4
commit 501a26fb13
4 changed files with 70 additions and 81 deletions

View File

@ -23,7 +23,7 @@ defmodule Discordirc.DiscordHandler do
{:ok, webhook} ->
webhook.user.id == Nostrum.Snowflake.dump(me.id)
{:error, e} ->
{:error, _e} ->
false
end
@ -33,8 +33,6 @@ defmodule Discordirc.DiscordHandler do
end
def handle_event({:MESSAGE_CREATE, msg, _ws_state}) do
{:ok, me} = Api.get_current_user()
unless is_me_or_my_webhook(msg) do
case ChannelMap.irc(msg.channel_id) do
{:ok, net, _} ->

View File

@ -2,12 +2,11 @@ defmodule Discordirc.Formatter do
@moduledoc """
Transforms messages to/from discord from/to irc
"""
alias Nostrum.Api, as: DiscordAPI
alias Discordirc.DiscordInfo
@discordcdn "https://cdn.discordapp.com/"
def from_irc(nick, msg, ctcp \\ false) do
def from_irc(_nick, msg, ctcp \\ false) do
# strip or replace IRC formatting.
fmsg =
msg

View File

@ -34,7 +34,6 @@ defmodule Discordirc.IRC do
alias ExIRC.Whois
alias Discordirc.ChannelMap
alias Discordirc.Formatter
alias Nostrum.Api, as: DiscordAPI
def start_link(%{:network => network} = params) when is_map(params) do
state = %State{State.from_params(params) | :channels => ChannelMap.getircchannels(network)}
@ -68,6 +67,67 @@ defmodule Discordirc.IRC do
{:noreply, state}
end
def handle_info({:connected, server, port}, state) do
Logger.debug("Connected to #{server}:#{port}")
Logger.debug("Logging to #{server}:#{port} as #{state.nick}..")
Client.logon(state.client, state.pass, state.nick, state.user, state.name)
{:noreply, state}
end
def handle_info({:received, msg, %SenderInfo{:nick => nick}, channel}, state) do
discordid = ChannelMap.discord(state.network, channel)
fmsg = Formatter.from_irc(nick, msg, false)
case discordid do
{:ok, x} ->
send(
:WebhookService,
{:irc, %{channel_id: x, nick: "#{nick}@#{state.network}", content: fmsg}}
)
end
{:noreply, state}
end
def handle_info({:whois, whois = %Whois{:hostname => host}}, state) do
case whois do
%Whois{nick: n, user: user} when n == state.nick ->
me = "#{state.nick}!#{user}@#{host}"
Logger.debug("Setting host to #{me} #{inspect(whois)}")
{:noreply, %State{state | :me => me}}
_ ->
{:noreply, state}
end
end
def handle_info({:unrecognized, "396", %{args: _args}}, state) do
Logger.debug("Received UnrealIRCD host change notification, double checking host")
Client.whois(state.client, state.nick)
{:noreply, state}
end
def handle_info({:me, msg, %SenderInfo{:nick => nick}, channel}, state) do
discordid = ChannelMap.discord(state.network, channel)
fmsg = Formatter.from_irc(nick, msg, true)
case discordid do
{:ok, x} ->
send(
:WebhookService,
{:irc, %{channel_id: x, nick: "#{nick}@#{state.network}", content: fmsg}}
)
end
{:noreply, state}
end
# lets try using the supervisor instead...
def handle_info(:disconnected, state) do
Logger.debug("Disconnected, throwing self to hell.")
{:stop, "disconnection", state}
end
def handle_info({:discordmsg, msg}, state) do
channel = ChannelMap.irc(msg.channel_id)
@ -112,89 +172,23 @@ defmodule Discordirc.IRC do
{:noreply, state}
end
def handle_info({:discord_cmd, :kick, users}) do
end
def handle_info({:discord_cmd, :ban, users}) do
end
def handle_info({:discord_cmd, :mode, modestr}) do
end
def handle_info({:discord_cmd, :topic, topic}) do
end
def handle_info({:connected, server, port}, state) do
Logger.debug("Connected to #{server}:#{port}")
Logger.debug("Logging to #{server}:#{port} as #{state.nick}..")
Client.logon(state.client, state.pass, state.nick, state.user, state.name)
def handle_info({:discord_cmd, :kick, _users}, state) do
{:noreply, state}
end
def handle_info({:received, msg, %SenderInfo{:nick => nick}, channel}, state) do
discordid = ChannelMap.discord(state.network, channel)
fmsg = Formatter.from_irc(nick, msg, false)
case discordid do
{:ok, x} ->
send(
:WebhookService,
{:irc, %{channel_id: x, nick: "#{nick}@#{state.network}", content: fmsg}}
)
end
def handle_info({:discord_cmd, :ban, _users}, state) do
{:noreply, state}
end
def handle_info({:whois, whois = %Whois{:hostname => host}}, state) do
case whois do
%Whois{nick: n, user: user} when n == state.nick ->
me = "#{state.nick}!#{user}@#{host}"
Logger.debug("Setting host to #{me} #{inspect(whois)}")
{:noreply, %State{state | :me => me}}
_ ->
{:noreply, state}
end
end
def handle_info({:unrecognized, "396", %{args: args}}, state) do
Logger.debug("Received UnrealIRCD host change notification, double checking host")
Client.whois(state.client, state.nick)
def handle_info({:discord_cmd, :mode, _modestr}, state) do
{:noreply, state}
end
def handle_info({:me, msg, %SenderInfo{:nick => nick}, channel}, state) do
discordid = ChannelMap.discord(state.network, channel)
fmsg = Formatter.from_irc(nick, msg, true)
case discordid do
{:ok, x} ->
send(
:WebhookService,
{:irc, %{channel_id: x, nick: "#{nick}@#{state.network}", content: fmsg}}
)
end
def handle_info({:discord_cmd, :topic, _topic}, state) do
{:noreply, state}
end
# lets try using the supervisor instead...
def handle_info(:disconnected, state) do
Logger.debug("Disconnected, throwing self to hell.")
{:stop, "disconnection", 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
# this MUST be the last handle_info.
def handle_info(event, state) do
Logger.debug("unknown event: inspect output: " <> inspect(event))
{:noreply, state}

View File

@ -6,8 +6,6 @@ defmodule Discordirc.WebhookService do
use GenServer
require Logger
alias Nostrum.Api, as: DiscordAPI
alias Nostrum.Cache, as: DiscordCache
alias Nostrum.Error.ApiError
defmodule State do
defstruct hooks: nil
@ -94,10 +92,10 @@ defmodule Discordirc.WebhookService do
DiscordAPI.execute_webhook(wh.id, wh.token, args)
rescue
e in MatchError ->
Logger.warn("MatchError from nostrum workaround in place.")
Logger.warn("MatchError from nostrum workaround in place. e: #{inspect(e)}")
e in FunctionClauseError ->
Logger.warn("FunctionClauseError from nostrum workaround in place.")
Logger.warn("FunctionClauseError from nostrum workaround in place. #{inspect(e)}")
end
{:noreply, state}