summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-03-07 23:28:29 +0100
committerAlex Legler <alex@a3li.li>2015-03-07 23:28:29 +0100
commitd9683751a0eadfa6e7b3736d361a29acedfa3a57 (patch)
tree9f3656e2fcad6ad95fc39f61d4c8bb93aae75c52
downloadudp2irc-d9683751a0eadfa6e7b3736d361a29acedfa3a57.tar.gz
udp2irc-d9683751a0eadfa6e7b3736d361a29acedfa3a57.tar.bz2
udp2irc-d9683751a0eadfa6e7b3736d361a29acedfa3a57.zip
Initial commit
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock10
-rw-r--r--config.rb.default11
-rw-r--r--plugins/message.rb30
-rw-r--r--test.rb5
-rw-r--r--udp2irc.rb21
6 files changed, 80 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..f8273df
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem 'cinch' \ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..8171164
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,10 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ cinch (2.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ cinch
diff --git a/config.rb.default b/config.rb.default
new file mode 100644
index 0000000..f2a8716
--- /dev/null
+++ b/config.rb.default
@@ -0,0 +1,11 @@
+IRC_SERVER = 'irc.freenode.org'
+IRC_CHANNEL = '#gentoo-test'
+IRC_NICK = 'udp2irc'
+IRC_USER = 'udp2irc'
+IRC_PASS = ''
+IRC_REALNAME = 'Gentoo bot!'
+
+INGEST_PORT = 10010
+INGEST_ADDR = '0.0.0.0'
+
+FILTERS = [] \ No newline at end of file
diff --git a/plugins/message.rb b/plugins/message.rb
new file mode 100644
index 0000000..22b6491
--- /dev/null
+++ b/plugins/message.rb
@@ -0,0 +1,30 @@
+require 'socket'
+
+class Listener
+ def initialize(bot)
+ @bot = bot
+ end
+
+ def start
+ @server = UDPSocket.new
+ @server.bind(INGEST_ADDR, INGEST_PORT)
+
+ while true do
+ msg, sender = @server.recvfrom(1024)
+ @bot.handlers.dispatch(:udpmessage, nil, msg)
+ end
+ end
+end
+
+class MessagePlugin
+ include Cinch::Plugin
+
+ listen_to :udpmessage
+ def listen(m, message)
+ FILTERS.each do |filter|
+ return if message.match filter
+ end
+
+ Channel(IRC_CHANNEL).send message
+ end
+end \ No newline at end of file
diff --git a/test.rb b/test.rb
new file mode 100644
index 0000000..706e746
--- /dev/null
+++ b/test.rb
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+require 'socket'
+
+sock = UDPSocket.new
+sock.send "Foo/de]] xyz", 0, "127.0.0.1", 51666
diff --git a/udp2irc.rb b/udp2irc.rb
new file mode 100644
index 0000000..e697fed
--- /dev/null
+++ b/udp2irc.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require 'cinch'
+require_relative 'plugins/wiki'
+require_relative 'config'
+
+bot = Cinch::Bot.new do
+ loggers.level = :warn
+ configure do |c|
+ c.server = IRC_SERVER
+ c.channels = [IRC_CHANNEL]
+ c.nick = IRC_NICK
+ c.user = IRC_USER
+ c.password = IRC_PASS
+ c.realname = IRC_RELNAME
+ c.plugins.plugins = [WikiPlugin]
+ end
+end
+
+Thread.new { Listener.new(bot).start }
+bot.start