Erlang IRC bot for #hspbp @ IRCnet


List of components

Name PurposeSource code
Erlang IRC botIRC connectivity, plugin managementGitHub repo
Topic generatorGenerate channel topicGitHub repo
G3mailsGet Google Groups mailsGitHub repo
AtomizerParse Atom feedsGitHub repo
ErlsomParse XML documentsSourceforge
GitHub moduleReacts to GitHub URLsGitHub gist
Erlang RFC4627Parses JSONGitHub repo
Leet module (inactive)Announces leet time 13:37GitHub gist

Information flow between components


Component: Erlang IRC bot


The erlang IRC bot is responsible for communication with the IRC server. It manages the lifecycle of the plugins by starting them after the connection is established, and sends them a quit message, when the bot is about to shut down. The bot handles only the core IRC-related functionality, such as startup, responding to keep-alive messages (PING) from the server, and shutting down when receiving the appropriate command from an authorized source.

Plugin lifecycle

After startup the bot iterates through the list of plugins and initializes them via their ircmain function. It passes them a Pid and a list of plugin-specific parameters supplied by the user. This Pid can be used to interact with the IRC connection, such as sending channel messages or chaning the topic. The ircmain function returns a Pid, to which the bot sends a quit message when the bot is about to shut down.

Messages exchanged between the plugin and the bot

quitbotpluginto signal the plugin that it must stop functioning because of being killed or the bot is about to shut down (note: there is no guarantee, that the IRC connection is alive even in case of immediate reception)
{announce, Msg}pluginbotto send the message contained in the string Msg to the channel
{topic, Topic}pluginbotto change the topic to the value of string Topic
{raw, Data}pluginbotsend Data directly to the IRC server
{subscribe, Pid}pluginbotsubscribes Pid to be notified of every incoming TCP data
{incoming, Data}botpluginnotifies a subscribed plugin about incoming TCP data in Data
{getmods, Pid}pluginbotrequests the list of module PIDs to be sent to Pid
{mods, List}botplugincontains a list of currently loaded module PIDs in List
{killmod, ModPid, RespPid}pluginbotkill the module identified by ModPid and notify RespPid of the result
{killmod, Msg}botpluginnotifies the plugin about the result of a killmod message in a textual format in Msg
{insmod, ModName, Params, Pid}pluginbotload the module identified by ModName, start it with the parameter list in Params, and notify Pid of the result
{insmod, Msg}botpluginnotifies the plugin about the result of an insmod message in a textual format in Msg

Component: Topic generator


The topic generator is responsible for generating the channel topic based on the state of HackSense and the hsbp.org wiki. After startup, it spawns a process, which monitors the aforementioned sources, and if any of them changes, it constructs the topic (only if both of them returned valid information at least once), and send it in a topic message to the bot. The plugin exits from this loop when it receives a quit message.

HackSense monitoring

The hacksense module handles the extraction of data from the HackSense REST API, and parses the state information in CSV format. This module is also responsible for converting it into a human-readable string format.

hsbp.org wiki monitoring

The event module handles the extraction of data from the hsbp.org wiki via a Python script. Python was selected for this sole task, because the BeautifulSoup module could easily parse invalid markups as well. Later, the BS parser was replaced with LXML because of its performance, simplicity and "well-maintainedness". The event.py script returns the next event via standard output, which is read in the event module already in a convenient string format. If something goes wrong in the Python script, the following things can happen:

  • If the problem occured inside the Python script, nothing is written to the standard output.
  • If the problem occured before the Python script even started, the standard output remains silent, because the standard error is redirected to /dev/null.

Because of these circumstances, the string will be non-empty if and only if the Python script ran and parsed the events successfully.

Fault tolerance

Both the HackSense and hsbp.org wiki queries are done in separate processes, so if anything goes wrong, it doesn't affect the bot nor the plugin.
Contributors to this page: dnet .
Page last modified on Saturday 13 of August, 2011 16:48:15 CEST by dnet.

Upcoming Events

1)  Tue 30 of May, 2017 19:00 CEST
2)  Tue 06 of Jun, 2017 19:00 CEST
3)  Tue 13 of Jun, 2017 19:00 CEST