Giter Club home page Giter Club logo

lorenzotherobot's Introduction

Build Status Circle CI

Try it out! The Code is live at http://www.twitch.tv/curvyllama You can send a whisper by typing /w Lorenzotherobot hi into the chat (from any channel)!

Lorenzotherobot

A bot with personality

Introducing Lorenzo - a Twitch chat/irc bot written in Python (2.6 / 2.7) with FULL WHISPER SUPPORT and more features than I care to count at this point. This implementation relies on a highly customized IRC connection library that allows for hot event-driven bot action over multiple sockets at once.

Installation

Virtual Environment

I would recommend running this in a virtual environment to keep your dependencies in check. If you'd like to do that, run:

sudo pip install virtualenv

Followed by:

virtualenv venv

This will create an empty virtualenv in your project directory in a folder called "venv." To enable it, run:

source venv/bin/activate

and your console window will be in that virtualenv state. To deactivate, run:

deactivate

Dependencies

MySQL Installation

Depending on your distribution, starting the server will be different, on a mac, this is accomplished by doing

brew install mysql
mysql.server start

Python Packages

To install all dependencies locally (preferably inside your activated virtualenv), run:

pip install -r requirements.txt

Further Steps

Make a copy of the example config file:

cp src/config/config_example.py src/config/config.py

Make a copy of the example globals file:

cp globals_example.py globals.py
Database Setup

From here, you need to enter the mysql console as root:

mysql -u root  # may require sudo
mysql> USE mysql;
mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY '';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost';
mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER';
mysql> FLUSH PRIVILEGES;
mysql> exit;

$ service mysql restart

Create your database and name it whatever you want (from within the mysql shell):

CREATE DATABASE databasename;

Then quit out of the shell:

\q

Create your schema from my blank template:

mysql -u root DATABASENAME < schema.sql

Globals and Config Files

Head into src/config/config.py and enter the correct channels and cron jobs you'd like to run, then go into globals.py. Leave CURRENT_CHANNEL, CURRENT_USER, VARIABLE, and CHANNEL_INFO alone.

Finally

To run:

./serve.py

Commands

So, what can the bot do? Here are a list of current commands in no particular order with a description of each (if one is needed):

!follower: !follower [username]
!quote: !quote
!opinion: !opinion
!llama: !llama ['treats'/'shots'/username/'list']
!release: !release [party_position_number_to_be_released] [your_username]
!commands: !commands
!arbitrary: !arbitrary ['number'/'emote']
!addquote: !addquote [quote]
!check: !check ['trades'/'market'/'items'/'inventory'/username]
!caster: !caster [streamer_username]
!define: !define [insert_word_here]
!tallgrass: !tallgrass [number_of_treats_to_sacrifice]
!nickname: !nickname [position_to_update] [nickname(must not contain spaces)]
!help: !help
!popularity: !popularity [name_of_game]
!followers: !followers
!trade: !trade [party_position] [requested_pokemon] [minimum_asking_level]
!catch: !catch
!stream: !stream
!buy: !buy [item_number]
!edit: !edit [!command_name] [user_level (reg/mod)] [response (to add a custom user, use "{}")]
!uptime: !uptime
!winner: !winner
!add: !add [!command_name] [user_level (reg/mod)] [response (to add a custom user, use "{}") (to include message count, use "[]")]
!donation: !donation [username] [dollar_amount]
!party: !party [position_to_check(1-6)/'members'/username]
!battle: !battle [position_to_battle_with] [opponent_username]
!gift: !gift [username] [pokemon_name/'item'] [starting_level/'item_number']
!rem: !rem [!command_name]
!leaderboard: !leaderboard
!weather: !weather [units (metric/imperial)] [location (any format)]
!treats: !treats [add/remove/set] [username] [number]
!use: !use [item_position] [party_position]
!shots: !shots [add/remove/set] [number]
!wins: !wins [add/remove/set] [number]
!evolve: !evolve [position_to_evolve]
!report: !report [insert bug report text here]
!highlight: !highlight
!redeem: !redeem [party_position_to_trade] [username_to_trade] [party_position_to_redeem_from_user]
!loyalty: !loyalty [username]

Make It Do

Adding your own commands

You're going to need to know basic Python if you want to add your own commands. Open up src/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.

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 in src/lib/command_headers.py:

