Coder Social home page Coder Social logo

irc-bot's Introduction

IRC Bot

A simple IRC Bot written in Python To start it just cd to the src directory and type ./ircbot.py, although before using the bot it's recommended to check the config first.

The bot can handle multiple channels at a time, also if you want to have a private discussion it can be queried (/query PPyBot).

IRC Protocol reference: RFC 1459

Disclaimer: This project is no longer maintained, it was just a learning project and it was coded close to the data that the freenode servers send when taking actions such as changing the nickname, hence it is possible that the bot doesn't work on other servers. (For details please see issue #42)

Documentation

Sphinx docs to come

Commands

  • !google <search term>
    • returns a link and a short description of the first Google search result
    • see Dependencies: !google
  • !wiki <search term>
    • replies a wikipedia link for <search term> along with the first paragraph from the page
  • !quit [#channel ]+
    • disconnects the bot from the given list of channels
    • if no arguments are given, all connected channels are disconnected
    • if some arguments are provided the bot checks the channel names and disconnects only the valid ones
    • if no channel is "alive" then the bot closes
    • Example: !quit #foo #bar - quits from #foo and #bar
    • see Config: owner, channels
  • !join <#channel >+
    • the bot joins the given channels, minimum one channel name must be supplied
    • see Config: owner
  • !channels
    • replies a list containing the channels the bot is connected to
    • see Config: owner
  • !help
    • list all available commands
  • !answer
    • you'll find the answer through this command
  • !weather <city> or !weather <city>, <state or country>
    • replies some info related to the current weather conditions from the given location
  • !about
    • a few words about this software
  • !mball
    • the famous Magic Ball
  • !uptime
    • shows current uptime of the bot
  • !so <search term>
    • replies the first question's title and URL from the search result
    • see Dependencies: !so
  • !twitter [username]
    • replies the latest tweet(along with the tweet date) for the username provided
    • the date will have the following format: DD/MM/YYYY HH:MM
    • if no username is provided then the bot will try to get the latest tweet for the IRC-user who issued the command

Total: 13 commands

Auto-commands

  • email_alert - the bot sends an email to the owner when somebody talks to him

Total: 1 auto-command

Adding commands

  1. In src/config.py you must add the name of the command to the cmds_list's end(without !)
  2. In src/cmds/ directory you must create a file named after your command
  3. Into the newly created file you must define a function named after your command that takes one parameter, this parameter will contain the command components sent by the user, the function must return either a message(string) to be sent on the channel, either a list, first item being a command(other than PRIVMSG which is added automatically if needed) and the second being the command's arguments.

E.g.:

If you want to create a command !ncmd, you must follow these steps:

  1. Add 'ncmd' to the cmds_list in src/config.py
  2. Create src/cmds/ncmd.py
  3. In src/cmds/ncmd.py define def dance(param):, param will hold the users command components(see src/parser.py) in case you must do some checkings, it must return a message(eg. return 'Dance time!', in this case src/ircbot.py will automatically add PRIVMSG at the beginning and \r\n at the end) or a list(eg. return ['JOIN ', '#chan1,#chan2'], in this case the list will be joined and \r\n added at the end)

If you want to create a command that the bot should execute if something happens on the chat (not if the command is manually triggered) you should add the command name to the auto_cmds_list insead of cmds_list.

Config

See src/config.py:

  • owner - the users who are allowed to send a specific command to the bot (for example the !quit command)
  • log - path to the logging directory, all logs are stored here
  • server - server to connect to (default: chat.freenode.net)
  • port - port number to use (default: 6667)
  • channels - a list of channels to connect to
  • nicks - a list of strings, the bot's name will be the first unused nick from this list or the first nick in the list and a random sequence appended if all nicks are used
  • real_name - bot's "real name"
  • cmds_list - a list of strings that the bot knows to answer to
  • auto_cmds_list - a list of commands defined as regular commands with the only difference that they cannot be invoked by users, the bot executes them as result of an event

Dependencies

  • !weather, !twitter and !wiki module depends on BeautifulSoup
    • !weather and !twitter depends on BeautifulStoneSoup (XML)
    • !wiki depends on BeautifulSoup (HTML)
  • !google module depends on Google Custom Search API
  • !so module depends on StackExchange API
    • you're going to have to generate an API key and populate the api_key variable in src/cmds/so.py

License

(C) Copyright 2011-2014 Barbu Paul - Gheorghe

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

irc-bot's People

Contributors

chiggins avatar markneves avatar paulbarbu 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

Watchers

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

irc-bot's Issues

Futures Module

Hello! :) What exactly am I doing wrong where I keep getting "ImportError: No module named futures" when trying to execute the script? I've pip'd the module in, and am still seeing this? I'm sure it's something ridiculously easy. Any advice? Thanks!

Thread safe functions

Since the commands will be run in separate threads/processes, the functions that can be used in both core and commands should be thread safe (especially if they use shared resources such as the socket or the log file).

garbage after command

!command_with_no_required_args garbage here
solution: len(!command_with_no_required_args) == len(components['arguments'])

Commands config

Commands should have their own config files in order to keep the core clean

help

!help command( print doc)

Multi response string

This message won;t be fully sent:
Task 1: test\r\nTask 2: make homeworks\r\nTask 3: test2\r\n
Because it's transformed:
PRIVMSG #ppybbot :Task 1: test\r\nPRIVMSG #ppybbot :Task 2: make homeworks\r\nTask 3: test2\r\n

Add join and quit messages

Yield a message after joining the channels.
Yield a message after quitting the channels(if not quitting all the channels of course).

abnormal disconnect

I'm using this bot on my server and test in local machine.

Bot connects and works normally, but at some point the bot simple simply, no error, no log, only disconnect. I tested locally and in 2 servers and have same problem, then isn't network problem.

Check for commands on the fly

Get rid of cmds by checking for cmds on the fly.

A way to disable a command would then be to check for a disable = True variable in the command's module.

This enables me to hot plug commands.

Undernet

On Undernet, the bot say's it connected but it's not, I changed the server to freenode and it work, can't figure out the issue.

Github

Add some github related commands using their api

weather

!weather sibiu romania (no comma)

RSS

!rss (get latest post)

Generate docs

using doxygen

  • Main page
  • every function and every variable
  • author

Verify user

Verify if the owner is authenticated on freenode

/msg nickserv info <nick>

Consider the cases:

  • not registered as without rights
  • registered and in the owners list as the user has rights

Add tests

Add tests using unittest and mock.

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.