Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5cba00e9e6
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (41 sloc) 1.317 kb
* (c) 2010 Anastasia Gornostaeva <>
open Hooks
open Plugin_command
let encode str =
let buf = Buffer.create (String.length str) in
String.iter (function
| '\032'..'\126' as ch -> Buffer.add_char buf ch
| ch -> Buffer.add_string buf
(Printf.sprintf "\\x%02X" (Char.code ch))
) str;
Buffer.contents buf
let bf xmpp env kind jid_from text =
if text = "" then
env.env_message xmpp kind jid_from "brain fuck!"
let code = Xml.decode text in
let getchar () = int_of_char '.' in
let buf = Buffer.create 1023 in
let putchar ch = Buffer.add_char buf (Char.chr (ch land 0xFF)) in
let f () =
Brainfuck.execute code putchar getchar;
let result = Buffer.contents buf in
if result <> "" then
env.env_message xmpp kind jid_from (encode (encode result))
| Brainfuck.Error msg ->
env.env_message xmpp kind jid_from msg
| exn ->
env.env_message xmpp kind jid_from (Printexc.to_string exn)
ignore (Thread.create f ())
let plugin opts =
(fun _opts xmpp ->
add_commands xmpp [("bf", bf)] opts
let _ =
Plugin.add_plugin "brainfuck" plugin
Jump to Line
Something went wrong with that request. Please try again.