'!random': {
    'limit': 20,
    'argc': 2,
    'return': 'command',
    'ul': 'mod',
    'space_case': True
}

'limit' refers to the cooldown. The cooldown is only active per separate channel

'argc' refers to the number of arguments a command accepts, separated by spaces. If the command does not have 'command' as its 'return' value, this is not necessary. However, even if there are no arguments and 'command' is listed, 0 should be used.

If a command is not intended for use by moderators, there is no need for 'ul' to be included

a 'space_case' is a special scenario where you would like a command to have a single argument, but no limits to the number of separate strings you can input. Normally, arguments are separated by spaces.

Pokémon

Built in are several functions for battling first generation of Pokémon. Users can compete to be the first to !catch the randomly generated Pokémon and !battle each other in a social, multi-stream and whisper context. Users level up after winning a battle and they can !evolve, !nickname, !trade, and even !check their item inventory (inlcuding evolution stones and rare candies). Here are some Pokémon-specific commands:

!catch
!tallgrass [amount] (!tallgrass 1000)
!party
!party ['members'/ username] (!party singlerider)
!battle [party position] [username] (!battle 1 lorenzotherobot)
!leaderboard
!check ['trades'/'items'/'inventory'] (!check inventory)
!use [item position] [party position] (!use 11 4)
!trade [party position] [desired pokemon] [desired level] (!trade 1 Bulbasaur 5)
!redeem [party_position_to_trade] [username_to_trade] [party_position_to_redeem_from_user] (!redeem 2 singlerider 6)

Whispers

If a user tries to type a message that is currently on a cooldown, the bot will whisper the user directly. It will inform them that they need to chill and how much more time they have until they can use it again. It will also let them know that they can just try to use the command in the whisper message itself. Users can type whatever they want to the bot and it will reply with quite a few responses defined in the brain directory using a language called RiveScript https://www.rivescript.com/ . There is also an API for quotes that the bot hits when it gets stumped so it sounds smart. The API is provided by http://forismatic.com/en/api/ . The bot can be whispered by typing

/w Lorenzotherobot hi

into any chatroom on Twitch.

Llama

The Llama family of features is associated with tracking user activity and returning it at will. The data is stored in a MySQL database. Every five minutes, if the streamer is currently streaming, points (or "treats") are added incrementally, one every time the function runs as a cron job. For a user to retrieve another user's or their own treats amount, they would type !llama [username]. If they would like to see a list of the top ten users in descending order, they would type "!llama list".

!llama
!llama ['treats'/username/'shots'/'list'/'wins']

lorenzotherobot's People

Contributors

harrymilne avatar joyider avatar nelsonam avatar singlerider avatar theepicsnail avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lorenzotherobot's Issues

cache current chatter data

Twitch's endpoints are starting to take way too to return a valid response. Caching is a better option.

curvyllama: davidwhodat

davidwhodat reports "couldn't access !loyalty; was told "mod-only command". shane might be testing system." in curvyllama

Gifting items to users with no treats doesn't work

[21:33:24 #shedeviil_09] [BOT] Command is valid and not on cooldown. (!gift) (izzet8486)
shedeviil_09
ID FOUND TO MATCH ITEMS AVAILABLE
invalid literal for int() with base 10: "No treats found, but don't worry. You can earn them by watching the stream when it's live!"
[21:33:24 #shedeviil_09] BOT : Item ID must be a number

Add Whisper

Add whisper functionality with conversational English responses.

I broke the bot again

Shaaaaaaaaaaaaaaaane I'm sorryyyyyyyyyy

(I did a "!battle Lorenzotherobot 4" in private chat)

Now messaging Lorenzo "!party" returns an error

Chatroom Bounties

Imagine a chat where, at a random time, the bot would assign a bounty to a user's head. The first user to claim that bounty would claim it.

Llama stream needs to display non-UTF 8 characters

"\u256f\u00b0\u25a1\u00b0\uff09\u256f\ufe35 \u253b\u2501\u253b Lets try something new." should translate to (╯°□°)╯︵ ┻━┻ Lets try something new. (╯°□°)╯

But an error message is returned because IRC doesn't like these characters.

Add HTML Scraper

Add HTML Scraper to find out what is on the home page of many websites - Syntax:

!whatson nickreboot

Requests needs Unicode-only output

!request, when coupled with video request with non-unicode characters, such as Korean characters, etc. will provide an error message, even though the video still gets appended to the YouTube playlist.

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.