Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23b0b26
Formatted readme to markdown
fenhl Apr 4, 2013
b3c835c
Run python files through 2to3
fenhl Apr 4, 2013
217035d
Fixes #1
fenhl Apr 4, 2013
be39fc1
Fixes #2
fenhl Apr 4, 2013
87bdfb5
Ditch byte strings, some refactoring
fenhl Apr 4, 2013
1000086
Fix a bug with bind()
fenhl Jul 24, 2013
3096607
Add pycache to gitignore
fenhl Jul 27, 2013
52697b7
Add optional server password
fenhl Aug 18, 2013
e3ea56f
Typo
fenhl Aug 18, 2013
a21b373
Add SSL
fenhl Aug 18, 2013
f261dc3
Replace invisible char with escape sequence
fenhl Aug 19, 2013
49b2a1e
Basic logging
fenhl Oct 13, 2013
f61844f
Log messages sent by the bot
fenhl Oct 13, 2013
335ba79
Rename __log to log
fenhl Oct 15, 2013
753082e
Add topic command
fenhl Oct 18, 2013
58ccbf5
Update readme with better intro and documentation of additional methods
fenhl Oct 19, 2013
53e3697
Add IPv6 support, fixes #4
fenhl Mar 6, 2016
2c35543
Fix: IPv6 is now used if there is an aaaa record
lemoer Jun 4, 2016
22f22fa
Use timeout while receiving on the socket
lemoer Jun 4, 2016
c6770c2
Format: added some whitespace
lemoer Jun 4, 2016
56e0161
Differentiate between gracefully reconnect and non gracefully
lemoer Jun 4, 2016
80f3d10
Disconnect after bot.keepGoing is set to False
lemoer Jun 4, 2016
dbadc64
Introduce better connect behavior
lemoer Jun 5, 2016
5777691
Sending without an active connection now results in a warning
lemoer Jun 5, 2016
95ce474
The client is now pinging the server regularly
lemoer Jun 5, 2016
5e420ab
Merge pull request #6 from lemoer/dev-timeouts
fenhl Jun 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
107 changes: 0 additions & 107 deletions README

This file was deleted.

93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
This is an **IRC bot framework written in Python 3**.

To use it, import the `ircBot` class from [`ircbotframe.py`](ircbotframe.py).

Example usage
=============

First, create the bot object with the constructor:

bot = ircBot(<irc netwrok address>, <port>, <bot name>, <bot description>[, password=<server password>][, ssl=True][, ip_ver=<4 or 6>])

Next, bind functions to the various IRC message types. These functions will be called when the IRC bot receives messages with those message types. The function to be called should be of the form:

funcname(sender, header, message)

These can then be bound using:

bot.bind(<messsage type>, <funcname>)

Once functions have been bound, connect the irc bot to the server using:

bot.connect()

Then join a / some channel(s) using:

bot.joinchan(<channel name>)

where `channel name` begins with the `#` character. Finally, make the bot start listening to messages with:

bot.run()

Bot methods
===========

ban(banMask, channel, reason)

Bans and kicks users satistfying the ban mask `banMask` from `channel` with a given `reason` (optional). Only works if the bot has operator privileges in `channel`.

bind(msgtype, callback)

This command binds a particular message type `msgtype` (passed as a string) to a given <callback> function. If the bot hears a message with this message type, the corresponding function will be called. The `callback` function MUST be of the form `funcname(sender, headers, message)` where `sender` is the nick of the entity that sent the message, `headers` is a list of any additional message headers before the message content and `message` is the actual message content. Bind can be used to listen for both server and user message types (bear in mind that server message types are usually numeric strings). Bind only allows a single function to be bound to each message type.

connect()

Makes the bot connect to the specified irc server. This function is blocking until the server sends the end of the motd or the connect_timeout is reached. The return value indicates which case you have (`True` means successful).

debug(state)

Sets the bot's debug state to `state` which is a boolean value.

disconnect(qMessage)

Makes the bot disconnect from the irc server with the quit message `qMessage` (for no quit message, put an empty string)

identify(nick, callbackApproved, approvedParameters, callbackDenied, deniedParameters)

where `callbackApproved` and `callbackDenied` are of the form `funcname(parameter 1, parameter 2, ...)`. Used for checking whether or not a user with the nickname `nick` is who they say they are by checking their `WHOIS` info from the server. If they are verified, the function `callbackApproved` will be called with the parameters `approvedParameters` (which will fill `parameter 1`, `parameter 2`, etc. in order). If they cannot be verified or are not registered, then `callbackDenied` is called with `deniedParameters`. Parameter lists `approvedParameters` and `deniedParameters` are tuples with the tuple items matching the `callbackApproved` and `callbackDenied` function parameters in order from the second parameter. For example, `identify(nick, approved, (string, integer1), denied, (integer2))`. If the nick is verified the following function will be called: `approved(string, integer1)`. Otherwise the other function will be called: `denied(integer2)`

joinchan(channel)

Makes the bot join a given channel. `channel` *must* start with a `#` character.

kick(nick, channel, reason)

If the bot has operator privileges in the channel `channel`, the user with `nick` will be kicked from it with the given reason <reason>.

reconnect()

Disconnects from the server then reconnects. It disconnects with the quit message "Reconnecting".

run()

Tells the bot to start listening to the messages it receives and to act upon the input using functions connected to the bindings using the command `bind()`. The bot starts listening on a new thread and so is not a blocking call. Any bot functions you wish to call must be called by functions connected to bindings (using the command `bind()`).

say(recipient, message)

The bot says the given message `message` to the recipient `recipient`. The recipient can be a channel (and should start with a `#` character if this is the case).

send(string)

Sends a raw IRC message given by `string` to the server. Can have dire consequences if your message is not formatted correctly. It is advised that you consult the IRC specification in RFC 1459.

stop()

Stops the IRC bot from running. You should disconnect from the server first. The bot's thread will terminate naturally. Should you wish to use the bot's thread `join()` function, `stop()` should be called first.

topic(channel, message)

The bot sets the topic in `channel` to `message`, if it has sufficient privileges.

unban(banMask, channel)

Unbans previously banned users satistfying the ban mask `banMask` from `channel`. Only works if the bot has operator privileges in `channel`.
8 changes: 4 additions & 4 deletions examplebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def privmsg(sender, headers, message):
if sender == owner:
bot.identify(sender, kickSuccess, (message[6:firstSpace], message[firstSpace+1:secondSpace], message[secondSpace+1:]), authFailure, (headers[0], sender))
else:
print "PRIVMSG: \"" + message + "\""
print("PRIVMSG: \"" + message + "\"")

def actionmsg(sender, headers, message):
print "An ACTION message was sent by " + sender + " with the headers " + str(headers) + ". It says: \"" + sender + " " + message + "\""
print("An ACTION message was sent by " + sender + " with the headers " + str(headers) + ". It says: \"" + sender + " " + message + "\"")

def endMOTD(sender, headers, message):
bot.joinchan(chanName)
Expand Down Expand Up @@ -76,10 +76,10 @@ def endMOTD(sender, headers, message):
bot.start()
inputStr = ""
while inputStr != "stop":
inputStr = raw_input()
inputStr = input()
bot.stop()
bot.join()
else:
print "Usage: python examplebot.py <server> <port> <your IRC nick> <irc channel (no '#' character please)>"
print("Usage: python examplebot.py <server> <port> <your IRC nick> <irc channel (no '#' character please)>")


Loading