Git Product home page Git Product logo

simplebot's Introduction

SimpleBot Build status

This is a simple TeamSpeak chat bot. It connects as a usual client and responds to some messages. The bot originally was built to test and showcase the capabilities of the tsclientlib library, though it developed into a more sophisticated and usable bot.

Dependencies

  • OpenSSL 1.1 (not needed on windows)
  • Rust (only needed if you want to compile the bot yourself, the preferred installation method is rustup), currently the nightly version is needed

Binary downloads of SimpleBot can be found here.

Usage

Use a settings file with ./simple-bot --settings settings.toml or put it in the configuration directory of your system, which should be

  • Linux: .config/simple-bot/
  • Windows: %APPDATA%/ReSpeak/simple-bot/config/
  • macOS: Library/Preferences/ReSpeak.simple-bot/

Features

The bot gets triggered by certain words, which then leads to a response.

These actions can be defined e.g. using the builtin commands. These can be used in any chat with the bot (you can even poke him with your requests).

.help
# List all commands
.list <page>
.add <reaction> on <trigger>
.del <trigger>
# Reload the configuration
.reload
# Disconnect the bot
.quit

Examples:

.list
.add Please read the [URL=…]faq[/URL] on question
# Trigger the response
I have a question
# Will not trigger the response
This is questionable.
.del question

Note: The trigger will only match whole words. So in the example before, the response will be triggered on I have a question but not on This is questionable. The matching is case sensitive, so Question will also not trigger the response.

Configuration

The bot supports a simple configuration in a settings.toml file. The default options are

# The server to connect to
address = "localhost"
# The channel to connect to
# This can be e.g. 4, "My Channel" or "My Channel/Nested"
channel = ""
# The name of the bot
name = "SimpleBot"
# How many responses can be sent per second
rate_limit = 2
# The prefix for builtin commands
prefix = "."

# The path to the private key file
key_file = "private.key"
# The file to store dynamically added actions
dynamic_actions = "dynamic.toml"

Additionally, more complex behaviour can be defined in the configuration file. This allows triggers on regular expressions instead of static strings and also gives the ability to execute arbitrary scripts. The bot will first search for a matching action in the settings, then in the builtins and afterwards in the dynamic actions (the ones which were added with .add). The format is:

[[actions.on_message]]
# Trigger
# contains and regex cannot be defined together, though it is ok to define none
# of them which will match every message.
contains = "simple string, like added with .add"
regex = "(?i)e.g. case invariant"
# The way the message is received.
chat = "server|channel|client|poke"

# Reaction
# At maximum one of the reactions can be defined
# A response of this type is added by the .add builtin command.
response = "plain response"
# Run a script, the arguments will be splitted at spaces and the following
# arguments will be added:
# - Chat mode (server|channel|client|poke)
# - Message
# - Username
# - User uid (optional): This can be used to uniquely identify a user, it will
#   not be set when a global server message is received.
command = "python3 ./script.py"
# Run the command in a shell so pipes can be used, etc. The same arguments as
# for commands will be passed, make sure to escape them!
shell = "echo Hi, \"$3\""

If a command is executed and returns -1 as status code, the action of this command will be skipped and the next matching action will be executed. This can be used to e.g. allow only certain users to quit the bot:

[[actions.on_message]]
regex = "^\\.(del|quit)"
# This is unix specific, on windows this should be another command.
shell = "grep -Fqv \"$4\" whitelist.txt"

And create a file whitelist.txt:

One uid per line

For every incomming message that starts with .del or .quit, the uid will be searched in the whitelist file. If the uid is found, grep will exit with code 1, the bot will skip this action and the .quit command will be executed. If the uid is not found, grep will exit with code 0 and the bot will respond with the command output and not execute .quit. As the command output is empty, it will be ignored.

License

Licensed under either of

at your option.

simplebot's People

Contributors

bluscream avatar flakebi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bluscream

simplebot's Issues

How to pull arguments?

how to add command like:

.test

and when i run it that have to do:

respond on teamspeak like: Successfuly started for to end
and run command via "shell" or "command" like: echo

how to do that?

Client Version

From where the bot is getting client version?
Is it possible to easily change it?

Default channel

I guess that it is easy to set default_channel by adding a code snippet into main.rs and it is last thing that I need.
I would be more than happy if you can help me with this.

It is probably as simple as my last question. (I've created extra issue as someone may find this useful later)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.