Git Product home page Git Product logo

camper-gitter-bot's Introduction

CamperBot

Join the chat at https://gitter.im/FreeCodeCamp/camperbot Stories in Ready

This is a full featured bot for Gitter.im/FreeCodeCamp chat rooms.

Main features:

  • integration with github FCC wiki
  • find (alias explain) command to show wiki pages
  • wrapper for commands

The CamperBot is integrated into various FreeCodeCamp chat rooms.

Join us in Gitter.im/FreeCodeCamp/camperbot to discuss about camperbot development!

Test the CamperBot in the Gitter.im/FreeCodeCamp/camperbotPlayground room.

CamperBot was originally created by for Free Code Camp by @dcsan at RIKAI Labs, and is now maintained by our open source community.

Contents

Introducing CamperBot!

CamperBot is a full featured chat bot for Gitter.im developed to integrate with the chat rooms for FreeCodeCamp — the largest online coding bootcamp in the world , where it serves more than 60,000 campers.

Github Wiki Search

You can search for articles in a projects github wiki

Share wiki summaries in chat

Use explain to pull a wiki summary right into the chat:

Points system

Allow your users to send points to each other to say thanks @username

Fixed messages

Based on scannable expressions, send messages into the chat.

Extensible

Custom functions can easily be added. Check the System Overview

Installation instructions

To run camperbot, you need Node.js 4.2.0 or greater.

Mac / Linux

To install Node, follow the instructions here

  • To make your local server automatically watch for file changes, install "nodemon" (you may need sudo)
npm install -g nodemon
  • To download the app, clone the repository the bot is in:
git clone https://github.com/FreeCodeCamp/camperbot.git
  • Run the following commands to run the app:
cd camperbot
cp dot-EXAMPLE.env .env
cp example.config.json config.json
git submodule update --remote --checkout --init --recursive
npm install
nodemon app.js

You can now chat to your bot via Gitter.im at https://gitter.im/demobot/test

Windows

To install Node.js on Windows, follow these instructions.

  • To make your local server automatically watch for file changes, install "nodemon" in an administrator console.
npm install -g nodemon
  • To download the app, clone the repository the bot is in:
git clone https://github.com/FreeCodeCamp/camperbot.git
  • Run the following commands to run the app:
cd camperbot
copy dot-EXAMPLE.env .env
copy example.config.json config.json
git submodule update --remote --checkout --init --recursive
npm install
nodemon app.js

You can now chat to your bot via Gitter.im at https://gitter.im/demobot/test

Make your own bot user

If you've followed the instructions so far your bot instance is the demobot provided for you.

The .env file you copied above contains login info. This is using the shared "demobot" account so you may find yourself in a chatroom with other people using the same ID!

Here are instructions on getting your own bot user running.

Setup GitHub user

The first thing you'll want to do is set up a GitHub account which will be the username of your bot

You can either

  • make a new account
  • use an existing account

Follow the instructions for signing up on https://github.com/

change the SERVER_ENV=demobot in your .env to server_ENV=USERNAMEHERE where USERNAMEHERE is your github user name.

Getting your own appID

To setup your own gitter login info, you should create your own Gitter API key on their developer site, and replace the info in that .env file. Get your own API keys for gitter from: https://developer.gitter.im/apps

When you sign in to the developer page select the option to make an app. Name the app what you want and set the callback url to http://localhost:7891/login/callback

The next page should show you various API keys/secrets. Use those to replace the demobot default options in your .env.

Configure your bot

Now it is time to set up your bot w/ the app. Copy example.config.json to config.json and open config.json in your editor. Replace all instances of GITHUB_USER_ID with your user name set up earlier.

Take note of the the rooms property of config. You can set up additional gitter rooms to connect your bot to here. The default room is GITHUB_USERID/test feel free to change this.

You may chat with us in the CamperBot Dev chat room if you have problems. contributors chatroom.

Running tests

Tests are located in the test/ folder can be run, along with linting, by running gulp. This is a watch task that will rerun whenever a .js file changes.

Wiki Content

The wiki content is pulled in from FCC's wiki using a git submodule. But then we just copy it and commit it back to the main app as submodules are nasty to deal with on production servers.

bin/wiki-update.sh

System Overview

data/RoomData.js

The list of rooms your bot is going to join.

To start with create your own bot, a test room to enter and debug in. This needs to be changed so you would only join your own rooms, otherwise developers will get into a situation where everyone is joining the same rooms and the bots go crazy talking to each other!

lib/bot/BotCommands.js

This is where you add things that the bot can do. Some commands are broken into separate files such as cmds/thanks.js and cmds/update.js. Each command gets a input which is a blob of data including what the user entered, and a bot instance.

KBase.js

The Knowledge base. This is an interface to all the data in the wiki.

RoomMessages.js

