2016-04-05 16 views
1

Basit bir bot yapmak için ExIrc ile çalışıyorum ama işe yaramayacağım.ExIrc süpervizörü başlatılıyor

** (Mix) Could not start application streamingutils: TwitchSniper.start(:normal, 
[]) returned an error: shutdown: failed to start child: TwitchSniper.Bot 
    ** (EXIT) an exception was raised: 
     ** (ArgumentError) argument error 
      :erlang.apply([%TwitchSniper.Bot.State{client: nil, handlers: [], host: "irc.chat.twitch.tv", name: "Paul Schoenfelder", nick: "hajtosek", pass: "my password", port: 6667, user: "hajtosek"}], :host, []) 
      (streamingutils) TwitchSniper.Bot.init/1 
      (stdlib) gen_server.erl:328: :gen_server.init_it/6 
      (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3 

Ben ExIrc kütüphanesini kullanmaya çalışıyor: https://github.com/bitwalker/exirc

Sadece readme kodun büyük kopyalanamaz, sadece takas verileri

Kod

Bu hata alıyorum :

defmodule State do 
    defstruct host: "irc.chat.twitch.tv", 
       port: 6667, 
       pass: "password", 
       nick: "hajtosek", 
       user: "hajtosek", 
       name: "Paul Schoenfelder", 
       client: nil, 
       handlers: [] 
end 

def start_link(_) do 
    GenServer.start_link(__MODULE__, [%State{}]) 
end 

def init(state) do 
    # Start the client and handler processes, the ExIrc supervisor is automatically started when your app runs 
    {:ok, client} = ExIrc.start_client!() 
    #{:ok, handler} = ExampleHandler.start_link(nil) 

    # Register the event handler with ExIrc 
    ExIrc.Client.add_handler client, self 

    # Connect and logon to a server, join a channel and send a simple message 
    ExIrc.Client.connect! client, state.host, state.port 
    ExIrc.Client.logon  client, state.pass, state.nick, state.user, state.name 
    ExIrc.Client.join  client, "#channel" 
    ExIrc.Client.msg  client, :privmsg, "#channel", "Hello world!" 
    ExIrc.Client.msg  client, :ctcp, "#channel", "Hello world!" 

    IO.inspect "IRC activated" 

    {:ok, %{state | :client => client, :handlers => [self]}} 
end 

def terminate(_, state) do 
    # Quit the channel and close the underlying client connection when the process is terminating 
    ExIrc.Client.quit state.client, "Goodbye, cruel world." 
    ExIrc.Client.stop! state.client 
    :ok 
end 

cevap

2

Bu, README'de bir yazım hatası gibi görünüyor. Init için state argümanı her zaman bir liste (GenServer.start_link'a verilen listeyi alır). Yani mesele, bir değilken bir yapı gibi bir durumu kullanmaya çalıştığınızdır. init için işlev kafasını state yerine [state] olarak değiştirin ve devam etmek iyi olacak.

DÜZENLEME: Ayrıca değer örnekler exirc kullanmak tam uygulamalar için GitHub'dan klasörüne sen, bir göz atmalısınız onlar daha gerçekçi örnek olduğunu belirtti.

+0

Çok teşekkür ederim, lib yazarına rapor vermelisiniz. – Haito

+0

Ben lib'in yazarıyım, bu yüzden rapor etmeyi düşünün;) – bitwalker