GithubHelp home page GithubHelp logo

fridim / cabot Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 3.0 57 KB

a simple IRC framework written in whatever you want

License: MIT License

Go 77.59% Ruby 9.11% Perl 1.47% C 7.23% Python 2.68% Shell 1.92%
irc irc-bot bot-framework bot golang

cabot's Introduction

cabot, a simple IRC framework written in whatever you want

About

This is a minimalist IRC bot written in Go as an exercice to learn the language. The core codebase (in Go) has very few features :

  • connect to a server
  • plugins:
    • run all executable files located in plugins/
    • dispatch input to all plugins located in the plugins/ directory
    • Example output of ps
3551 pts/2    Sl+    0:00  \_ ./bot -server=irc.freenode.org:6667
3558 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/register_and_join.rb
3561 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/url.rb
3566 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/date.rb
3577 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/hello.rb
3579 pts/2    Sl+    0:00      \_ plugins/ping
  • signals:
    • SIGHUP will kill and reload all plugins
    • SIGUSR1 to reconnect

I have absolutely no credit, as this program is a clone of vivien’s modulo. Have a look there!

Plugins

Everything other than the previous is done via plugins. Plugins are scripts or compiled programs in the plugins/ directory.

A plugin must:

  • be executable
  • read from STDIN
  • write to STDOUT

Example of plugins:

  • ping.go: reply to PONG from server and send SIGUSR1 to parent process if last pong is too old
  • freenode_register_join.rb: register USER and NICK and JOIN channels
  • reload plugins from IRC by just talking to your bot, plugin will SIGHUP the parent process on a specific input from registered owner.
  • whatever you want, really

Input from the IRC Socket is directly rewritten to the plugin STDIN. The STDOUT of the plugin is then pipelined back to the IRC socket. It’s that simple.

Example of helloworld in Ruby:

#!/usr/bin/ruby
STDOUT.sync = true

STDIN.each_line do |l|
  if l =~ /PRIVMSG (#\w+) :(.+)/
    channel = $1
    message = $2
    if message =~ /^hello/i
      puts "PRIVMSG #{channel} :Hello o/"
    end
  end
end

Do not forget to sync the STDOUT in your plugin otherwise, the bot will probably not reply when you imagine it would.

Getting started

Build

$ go build *.go

You will also need the ping plugin

$ cd plugins_examples/ping
$ go build ping.go
$ cp ping ../../plugins/

Minimal configuration

Everything related to IRC will be dealt with by plugins.

You will find examples of plugin in plugins_examples/ directory. For freenode, you can just edit plugins_examples/freenode_register_join.rb and set channels to join and Nickserv password in a file.

Run

$ ./bot -server=chat.freenode.net:6697 -ssl

Install dependencies

Alpine

apk add git go ruby-dev perl python3 py3-pip perl-libwww
gem install tzinfo
gem install io-console
gem install etc
pip install googletrans

cabot's People

Contributors

arsnael avatar daftaupe avatar fridim avatar sim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

daftaupe sim arsnael

cabot's Issues

Crash

!!! 2021/12/14 22:24:52 ping not received from server for 500 sec, SIGUSR1 sent to 5536
!!! 2021/12/14 22:33:12 ping not received from server for 500 sec, SIGUSR1 sent to 5536
!!! 2021/12/14 22:41:32 ping not received from server for 500 sec, SIGUSR1 sent to 5536
!!! 2021/12/14 22:49:52 ping not received from server for 500 sec, SIGUSR1 sent to 5536
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@iii 2021/12/15 06:59:32 All plugins loaded, wg: {{} [0 39 0]}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x483fb4]

goroutine 1 [running]:
bufio.(*Reader).ReadSlice(0x0, 0xa, 0x0, 0x0, 0x40, 0x79c780, 0x637340)
	/usr/lib/go/src/bufio/bufio.go:335 +0x54
bufio.(*Reader).collectFragments(0x0, 0xc00006000a, 0x2, 0xc0000780f0, 0x26, 0x0, 0x0, 0x26, 0xc0000a1eb8, 0x5e7e38, ...)
	/usr/lib/go/src/bufio/bufio.go:435 +0x7a
bufio.(*Reader).ReadString(0x0, 0x64e90a, 0xc0000566c0, 0xc00008a000, 0x0, 0x0)
	/usr/lib/go/src/bufio/bufio.go:483 +0x4c
main.main()
	/home/fridim/cabot/bot.go:183 +0x54a

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.