Skip to content

Commit

Permalink
Merge pull request #7 from rockerBOO/0.2.1-beta2
Browse files Browse the repository at this point in the history
Refactored. Simplified dependencies. Moving config to app start. Tests
  • Loading branch information
rockerBOO committed Jul 13, 2020
2 parents 28255d1 + 543997a commit 09319ee
Show file tree
Hide file tree
Showing 45 changed files with 923 additions and 714 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ jobs:
build:

runs-on: ubuntu-latest

name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: [22.1.7]
elixir: [1.10.4]
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Setup elixir
uses: actions/setup-elixir@v1
with:
elixir-version: '1.9.4' # Define the elixir version [required]
otp-version: '22.2' # Define the OTP version [required]
elixir-version: ${{matrix.elixir}} # Define the elixir version [required]
otp-version: ${{matrix.otp}} # Define the OTP version [required]
- name: Install Dependencies
run: mix deps.get
- name: Run Tests
run: mix test
- run: mix coveralls.github
78 changes: 19 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
Blur
====

Chat Bot for Streamers. Built to scale. Fast, efficient processing.
Twitch Chat Bot

![Elixir CI](https://github.com/rockerBOO/blur/workflows/Elixir%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/rockerBOO/blur/badge.svg)](https://coveralls.io/github/rockerBOO/blur)

## Install

To setup, the configuration options are in `.env`. `.env.example` is setup to show how to configure, and just rename to `.env`.
First, add Blur to your mix.exs dependencies:

```elixir
# The key generated from twitchtmi.com/chat
export TWITCH_CHAT_KEY=oauth:

# Username on Twitch for the Bot.
# It needs to match to the user of the access token/chat key.
export TWITCH_USERNAME=

# OPTIONAL. This takes precidence over the chat key for more intergrated options (authenticated calls to twitch)
# export TWITCH_ACCESS_TOKEN=
def deps do
[{:blur, "~> 0.2"}]
end
```

## To Run

`source .env && iex -S mix`

## Configuration for Channels
Then, update your dependencies:

Configuration for channels are stored in `data/#channel/`
```sh-session
$ mix deps.get
```

* `data/rockerboo/commands.json`
* Commands list
* `data/rockerboo/config.json`
* Configuration options for the channel
* `data/rockerboo/aliases.json`
* Stores aliases for commmands
To setup, the configuration options are in `.env`. `.env.example` is setup to show how to configure, and just rename to `.env`.

### `data/#channel/config.json`
```js
{
"messages": "on"
}
```
```elixir
# The key generated from https://twitchapps.com/tmi/.
export TWITCH_CHAT_KEY=oauth:

### `data/#channel/commands.json`
```js
{
"hello": ["say", "Hello"],
"help": ["say", "You need help"],
"follower": ["cmd", "follower"],
"followed": ["cmd", "followed"],
"flip": ["say", "(╯°□°)╯︵┻━┻"],
"song": ["cmd", "song"],
"highlight": ["cmd", "highlight"]
}
# Username on Twitch for the Bot.
# It needs to match to the user of the access token/chat key.
export TWITCH_USERNAME=
```


### `data/#channel/aliases.json`
```js
{
"bealight": "bealright",
"bot": "elirc",
"glacier": "theme",
"xfile": "xfiles",
"x-file": "xfiles",
"x-files": "xfiles",
"h": "help",
"playlist": "lastfm",
"coming": "getsmeeverytime",
"63": "speedlimit",
"soundslist": "soundlist",
"sounds": "soundlist",
"table": "flip",
"tableflip": "flip"
}
```
28 changes: 0 additions & 28 deletions config/config.exs

This file was deleted.

29 changes: 29 additions & 0 deletions lib/app.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule Blur.App do
use Supervisor

def start! do
Supervisor.start_link(__MODULE__, [], name: :blur)
end

@spec start(atom, list) :: GenServer.on_start()
def start(_type, [user, channels]) do
Supervisor.start_link(__MODULE__, [user, channels], name: :blur)
end

@impl Supervisor
def init([user, channels]) do
{:ok, client} = ExIRC.start_link!()

children = [
{Blur.Channels, []},
{Blur.Users, []},
# {Blur.IRC.Client, [client]},
{Blur.IRC.Connection, [client, user]},
{Blur.IRC.Login, [client, channels]},
{Blur.IRC.Channel, [client]},
{Blur.IRC.Message, [client]}
]

Supervisor.init(children, strategy: :one_for_one)
end
end
69 changes: 34 additions & 35 deletions lib/blur.ex
Original file line number Diff line number Diff line change
@@ -1,67 +1,66 @@
defmodule Blur do
@moduledoc """
Access your bot through Blur
"""

require Logger
@doc """
Join a channel.
Client
## Examples
iex> Blur.join "#channel"
:ok
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]
"""
@spec join(channel :: binary) :: :ok | {:error, atom}
def join(channel),
do: join(:irc_client, channel)

require Logger

@doc """
Join a channel on the client IRC connection.
## Examples
iex> Blur.join client, "#channel"
:ok
Blur.join :twitch, "#channel"
:ok
"""
@spec join(pid | atom, binary) :: :ok | {:error, atom}
@spec join(client :: GenServer.server(), channel :: binary) :: :ok | {:error, atom}
def join(client, "#" <> _ = channel),
do: Blur.IRC.join(client, channel)
do: join(client, channel)

def join(client, channel),
do: join(client, "#" <> channel)
do: Blur.IRC.join(client, channel)

@doc """
Leave a channel on the client IRC connection.
## Examples
iex> Blur.leave client, "#channel"
:ok
Blur.leave :twitch, "#channel"
{:error, :not_logged_in}
"""
@spec leave(client :: pid, channel :: binary) :: :ok | {:error, atom}
@spec leave(client :: GenServer.server(), channel :: binary) :: :ok | {:error, atom}
def leave(client, channel),
do: Blur.IRC.part(client, channel)

@doc """
Leave a channel.
## Examples
iex> Blur.leave "#channel"
:ok
"""
@spec leave(channel :: binary) :: :ok | {:error, atom}
def leave(channel),
do: leave(:irc_client, channel)

@doc """
Say a message to the channel.
## Examples
iex> Blur.say "#channel", "a message to the channel"
:ok
Blur.say :twitch, "adattape"
"""
@spec say(channel :: charlist, msg :: charlist) :: :ok | {:error, atom}
def say(channel, msg),
do: Blur.IRC.say(:irc_client, channel, msg)
def say(client, channel, message),
do: Blur.IRC.say(client, channel, message)

@doc """
Get token from the environmental variables.
Expand Down
Loading

0 comments on commit 09319ee

Please sign in to comment.