Ruby 查看新推文的最佳方式

Ruby 查看新推文的最佳方式,ruby,twitter,Ruby,Twitter,这是我的irc机器人的一段代码。它所做的是检查特定帐户上的新推文,然后在频道中回复。 现在,有没有更好的方法来检查新的推文?对于我来说,在1..99999999中感觉有点不太好,ddos'y tweetzsr = {} xzsr = {} zsr = {} on :message, ".start zsr" do |m| if zsr[m.channel] == true m.reply "already doing it.." else m.reply "ok."

这是我的irc机器人的一段代码。它所做的是检查特定帐户上的新推文,然后在频道中回复。 现在,有没有更好的方法来检查新的推文?对于我来说,在1..99999999中感觉有点不太好,ddos'y

tweetzsr = {}
xzsr = {}
zsr = {}

on :message, ".start zsr" do |m|
  if zsr[m.channel] == true
    m.reply "already doing it.."
  else
    m.reply "ok."
    zsr[m.channel] = true
    for i in 1..99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
      sleep 60
      puts "#{xzsr[m.channel]} = x, tweetzsr = #{tweetzsr[m.channel]}"
      tweetzsr[m.channel] = Twitter.user_timeline("twiitterracount").first.text
      if xzsr[m.channel] == tweetzsr[m.channel]
        nil
      else
        m.reply "#{tweetzsr[m.channel]} - via twitter feed"
        xzsr[m.channel] = tweetzsr[m.channel]
      end
    end
  end
end

那是你的无限循环吗

将其更改为此以提高理智

loop do
  sleep 60
  newtweet[m.channel] = Twitter.user_timeline("twitteracount").first.text
  next if oldtweet[m.channel] == newtweet[m.channel]
  m.reply "#{newtweet[m.channel]} - via twitter"
  oldtweet[m.channel] = newtweet[m.channel]
end

您缺少两个
end
关键字。

这是您的无限循环吗

将其更改为此以提高理智

loop do
  sleep 60
  newtweet[m.channel] = Twitter.user_timeline("twitteracount").first.text
  next if oldtweet[m.channel] == newtweet[m.channel]
  m.reply "#{newtweet[m.channel]} - via twitter"
  oldtweet[m.channel] = newtweet[m.channel]
end

您缺少两个
end
关键字。

首先,对于无限循环,请使用
loop
方法

这种东西最好用。此api将向Twitter发送一个请求,然后Twitter将向您的客户端推送任何新数据。因此,有一种宝石叫做

用法示例:

TweetStream::Client.new.userstream do |status|
  m.reply "#{status.text} - via twitter"
end

首先,对于无限循环,请使用
loop
方法

这种东西最好用。此api将向Twitter发送一个请求,然后Twitter将向您的客户端推送任何新数据。因此,有一种宝石叫做

用法示例:

TweetStream::Client.new.userstream do |status|
  m.reply "#{status.text} - via twitter"
end

惯用ruby应该使用宁
loop do
然后
而true
。惯用ruby应该使用宁
loop do
然后
而true
。我在我的第一个链接中更新了代码,这是我的“推特部分”的所有代码,tweetstream可以使用吗?你的代码有点凌乱,所以我不完全确定你想做什么。在上面的示例中,每个新tweet都会调用一次块(如果您签出文档,则会有关于处理删除和错误的信息)。我想这就是你在展示的代码中要做的。我在我的第一个链接中更新了代码,这是我的“推特部分”的所有代码,tweetstream能用吗?你的代码有点凌乱,所以我不完全确定你想做什么。在上面的示例中,每个新tweet都会调用一次块(如果您签出文档,则会有关于处理删除和错误的信息)。我假设这就是您在展示的代码中试图做的事情。