Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4cdd138ddb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 74 lines (55 sloc) 1.988 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
-module(slerl_sandbox).

-include("slerl.hrl").
-include("slerl_util.hrl").

-export([test/0]).

-define(OWNER, "Brendon Lanley").

test() ->
    application:start(slerl),
    {ok, [Bits]} = file:consult("login.config"),
    First = ?GV(first, Bits),
    Last = ?GV(last, Bits),
    Password = ?GV(pass, Bits),
    case slerl:login_loop(First, Last, Password, 5) of
        {ok, Bot} ->
            after_login(Bot);
        Other ->
            ?DBG({oh_noes, Other})
    end.



after_login(Bot) ->
    Bot:connect(),
    start_chat_logger(Bot),
    Bot.


start_chat_logger(Bot) ->
    spawn(fun() ->
                  Bot:subscribe([chat, im]),
                  chat_logger(Bot)
          end).

chat_logger(Bot) ->
    receive
        {message, chat, Chat, _Name} ->
            io:format("(~.8s) <~s> ~s~n",
                      [Chat#chat.type, Chat#chat.fromName, Chat#chat.text]);


        {message, im, #im{fromName= <<?OWNER>>,
                          type=message_from_agent}=IM, _Name} ->
            handle_command(Bot, IM#im.text, IM);

        {message, im, #im{type=message_from_agent}=IM, _Name} ->
            io:format("*****IM***** <~s> ~s~n",
                      [IM#im.fromName, IM#im.text]);

        {message, im, IM, _Name} ->
            io:format("[~s ~s]~n", [IM#im.fromName, IM#im.type]);

        Other -> ?DBG(Other)
    end,
    chat_logger(Bot).


handle_command(Bot, <<"port ", Region/binary>>, _) ->
    Bot:im(?OWNER, list_to_binary(["Porting to ", Region])),
    Bot:teleport(Region, {128, 128, 2500});
handle_command(Bot, <<"heel">>, IM) ->
    Position = slerl_util:get_field(['MessageBlock', 'Position'], IM#im.message),
    {ok, {SimName, _}} = Bot:position(),
    case Position of
        {0.0, 0.0, 0.0} -> Bot:im(?OWNER, "Port me first");
        _ ->
            Result = Bot:teleport(SimName, Position),
            Bot:im(?OWNER, lists:flatten(io_lib:format("Result: ~p", [Result])))
    end;
handle_command(_, _, _) -> ok.
    
Something went wrong with that request. Please try again.