Giter VIP home page Giter VIP logo

twitch-bot's Introduction

Roboraj

This is a simple Twitch chat/irc bot written in python.

Installation

  • Open up your terminal/shell of choice.
  • Install the [http://docs.python-requests.org/en/latest/](Requests library) if you haven't already using pip install requests. I tested this application on Python 2.7.5.
  • Clone the Git repository.
  • Move config/config_example.py to config/config.py. Replace all of the placeholders there with your own username/oauth token/channels to join etc (tips are given in the file).
  • Type chmod +x /serve.py. To run, you simply need to execute the file by typing ./serve.py.

Adding your own commands

You're going to need to know basic Python if you want to add your own commands. Open up lib/command_headers.py. There are examples of pre-made commands in there as examples. The limit parameter is the amount of times a command can be used in seconds, if you don't want a limit to be enforced put in 0.

If your command is only going to return a string, ex - !hello returns Welcome!, don't include the argc parameter. Place the string you wish to be returned to the user in the return parameter. For example, if you wanted to create a command such as this and limit it to being used ever 30 seconds, you would add in:

'!hello': {
		'limit': 10,
		'return': 'Welcome!'
}

However, if your command has to have some logic implemented and if the command is just going to return whatever a function returns, set the return parameter on the command to command, and set argc to 0. If your command is going to take arguments, ex !hello <name>, set argc to 1 or however many arguments the command is going to take in.

Make a new file in lib/commands/ and give the filename command.py where command is the command name. If your argc was set to 0, don't include args in the functions parameters, else set the only parameter to args. Args will contain a list of whatever arguments were passed to the command.

This command will contain whatever logic needs to be carried out. You should validate the arguments in there. After you have the response that you want a user to see, just return it.

Let's say we want to add a command which will take two arguments, we will call it !random and it will take a minimum and maximum argument. We will limit this command to be allowed to be called every 20 seconds.

Add the following to the commands dictionary:

'!random': {
		'limit': 20,
		'argc': 2,
		'return': 'command'
}

And then in lib/commands/random.py , write the following:

import random

def random(args):
  min = args[0]
  max = args[1]
    
  usage = '!random <min> <max>'
  
  # carry out validation
  try:
    return ranrange(min, max)
  except ValueError:
    return '!random <min> <max> (use full integers)'
  except:
    return usage

And now if somebody types !random 5 10 into the chat, the bot will respond with a pseudo-random number between 5 and 10.

twitch-bot's People

Watchers

 avatar

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.