/
emote.ex
70 lines (52 loc) · 1.59 KB
/
emote.ex
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
defmodule Game.Command.Emote do
@moduledoc """
The "emote" command
"""
use Game.Command
alias Game.Character
alias Game.Events.RoomHeard
alias Game.Format.Channels, as: FormatChannels
commands(["emote"], parse: false)
@impl Game.Command
def help(:topic), do: "Emote"
def help(:short), do: "Perform an emote"
def help(:full) do
"""
Performs an emote. Anything you type after emote will be added to your name.
Example:
[ ] > {command}emote does something.{/command}
{player}Player{/player} does something.
[ ] > {command}*does something{/command}
{player}Player{/player} does something.
"""
end
@impl true
def parse(command, _context), do: parse(command)
@impl Game.Command
@doc """
Parse the command into arguments
iex> Game.Command.Emote.parse("emote hello")
{"hello"}
iex> Game.Command.Emote.parse("*hello")
{"hello"}
iex> Game.Command.Emote.parse("emote")
{:error, :bad_parse, "emote"}
iex> Game.Command.Emote.parse("unknown")
{:error, :bad_parse, "unknown"}
"""
def parse(command)
def parse("emote " <> text), do: {text}
def parse("*" <> text), do: {text}
@impl Game.Command
@doc """
Perform an emote
"""
def run(command, state)
def run({emote}, state = %{character: character, save: save}) do
state |> Socket.echo(FormatChannels.emote(character, emote))
message = Message.emote(character, emote)
event = %RoomHeard{character: Character.to_simple(character), message: message}
Environment.notify(save.room_id, event.character, event)
:ok
end
end