This is for static messages that are fired based on regex matches. If you just want to add some basic responses, this is the place to edit.

How to add a new Bot Command

Look at BotCommands, echo function. This is an example of a command being called. Anytime a user types a line starting with echo that will get passed to this function in input.

echo: function(input, bot) {
    var username = input.message.model.fromUser.username;
    return "@" + username + " said: " + input.message.model.text;
}

The input object contains keyword and params fields. If you type echo this you'll get

//input
{
    keyword: 'echo',
    params: 'this'
}

From any command you just return the new string you want to output. So you can add new commands with this knowledge.

More detail on how commands are found and called

In GBot.js

if (input.command) {
    // this looks up a command and calls it
    output = BotCommands[input.keyword](input, this);
} else {

BotCommands is a list of functions. E.g.

BotCommands.thanks = function() { ... }

where input.keyword is thanks then

BotCommands[input.keyword] is like saying BotCommands.thanks()

so then the params get also added in (input, this) so its

BotCommands[input.keyword](input, this);
//becomes
BotCommands.thanks(input, bot);

All of the bot commands expect these two params. E.g. in thanks.js

var commands = {
    thanks: function (input, bot) {

In RoomMessages.js we also have a table of regex and matching functions.

{
    regex: /\bth?a?n?[xk]s?q?\b/gim,
    func: BotCommands.thanks
}

We may switch all to just use this method in future. Would you like to help?

Environment Notes

wiki data

We use git submodules for some wiki data. to get these submodules you would do:

git submodule update --remote --checkout --init --recursive

Contributing

Have a look at the HelpWanted label issues and consider making some first steps!

The labels, P1 = priority one, and 'S' means a small task, so good places to start.

Chat with us!

Chat with us in the contributors chatroom if you get stuck.

camper-gitter-bot's People

Contributors

abhisekp avatar benmcmahon100 avatar berkeleytrue avatar cerebr4l avatar chrisdziewa avatar clairejanine avatar darthmeme avatar dcsan avatar ddaems avatar dhcodes avatar dting avatar duffn avatar elaine-jackson avatar irinatag avatar jonathan-grah avatar kirah1314 avatar ltegman avatar manish-giri avatar oab00 avatar offllne avatar ojongerius avatar opatel99 avatar quincylarson avatar rafase282 avatar raisedadead avatar saintpeter avatar t3h2mas avatar texas2010 avatar throwarray avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

camper-gitter-bot's Issues

'help me' issue

words:

help me

trigger adding environment variables [wiki]
which is obvious error. please fix that, it's annoying how much time we have to see this window
help_me

Project Ban Hammer

Project Ban Hammer

In order to facilitate troll extermination we need a system to promote campers to admins in Gitter without giving them write access on Free Code Camp org. We can do this. We have the power.

This will come in three parts.

  • Promote CamperBot's github user to an owner on FCC org.
  • Create a command where camperbot will enter the text /ban @<someUser> in all our main chat rooms.
  • Checks if the user giving the command is a FCC admin (This will be a list on the server that will not be tracked here on the Repo)

Update relative links to absolute links in chatrooms

Recently, we have made a switch to relative links in the FCC wiki. The links to other wiki articles, or fragmented links within same articles - are now relative.

However, the content in the chatroom would require absolute links. We need to have camperbot parse the links before posting, and add a constant URL string ahead of all hyperlinks.

Add per-camper "Thank You" rate limit

No more than X Thanks Yous per minute/hour/etc. Also, maybe no more than ?10? per thank you. Don't award any points at all if there are more than a certain number of @mentions in a message?

We had an issue where someone came into the main channel and spammed thank yous A LOT. It took a long time for Camperbot to process them all and could have acted like a DOS to the API and Camperbot.

Need to make bot recover from API errors

When camperbot hit the cloudflare DDoS protection it stopped accepting thanks and would not recover without a restart. camperbot should be able to recover from an error like that.

Remove/Improve "Add a Wiki" response

Right now if you search for something using the wiki command and it's not found you get a message like this:
image
The URL is no longer valid because we turned off the main Wiki commits. Now you need to go through the PR process on the main Wiki.

Maybe we need an article on how to add articles? Anyway, we need to remove this message for now.

Ask magic eightball questions

Right now it only responds with the command eightball. It be really cool to be able to
Oh magic eightball, Should I go to sleep?

I think we can scope it to lines starting with Oh magic Eightball. Thoughts?

Camperbot quiet thresholds

When the chat channel has high traffic Camperbot should be silenced from spamming mass body of texts to commit a CoC violation of spamming either on purpose, accidental or informational.

This could be also resolved with a prefix but combining both will keep the chat from being overloaded by a rogue Camperbot command.

Ex: If the chat is moving at a high rate, do not allow camperbot to spam more than 3 lines of text, no images, no gifs.

Tests shouldn't rely on live wiki data.

This makes some of the tests incredibly brittle. Our build is broken again because the wiki changed. Tests that rely on wiki type data should have data mocked for them.

Explain fails for staticReplies

Trying to explain items in the staticReplies array fails with tried to linkify an empty item because there is no dashedName property, so the bot sends this:

screen shot 2015-12-02 at 11 06 07 am

Regular wiki item explain js closures

topicData {
  displayName: 'js closures',
  fileName: 'js-closures.md',
  data: 'example',
  dashedName: 'js-closures' }
Utils.linkify> link [js closures  [wiki]](https://github.com/freecodecamp/freecodecamp/wiki/js-closures)
Utils.linkify> link [read more about js closures on the FCC Wiki](https://github.com/freecodecamp/freecodecamp/wiki/js-closures)
GBot> out|  ## :point_right: [js closures  [wiki]](https://github.com/freecodecamp/freecodecamp/wiki/js-closures)
Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure 'remembers' the environment in which it was created.
> tags: closure, javascript, js
:pencil: [read more about js closures on the FCC Wiki](https://github.com/freecodecamp/freecodecamp/wiki/js-closures)

staticReplies wiki item explain link

topicData try this [guide](http://www.freecodecamp.com/field-guide/all-articles).

I can try to take this one, but need feedback on how to handle. Link to the wiki home page for these, change how these are handled and not link to anything, something else?

User not found error message wording

The bot currently says "could not find receiver for user". It should provide a better worded error message when it can't find a user for brownie points.

screen shot 2015-12-04 at 2 23 15 pm

In-Chat Wiki (approach) Floods View

Camperbot's wiki invocation (via such commands as explain, help, etc.,) results in, potentially, large wiki pages that can contain: multiple lines, static (or dynamic gif) images and other media that disrupts the chat window (both on desktop/ and mobile platforms). Would it be possible to limit summary to 2-4 lines and provide the actual link to the wiki?

Add Travis CI

Tests are passing and linting is good right now, so this should be a cinch to get set up. I'll play around with it tomorrow.

Camperbot commands behind a prefix

Too many times do users come into a channel and type 'help me' or something similar that generates a wall of text or any english word that happens to be a camperbot command.

Example:
!explain format
!help where art thou

Camperbot is down

Camperbot is down across all the chat rooms since today (09/20), that I know of. Just FYI.

example.config.json breaking new features.

It looks like copying example.config.json to config.json is breaking Travis CI tests. See PR from @abhisekp here (scroll down)

It's an easy fix. Move the example to config.json and update the readme. The code itself relies on config.json which is why the test fails.

It makes sense for users who don't need a custom bot user not to need to alter a config.json anyway.

Camper bot - Wiki Migration

As discussed earlier with @Rafase282 in the chat:

Camperbot will no longer be able to suggest any of the wiki articles including:

  1. Solution hints
  2. Rooms
  3. Articles
  4. Any other help topic

Hence the course of action is now to:

  • Close all the open issues are pull requests with after a thorough audit.
  • Fix any issues relevant to chat and clean up this repository of the wiki related logic.
  • If it receives any command for wiki, respond with a migration message.
  • Deploy the bot.

Note : Its functionality to thank people will remain as such.
But any relevant help links should be removed or changed to forum links if available

/cc @FreeCodeCamp/issue-moderators
Refer freeCodeCamp/freeCodeCamp#9731

[Feature Request] Big Text Announcements

When there are known issues on FCC, we sometimes need to make "Big Text" announcements across channels. It would be nice if we could use the Camperbot to simplify this.

Command

!bigtext <Message>
We want it to be impossible to accidentally use. The output formatting might be pre-defined, or allow for the user to enter arbitrary text and formatting.

Broadcast Scope

We probably don't need it across every possible channel, more like just the "Core" help channels and main channel. We're need a list built in to the system.

Important Security

It would be critical that this command could only be used by designated admins. I'm thinking these would be hard-coded in to the codebase to prevent hijacking.

This could potentially also be limited to only being executed from a single room.

It might make sense to have a two stage process:

  1. Define what you want to say
  2. Camperbot echos it back in the current channel for review
  3. !bigtext confirm to broadcast or !bigtext cancel or just do a new bigtext to update the message.

Remove web interface

This is not currently used by FCC and I also don't think it's completely working. I propose removing this.

Explain Java

When you know someone bring up the subject of my worst enemy (java) and I "cleverly" think "hmmm if I type explain java surely I will get a page telling this nice person about the horridness of java" but instead I got a page on javascript!

This makes me very upset for two reasons:

  1. It made me look dumb (very bad time in my life).
  2. java != JavaScript

It would be nice if we could do something about this atrocity.

Love,
CEREBR4L

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.