Permalink
Browse files

Merge branch 'feature/ruby' of git://github.com/wilkie/XOmBot into ruby

Conflicts:
	XOmBot.pl
  • Loading branch information...
2 parents 33f7ec4 + a4083f5 commit fdcd7978d4616806251b2ee6e7ffb5fb22396cb8 @LindseyB LindseyB committed Mar 14, 2012
View
@@ -0,0 +1,2 @@
+config/config.yml
+*.rbc
View
@@ -0,0 +1,3 @@
+source :rubygems
+gem "cinch"
+gem "mechanize"
View
@@ -0,0 +1,28 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ cinch (1.1.3)
+ domain_name (0.5.2)
+ unf (~> 0.0.3)
+ mechanize (2.1.1)
+ domain_name (~> 0.5, >= 0.5.1)
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
+ net-http-persistent (~> 2.4, >= 2.4.1)
+ nokogiri (~> 1.4)
+ ntlm-http (~> 0.1, >= 0.1.1)
+ webrobots (~> 0.0, >= 0.0.9)
+ net-http-digest_auth (1.2)
+ net-http-persistent (2.4.1)
+ nokogiri (1.5.0)
+ ntlm-http (0.1.1)
+ unf (0.0.4)
+ unf_ext
+ unf_ext (0.0.4)
+ webrobots (0.0.13)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ cinch
+ mechanize
View
@@ -1,29 +1,21 @@
= XOmBot
----
-XOmBot is a simple IRC bot written in perl meant to lurk in #xomb.
+XOmBot is a simple IRC bot written in ruby meant to lurk in #xomb.
Right now XOmBot accepts the following commands:
-* !wiki [article name]: will attempt to find a XOmB wiki article of that name and provide a definition
-* !latest: will provide information for the latest commit
-* !commands: will list the commands XOmBot listens for and what they do
-* !google [phrase] for [nick]: Sends a lmgtfy.com link to nick
+* !commands: will list the commands XOmBot listens for
+* !help [command]: queries what a command will do
+* !google [phrase] for [nick]: Sends a lmgtfy.com link to nick
* !coinflip: flips a coin
* !santa: Asks Santa if the bot has been naught or nice
-* !d[n]: rolls a die with n sides
+* !d[n]: rolls a die with n sides
+* !roll [n]d[n][[+|-]n]: rolls several dice with bonuses
+* !joke: hear a funny joke
+* !answer: get the answer to the last funny joke
XOmBot has the following behaviours in addition to the commands:
-* announces an applied commit to the main XOmB repo
-* informs the channel of the !commands command upon entering a channel
* says "brains..." when directly refered to (ie: XOmBot: message)
+* responds dumbly to social cues
* displays the title of any valid http:// urls displayed in the channel
-
-----
-
-Requires:
-
-* Bot::BasicBot
-* URI::Title
-* URI::Find::Simple
-
View
268 XOmBot.pl
@@ -1,268 +0,0 @@
-#!/usr/bin/perl -w
-
-#################################################################################
-# XomBot.pl [nick] #
-# #
-# Your friendly XOmB bot for #xomb #
-# #
-# This program is free software. It comes without any warranty, to the extent #
-# permitted by applicable law. You can redistribute it and/or modify it under #
-# the term of the Do What The Fuck You Want To Public License, Version 2, as #
-# published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more #
-# details #
-# #
-#################################################################################
-
-package Bot;
-use base qw(Bot::BasicBot);
-use warnings;
-use strict;
-use URI::Title qw( title );
-use URI::Find::Simple qw( list_uris );
-use LWP 5.64;
-
-my($businessChannel) = '#xomb';
-my($pleasureChannel) = '##l2l';
-my $mynick = shift || 'XOmBot';
-my $browser = LWP::UserAgent->new;
-my $commitid = "";
-my $first = 1;
-
-my $good = 0;
-my $bad = 0;
-
-my ($bot) = Bot->new(
- server => "irc.freenode.net",
- port => "8001",
- channels => [ $businessChannel, $pleasureChannel , "##IwantAkitty", "#rstatus", "#osgcc", "#croc"],
- nick => $mynick,
- charset => 'utf-8',
- );
-
-$bot->run();
-
-sub connected {
- my $self = shift;
- $self->say(channel => $_, body => "$mynick is online. !commands will show what I can do.") for (@{$self->{channels}});
-}
-
-sub tick {
- #check_rss();
- return 60;
-}
-
-sub said {
- my $self = shift;
- my $message = shift;
- my $body = $message->{body};
- my $nick = $message->{who};
- my $channel = $message->{channel};
- my $address = $message->{address};
-
- # --- url announce ---
- if(my @urls = list_uris($body)){
- if($nick ne "github-xombot"){
- $self->reply($message, title($_)) for (@urls);
- }
- }
-
- # --- command list ---
- if($body =~ m/^\!commands/ || $body =~ m/^\!h.lp/i){
- # show all the commands that xombot listens to
- $self->say(channel => $channel, body => "!wiki [search term] - will search the wiki for the given word or phrase.");
- $self->say(channel => $channel, body => "!latest - will show the last commit to the offical XOmB repository.");
- $self->say(channel => $channel, body => "!google [phrase] for [nick] - answer questions. More bangs to shoot from the hip.");
- $self->say(channel => $channel, body => "!coinflip - ...");
- $self->say(channel => $channel, body => "!santa - ask Santa whether $mynick has been naughty or nice.");
- $self->say(channel => $channel, body => "!d[n] - rolls die with n sides");
- }
-
- if ($body =~ m/^\!wiki\s*([\w*\s]*)/){
- # check if article exists in the wiki
- get_wiki_entry($1, $channel);
- }
-
- if($body =~ m/^\!latest/){
- # show the latest commit the next loop around
- $commitid = "";
- }
-
- if($body =~ m/^\!(!*)google(!*) (.*) for (.*)/){
- my($term) = $3;
- my($target) = $4;
- my($lucky);
-
- if($1 ne "" || $2 ne ""){
- $lucky = "&l=1";
- }
-
- $term =~ s/ /+/g;
-
- $self->say(channel => $channel, who => $target, address => "1", body => "http://lmgtfy.com/?q=$term$lucky");
- }
-
- if($body =~ m/^\!coinflip/){
- my $outcome;
-
- if($body =~ m/^\!coinflip.* heads (.*) tails (.*)/){
- $outcome = $1;
- $outcome = $2 if int(rand(2)) == 1;
- }else{
- $outcome = "heads";
- $outcome = "tails" if int(rand(2)) == 1;
- }
-
- #$self->say(channel => $channel, who => $nick, address => "1", body => "$outcome");
- $self->say(channel => $channel, body => "$outcome");
- }
-
- # dice roll
- if($body =~ m/^\!d(\d+)/){
- $self->say(channel => $channel, body => int(rand($1)) + 1);
- }
-
- if($body =~ m/^\!santa/){
- if($good >= $bad){
- $self->emote(channel => $channel, body => "has been a good little robotic zombie");
- }else{
- $self->emote(channel => $channel, body => "is getting coal in its metal stocking");
- }
- }
-
- # --- miscellaneous behaviors ---
-
- # annoy duck
- if($body eq "hi" and $nick eq "duckinator"){
- $self->say(channel => $channel, who => $nick, body => "hi", address => "1");
- }
-
- my($respondedFlag) = 0;
-
- if ($address || $body =~ m/$mynick/){
- my $compliment = $body;
-
- if($compliment =~ m/good/i || $compliment =~ m/cookie/i || $compliment =~ m/<3/){
- $self->emote(channel => $channel, body => "drools");
-
- $good++;
- $respondedFlag = 1;
- }elsif($compliment =~ m/bad/i || $compliment =~ m/spank/i){
- $self->emote(channel => $channel, body => "cowers");
-
- $bad++;
- $respondedFlag = 1;
- }
- }
-
- if($address && !$respondedFlag){
- $self->say(channel => $channel, who => $nick, address => "1", body => "brains...");
- }
-
- return undef;
-}
-
-sub check_rss {
- my $response = $browser->get("http://github.com/feeds/xomboverlord/commits/xomb/unborn");
-
- if($response->is_success && $response->content =~ m/<entry>\s*<id>.*\/(\w*)<\/id>/){
- my $commiter = "Unknown";
- my $commit_msg = "Unspecified";
- my $orig_commitid = $commitid;
-
- #if it's not the last one we announced
- if($commitid ne $1){
- $commitid = $1;
-
- # get try to get the info to announce it
- if($response->content =~ m/<entry>.*?<title>(.*?)<\/title>/s){
- $commit_msg = $1;
- }
-
- # get try to get the author to announce it
- if($response->content =~ m/<name>(\w*)<\/name>/){
- $commiter = $1;
- }
-
- if($commit_msg ne "Sorry, this commit log is taking too long to generate."){
- unless($first){
- $bot->say(channel => $businessChannel, body => "Commit made by $commiter: $commit_msg");
- $bot->say(channel => $businessChannel, body => "View: http://github.com/xomboverlord/xomb/commit/$commitid");
- }else{
- $first = 0;
- }
- }else{
- # we don't know if there actually was a new commit
- $commitid = $orig_commitid;
- }
- }
- }
-}
-
-
-
-sub get_wiki_entry {
- my $articlename = shift;
- my $channel = shift;
-
- #replace spaces with +
- $articlename =~ s/\s/\+/gs;
-
- # searching for the article rather than going directly to it allows us to ignore the issue of case sensitivity
- my $response = $browser->get("http://wiki.xomb.org/index.php?search=$articlename&go=Go");
-
- #check if article exists
- my $exists = 1;
- if($response->content =~ m/There is no page titled/)
- {
- $exists = 0;
- }
-
- my $content = $response->content;
-
- # remove the html tags
- # the following line breaks syntax highlighting in intype :(
- $content =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
-
- #replace + with spaces
- $articlename =~ s/\+/ /gs;
-
- if ($response->is_success && $exists)
- {
- # try to get a definition
- if( $content =~ m/(.*?$articlename.*?\.)/i)
- {
- $bot->say(channel => $channel, body => $1);
- }
-
- #replace spaces with _
- $articlename =~ s/\s/_/gs;
-
- $bot->say(channel => $channel, body => "Full article here: " . $response->base);
- }
- else
- {
- $bot->say(channel => $channel, body => "Sorry, there's no article by that name");
- # try to search for similar articles
- search_for_article($articlename, $channel);
- }
-
-}
-
-sub search_for_article {
- my $searchterm = shift;
- my $channel = shift;
-
- # replace spaces with +
- $searchterm =~ s/\s/\+/gs;
-
- my $response = $browser->get("http://wiki.xomb.org/index.php?search=$searchterm&go=Go");
-
- if($response->is_success)
- {
- if($response->content =~ m/<li><a href="\/index\.php\?title=(\w*)/)
- {
- $bot->say(channel => $channel, body => "Did you mean $1: http://wiki.xomb.org/index.php?title=$1");
- }
- }
-
-}
View
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+$: << File.dirname(__FILE__) + '/../lib'
+
+require 'xombot'
+require 'xombot/cli'
+
+XOmBot::CLI.run
@@ -0,0 +1,5 @@
+server: irc.freenode.org
+port: 6697
+name: XOmBot-test
+channels: ["#XOmBot"]
+ssl: true
Oops, something went wrong.

0 comments on commit fdcd797

Please sign in to comment.