Skip to content

Instantly share code, notes, and snippets.

/bot Secret

Created March 11, 2015 09:54
Show Gist options
  • Save anonymous/a35e580bc3fef09de8e0 to your computer and use it in GitHub Desktop.
Save anonymous/a35e580bc3fef09de8e0 to your computer and use it in GitHub Desktop.
require 'cinch'
require 'json'
require 'net/http'
class TodayILearned
include Cinch::Plugin
match "learn"
def execute(m)
uri = URI('http://www.reddit.com/r/todayilearned/new/.json')
source = Net::HTTP.get(uri)
parsed = JSON.parse(source)
title = parsed['data']['children'][0]['data']['title']
url = parsed['data']['children'][0]['data']['url']
time_posted = parsed['data']['children'][0]['data']['created_utc']
last_update = nil
if last_update == nil
last_update = time_posted
end
if time_posted > last_update
m.reply("#{title} (#{url})")
else
m.rpely("No new posts has been found.")
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.nick = "TodayILearned"
c.server = "irc.freenode.net"
c.channels = ["#intosec", "#intosec-test"]
c.plugins.plugins = [TodayILearned]
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment