Giter VIP home page Giter VIP logo

welcomebot's Introduction

What is this?

oh-irc-bot (or "WelcomeBot", its IRC nick) is a bot for welcoming people into the #openhatch irc channel when no one is paying attention. It has two main goals: first, to alert community members when someone new enters the room and says hello (either by using their nick in a response, or by sending a private message). Second, it helps the new person to feel welcome even when there's no one around, and provides more information to them about staying in touch.

Basic Structure

bot.py is the project's main file. It uses the socket module to communicate and gathers a list of known IRC nicknames, stored in nicks.csv. Its basic functions include:

  1. If someone enters the channel, the bot checks to see if they are a known nick. If not, it adds them to a list of people to greet. If no one else has spoken into the channel after a period of time, 60 seconds by default, it greets them. If someone else (not the new nick) speaks into the channel within the set wait time, or if the nick is known, the bot remains silent. The bots response text includes the nicks of channel maintainers/frequent contributors so that they are pinged. Channel maintainers can change the wait time of the bot by using the following command in the irc channel: Botname --wait-time new wait time in seconds.
  2. If someone says hello to the bot, the bot says hello back.
  3. If someone asks the bot for information (via key phrases like "help", "faq", etc) the bot explains what it is and links to this repository.

The repository contains test_bot.py, which is a set of automated tests for the bot. To learn more about these, see Testing below or the testing tutorial. It also contains test_nicks.csv, the set of nicks used for the automated tests.

Finally, we have a docs folder which contains tutorial-style instructions for various concepts used by WelcomeBot. Currently there is one tutorial, for unit testing.

Setting up

Currently, the bot is only compatible up to Python 2.7.

To run the bot:

  1. Download the repository. If you need help using github, see here.
  2. Edit bot.py to change the nickname to something besides "WelcomeBot" and the channel to "openhatch-bots".
  3. Open up a command line and type python bot.py.
  4. Although all IRC messages should be printed to your command line, for development purposes, it will probably be useful to be on IRC separately using your normal nick.

If you run into setup difficulties, ping shauna on freenode (via the #openhatch channel is preferred) and/or leave an issue in this repository's issue tracker.

In order to keep the bot continuously running, we put it on a server using the following command:

nohup python bot.py &

Nohup keeps it from terminating when we close the terminal and & keeps it from printing the IRC messages to the terminal.

Testing

We use Python unittest to test the bot, and Coverage to look at the test coverage.

When running tests, use this command:

python -m unittest test_bot

The output should tell you how many tests you ran and if any of them are failures.

When creating tests, you can use the following series of commands to see whether your test is testing the code you want it to test:

./bin/coverage run test_bot.py ./bin/coverage html

You can then see the results in htmlcov/index.html.

Note: You will likely need to install coverage. The above command assumes you have installed it to a virtual environment. If you haven't, use coverage instead of bin/coverage, for example: coverage run test_bot.py

How to help

The issue tracker lists improvements we want to make. Tasks that are better for newcomers are labelled first task.

I strongly encourage you to contact me and say hello before you get started (I am shauna on the #openhatch IRC). Please feel free to submit pull requests to address these issues. If you're not familiar with how to do this using github, see here. You can also always ask me for help or clarification.

Credit

This bot was adapted from code found here.

welcomebot's People

Contributors

aaparella avatar aaron1011 avatar bananaobserved avatar dcarrot2 avatar jbertino avatar kwurst avatar lkuper avatar ppegusii avatar shaunagm avatar sunu avatar vr-clarissa 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

Watchers

 avatar  avatar  avatar  avatar  avatar

welcomebot's Issues

License

Would you mind adding a license to the welcome-bot? Thanks!

the > in the url

When the bot is queried the URL shown has an extra > at the end, resulting in a 404 page

More flexible regexes for greeting WelcomeBot

As a follow up to this issue I think it would be great if our regexes were a bit more flexible. For instance, the common "WelcomeBot: hi" does not trigger a response - the greeting needs to come before the name. I think we should at least make sure any order is recognized.

Add rules to catch un-identified names

When users who have registered their nicknames join IRC without identifying, different IRC clients will change their nickname in different ways.

For instance, the default behavior in quassel is to add a trailing underscore (or two, or three) if you haven't identified to your nick. The bot currently catches this (https://github.com/shaunagm/oh-irc-bot/blob/master/bot.py#L113) but if we can determine the rules for other popular clients we can catch those as well.

To improve the bot, please:

  1. Research an IRC client (ideally starting with the most popular ones) and determine the default for un-identified nicks.

AND/OR

You can look through the stored nicks for patterns.

  1. Add to bot.py, in the function clean_nick(), appropriate rules to deal with that behavior.

Update: The bot now deals with trailing underscores, trailing numbers, and things with a pipe. Is there anything we're missing? The main one I see when browsing through the nicks is something like: name[Mobile]

Extract OpenHatch-specific details in a configuration file

There are lots of Python constants that could be moved into a configuration file instead of being hardcoded. This would make configuring a non-OpenHatch bot easier, and allow staying up to date with changes to WelcomeBot without having to merge.

WelcomeBot replies to PMs in #openhatch always

/query WelcomeBot faq WelcomeBot

will trigger in #openhatch.

See:

20:05 < paultag> ok, bug report time:
20:06 < WelcomeBot> I'm a bot!  I'm from here 
                    <https://github.com/shaunagm/oh-irc-bot>.  You can 
                    change my behavior by submitting a pull request or 
                    by talking to shauna.

Explain how to set up WelcomeBot to run indefinitely

I'd like to run WelcomeBot in a channel I moderate, but I haven't run an IRC bot before, and I'm not sure how to set up a bot to run indefinitely/permanently. I'd like to see a bit of explanation for recommended ways to do this.

For example, my friend suggested that I could run it inside a screen session on the tiny server that I use for running irssi inside screen; I haven't tried setting this up yet though.

add notification when bot crashes

Right now the WelcomeBot stops running at seemingly random times and sits there, quietly, until someone notices and reminds me to log into the server and restart it. It would be nice if I got an email notification or something similar when WelcomeBot stopped running.

Bot fails when given certain ircmsg inputs

Branched from a previous issue: #10

Every couple of weeks, WelcomeBot goes offline. The error messages all seem to look like this:
File "data/bot.py", line 98, in
actor = ircmsg.split(":")[1].split("!")[0]
IndexError: list index out of range

The input that appears to have caused this looks something like this:

ERROR :Closing Link: 87.98.215.226 (Ping timeout: 265 seconds)

It's not clear to me what's causing the index out of range. Split returns a list of size 1 or greater (I believe) so doing split("!")[0] should be fine, even if there's no ! in the string (as appears to be the case above). And the input above does have several ":" so the [1] shouldn't be out of range either. Maybe this is the wrong input somehow?

If we can't figure out how in particular this is being broken, we can perhaps still solve it by inserting a try:except statement around line 98. I don't think that we actually need to address whatever this rare, break-ing message is - we can just insert some nonsense that doesn't match any of the .find()s in the rest of the loop.

Improve tests by making a mockup of time

This is slightly advanced testing bizness. Basically, right now the testing suite is testing the time-sensitive aspects of the welcomebot code by using .sleep(), but @nedbat points out that a more robust way to do this is to make a mock time (like we do with the ircsock object). If anyone wants to pair with me on this, let me know!

Re-implement greeting newcomer by name

Right now we import the welcome message from a settings file and attach it to an instantiated bot, but with this method we can't dynamically include the username with the message. My guess is that the best way to fix this is to have welcome_message be a method on the bot which takes a username.

Unnecessary import

The bot currently imports queue, which is no longer used. It should be removed!

While they're at it, whoever fixes this issue should make sure that the other import statements are being used. You can do this by searching for references to the library in the program.

Don't welcome a nick who enters and then leaves

Currently the bot welcomes people who enter and then leave before the 60 second countdown ends.

It's obvious we shouldn't welcome someone who has left. The question is whether they should get their nicknamed stored. Thoughts?

Unit tests fail if nicks.csv does not exist

Before a contributor can run unit tests it is assumed that the user has a created a nicks.csv file in their WelcomeBot directory. Proper unit tests should create required files in the setUp() function and remove them during tearDown().

Traceback (most recent call last):
  File "test_bot.py", line 41, in setUp
    self.bot = botcode.Bot()
  File "bot.py", line 25, in __init__
    with open(self.nick_source, 'rb') as csv_file:
IOError: [Errno 2] No such file or directory: 'nicks.csv'

WelcomeBot having difficulty with newcomers who quit then rejoin before wait-time is over

Just observed this happening:

[14:10:42] -- jerrychen (~jerrychen@$place) has joined #openhatch
[14:11:00] jerrychen: Hello
[14:11:58] -- jerrychen (~jerrychen@$place) has left #openhatch
[14:12:11] -- jerrychen (~jerrychen@$place) has joined #openhatch
[14:14:26] shauna: hi jerrychen
[14:17:12] WelcomeBot: Welcome jerrychen!  The channel is pretty quiet right now, so I thought I'd say hello, and ping some people (like shauna, paulproteus, and marktraceur) that you're here.  If no one responds for a while, try emailing us at [email protected] or just try coming back later.  FYI, you're now on my list of known nicknames, so I won't bother you again.

Initial thoughts: when someone quits before being welcomed, they should be treated as new when they return. Maybe somethings going wrong with that part of the program and the old newcomer object is not being removed?

This bug should probably be reproduced before we go further.

Bot compatability with Python 3

The bot program as currently designed does not run in python 3, only python 2. I don't know how to make it able to function in python 3, but it would probably be good if someone updated it to function with newer versions.

Make test suite

Probably a good start is to just list the things we want to test. This could go in the readme for manual testing. At some point it would be nice to set up automated testing, too.

Fix hello/help functions.

WelcomeBot currently has very primitive regexes that tell it when to reply to a greeting or request for information (https://github.com/shaunagm/oh-irc-bot/blob/master/bot.py#L120).

For instance, it looks for any of the items in helpArray anywhere in each message, along with its name. So "I think WelcomeBot should stop talking" triggers a greeting, because it contains "hi" and the bot's name.

It seems likely that we could use regular expressions to improve upon this. Another option would be to generate phrases such as helloArray[i] + " " + botnick.

Change hard-coded values in testing suite to variables

Four tests (test_sent_messages, test_hello, test_help, & test_welcome_nick) currently fail and two tests (test_wait_time_from_non_admin and test_wait_time_from_admin) give errors because certain variables are hard-coded into the tests. We need to replace these with references to the variables themselves.

For example, in test_sent_messages (test_bot.py line 105) you can see that the list of strings Expected hard-codes the bot nickname of WelcomeBot2 and the channel openhatch-bots.

To fix this, we need to pass the variables used in bot.py (should be doable by passing botcode.channel, botcode.botnick, etc) and incorporate them into the test strings using the formatting described here and seen, for example, here.

At issue are, I think: channel, the bot's nick, and the number of admins allowed (the suite currently hard-codes for a single admin).

Document the test suite

Right now there are few comments in test_bot.py, and the README only covers how to run the test suite, not how to understand it nor how to write your own.

Check account name for "remembered" nicks

Let's check with NickServ to see if the nick that joined and isn't recognized is maybe an account we recognize.

This would save people like paulproteus from being greeted when he joins as paulprot1us etc.

May need to populate this (slowly) by running through the database and sorting out if any of the saved nicks are associated with accounts.

Add a function that registers your nick, if your bot uses one

In order to implement this, we'll probably need to add:

  • a variable or flag in the code that indicates whether or not the bot should try to identify
  • a function that sends a message to the network identifying using this syntax

To keep the password private, you'll probably want the password to be read in from a separate file, for example "bot_password.txt", that is outside the repository or is gitignored.

Create tutorial-style documentation

I would like WelcomeBot to be useful as an example of implementing different tools and concepts. To that end, let's expand the documentation to explain:

  • How we do testing, and how we use python's unittests
  • How regular expressions work, and how we use python's regex functions
  • How IRC works, and how we use python's socket and select libraries

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.