master
cynic 3 years ago
parent f3e1c22f1a
commit 5cd4e636ad
  1. 29
      .vscode/launch.json
  2. 16
      lib/ircked_elixir/chat_group.ex
  3. 7
      lib/ircked_elixir/chatter.ex

@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "mix_task",
"name": "mix (Default task)",
"request": "launch",
"projectDir": "${workspaceRoot}"
},
{
"type": "mix_task",
"name": "mix test",
"request": "launch",
"task": "test",
"taskArgs": [
"--trace"
],
"startApps": true,
"projectDir": "${workspaceRoot}",
"requireFiles": [
"test/**/test_helper.exs",
"test/**/*_test.exs"
]
}
]
}

@ -42,6 +42,7 @@ defmodule IrckedElixir.ChatGroup do
IO.puts(inspect pm)
case pm.body do
".cunny" -> send_all(chatters, pm.to, "cunny!")
".asskey" -> play(chatters, pm.to, File.read!("/home/rishi/awesome.txt") |> String.split("\n"))
_ -> ""
end
@ -55,12 +56,25 @@ defmodule IrckedElixir.ChatGroup do
GenServer.start_link(__MODULE__, chatters, name: :chatgroup)
end
def play(chatters, to, asskey) do
asskey
|> Stream.with_index |> Enum.to_list
|> Enum.each(
fn line ->
GenServer.call(
(@base_nick<>to_string(rem(elem(line, 1), @chatters)+1)) |> String.to_atom,
{:sendprivmsg, to, to_string(elem(line, 1))<>elem(line, 0)}
)
end
)
end
def send_all(chatters, to, body) do
chatters
|> Map.keys
|> Enum.each(
fn chatter ->
send(String.to_atom(chatter), {:sendprivmsg, to, body})
GenServer.call(String.to_atom(chatter), {:sendprivmsg, to, body})
IO.puts("LOL, "<>inspect(chatter))
end
)

@ -34,6 +34,13 @@ defmodule IrckedElixir.Chatter do
{:noreply, state}
end
@impl true
def handle_call({:sendprivmsg, to, body}, _, state) do
Privmsg.construct(state.nick, to, body).message |> Message.send(state.sock)
Process.sleep(10)
{:reply, :ok, state}
end
def start_link(starting_state) do
GenServer.start_link(__MODULE__, starting_state, name: starting_state.nick |> String.to_atom)
end

Loading…
Cancel
Save