Loading...
 
[Show/Hide Left Column]

Erlang IRC bot for #hspbp @ IRCnet




Overview


List of components


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


Information flow between components


Image

Component: Erlang IRC bot


Overview


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


MessageFromToPurpose
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


Overview


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(external link) module could easily parse invalid markups as well. Later, the BS parser was replaced(external link) with LXML(external link) 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: dnet922 points  .
Page last modified on Saturday 13 of August, 2011 16:48:15 CEST by dnet922 points .

Upcoming events

1)  Tue 23 of Dec., 2014 19:00 CET
Plénum
2)  Thu 25 of Dec., 2014 19:00 CET
Hakk csütörtök
3)  Tue 30 of Dec., 2014 18:00 CET
config night