Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tsoding/HyperNerd

Total Surveillance Automatic Ban Machine for Twitch and Discord
https://github.com/tsoding/HyperNerd

chatbot hacktoberfest hacktoberfest2020 haskell irc irc-bot stream tsoding-streams twitch twitch-api

Last synced: 26 days ago
JSON representation

Total Surveillance Automatic Ban Machine for Twitch and Discord

Awesome Lists containing this project

README

        

[![Tsoding](https://img.shields.io/badge/twitch.tv-tsoding-purple?logo=twitch&style=for-the-badge)](https://www.twitch.tv/tsoding)
# HyperNerd

[![Build Status](https://travis-ci.org/tsoding/HyperNerd.svg?branch=master)](https://travis-ci.org/tsoding/HyperNerd)
[![Good For Stream](https://img.shields.io/github/issues/tsoding/HyperNerd/good%20for%20stream.svg)](https://github.com/tsoding/hypernerd/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+for+stream%22)

![HyperNerd](https://i.imgur.com/07Ymbi6.png)

Second iteration of [Tsoder][tsoder]. Chat bot for [Tsoding][tsoding] streams.

## Quick Start

### NixOS

Keep in mind that we are not using any Haskell packages from nixpkgs. All of the dependencies are supposed to be downloaded by cabal or stack during the build.

#### Cabal v1-build

```console
$ nix-shell
$ cabal sandbox init
$ cabal install happy-1.19.9
$ cabal install --only-dependencies --enable-tests
$ cabal build
$ cabal test
$ cabal run HyperNerd secret.ini database.db
```

#### Cabal v2-build

See [Nix-style Local Builds](https://www.haskell.org/cabal/users-guide/nix-local-build-overview.html) for more info

```console
$ nix-shell
$ cabal v2-build
$ cabal v2-test
$ cabal v2-run exe:HyperNerd secret.ini database.db
```

### Stack

Native dependencies:
- OpenSSL
- zlib

```console
$ stack build
$ stack exec hlint .
$ stack exec HyperNerd secret.ini database.db
```

### Example of a secret.ini file

The `secret.ini` file consist of three optional sections.

```ini
[twitch]
nick = HyperNerd
channel = Tsoding
password =
clientId =
owner =

[discord]
authToken =
guild =
channels = [, , ... ]

[github]
apiKey =
```

#### Twitch Config Section

| name | description |
|------------|------------------------------------------------------------------------------------------------------------------|
| `nick` | Nickname of the bot. |
| `owner` | Owner of the bot. The bot will recognize this name as an authority regardless of not being a mod or broadcaster. |
| `password` | Password generated by https://twitchapps.com/tmi/. `oauth:` prefix is the part of the password. |
| `channel` | Channel that the bot will join on start up. |
| `clientId` | Client ID for Twitch API calls. |

#### Discord Config Section

| name | description |
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `authToken` | Authentication Token for the bot: https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token |
| `guild` | The id of the guild the bot listens to |
| `channels` | The list of ids of channels the bot listens to (the list is parsed as a [Haskell list][haskell-lists-tuples]: `[, , ... ]`) |

#### GitHub Config Section

| name | desc |
|------------|-------------------------------------------------------------------------------------------|
| `apiToken` | https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line |

## Docker-Compose
With secrets existing in volume defined in `docker-compose.yaml`,
```console
$ docker-compose up --build
```

## Docker

```console
$ docker build --target app -t hypernerd .
$ mkdir hypernerd-state
$ cp secret.ini hypernerd-state
$ docker create -v /absolute/path/to/hypernerd-state/:/tmp/hypernerd/ \
--name hypernerd-bot hypernerd
$ docker start -a hypernerd-bot
$ docker stop hypernerd-bot
$ docker exec -it hypernerd-bot sh
```

## Markov Chain Responses

To trigger a Markov chain response, just mention the bot in the chat.

### Training the Markov Model

The Markov model is a csv file that is generated from the logs in the
bot's database file using the `Markov` CLI utility:

```console
$ cabal exec Markov train database.db markov.csv
```

This command will produce the `markov.csv` file.

### Using the Trained Markov Model with the Bot

```console
$ cabal exec HyperNerd secret.ini database.db markov.csv
```

The `markov.csv` file is not automatically updated. To update the file
with the new logs you have to run the `Markov` CLI utility again.

## Command Aliases

You can assign a command alias to any command:

```
!test
test
!addalias foo test
!foo
test
```

The aliases are "redirected" only one level deep meaning that transitive aliases are not supported:

```
!addalias bar foo
!bar
*nothing, because !bar is redirected to !foo, but further redirect from !foo to !test does not happen*
```

Motivation to not support transitive aliases is the following:
- They are not needed in most of the cases. Generally you just have a
main command and a bunch of aliases to it.
- Support for transitive aliases requires to traverse and maintain a
"tree" of aliases, which complicates the logic and degrades the
performance.

## Quote Database

- `!addquote ` -- Add a quote to the quote database. Available only to subs and mods.
- `!delquote ` -- Delete quote by id. Available only to Tsoding.
- `!quote [quote-id]` -- Query quote from the quote database.

## Support

You can support my work via

- Twitch channel: https://www.twitch.tv/subs/tsoding
- Patreon: https://www.patreon.com/tsoding

[tsoder]: http://github.com/tsoding/tsoder
[tsoding]: https://www.twitch.tv/tsoding
[haskell-lists-tuples]: https://en.wikibooks.org/wiki/Haskell/Lists_and_tuples