https://github.com/matheusfillipe/irc_bash_bot
Proof of concept irc bot starting point
https://github.com/matheusfillipe/irc_bash_bot
bash bot irc shell-s
Last synced: 2 months ago
JSON representation
Proof of concept irc bot starting point
- Host: GitHub
- URL: https://github.com/matheusfillipe/irc_bash_bot
- Owner: matheusfillipe
- Created: 2021-09-23T07:17:54.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-03T07:33:55.000Z (over 4 years ago)
- Last Synced: 2025-01-20T21:37:48.675Z (over 1 year ago)
- Topics: bash, bot, irc, shell-s
- Language: Shell
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Irc Bash bot
A simple to add commands, irc bot written fully in bash using netcat for handling the connection. This is a proof of concept and might have security flaws.
# Usage
## Installation
Install netcat and make sure you have the `-v` and `-c` options enabled on it. On some distros this is called `ncat`:
``` sh
sudo apt install ncat
```
Edit `config.sh` with your bot's nickname, irc hort, port, and optionally the netcat command.
- NC_COMMAND: Netcat command. Usually ncat is fine.
- HOST: Irc server hostname
- PORT: Irc server port
- NAME: Nickname and Username of the irc bot
- CHAN: Channel the bot will join (it will join any other channel when it receives invitation)
- PREF: Prefix the bot commands should begin with. Usually something like '!', '=', '$', '@' etc...
- PING: Ping period in seconds. 10 is usually fine.
## Defining new commands
Anything inside the `commands` folder without extension or with the extension `.sh` will be a bot command, matching the file name. It does not need execution permissions.
For example, create a shell script named `command.sh` inside the `commands` folder. You can now run `=command argument1 argument2` on your bot (without having to restart it even!). Inside `command.sh` you can address "argument1" with `$1` and "argument2" with `$2`. Whatever this script's stdout is it's returned to the irc channel the command was called from. You can send multiple lines.
## Read channel and nickname
Channel and nickname information are relayed by stdin. Basically `"$channel $nick"` (notice the space in between) is piped to every command script. Check out echo.sh to know how to handle this. Also notice that if you are creating commands by simply copying or symlinking existing commands into `commands/` and this command reads stin you will probably get some undesired behaviour, so always create a script yourself inside `commands/` and call whatever you want like `some_command $@`.
Example:
```shell
info="$(cat -)" # read piped stdin
channel=$(echo "$info" | cut -d\ -f1)
nick=$(echo "$info" | cut -d\ -f2)
```
## Use other common irc commands
If your command script has a line starting with "/" on its stdout it will be read as an irc command like on most irc clients. Only a few commands are currently implemented like `/nick` `/msg` (for private or channel messages, like sending to another channel), `/join`, `/mode` etc.... These commands are case insensitive.
Example:
```shell
nick=$(cat - | cut -d\ -f2)
case "$1" in
"join")
echo "/join $2"
;;
"nick")
echo "/nick $2"
;;
"msg")
echo "/msg $2 ${@:3}"
;;
"help")
echo "$nick: you can use join, nick and msg to do whatever you want with me ;)"
;;
esac
```