-
Notifications
You must be signed in to change notification settings - Fork 1
/
blur.ex
102 lines (84 loc) · 2.01 KB
/
blur.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
defmodule Blur do
@moduledoc """
Access your bot through Blur
Client
Handlers
- Login
on_logon -> join_channels
- Connection
%ConnState{}
on_connection -> login
on_disconnection -> logoff
- Message
pool
- Channels
on_join -> add_channel
[Channel, Channel]
- Users
on_names -> add_users
on_user_join -> add_user
on_part -> remove_user
[User, User]
"""
require Logger
@doc """
Join a channel on the client IRC connection.
## Examples
Blur.join "#channel"
:ok
"""
@spec join(channel :: binary) :: :ok | {:error, atom}
def join(channel),
do: ExIRC.Client.join(:twitchirc, channel)
@doc """
Leave a channel on the client IRC connection.
## Examples
Blur.leave "#channel"
"""
@spec leave(channel :: binary) :: :ok | {:error, atom}
def leave(channel),
do: ExIRC.Client.part(:twitchirc, channel)
@doc """
Say a message to the channel.
## Examples
Blur.say "#rockerboo", "yo"
"""
@spec say(channel :: binary, message :: binary) ::
:ok | {:error, atom}
def say(channel, message),
do: ExIRC.Client.msg(:twitchirc, :privmsg, channel, message)
@doc """
List who is in the channel. This is not completely accurate.
## Examples
Blur.users "#rockerboo"
"""
@spec users(channel :: binary) :: list | {:error, atom}
def users(channel),
do: ExIRC.Client.channel_users(:twitchirc, channel)
@doc """
List channels we have joined.
## Examples
Blur.channels
"""
@spec channels() :: list | {:error, atom}
def channels(),
do: ExIRC.Client.channels(:twitchirc)
@doc """
Check if we are logged on.
## Examples
Blur.is_logged_on?
"""
@spec is_logged_on?() :: boolean
def is_logged_on?(),
do: ExIRC.Client.is_logged_on?(:twitchirc)
@doc """
Get token from the environmental variables.
"""
@spec token() :: nil | binary
def token do
case Blur.Env.fetch!(:access_token) do
nil -> Blur.Env.fetch!(:chat_key)
token -> "oauth:" <> token
end
end
end