我正在使用'twitter'红宝石创建一个机器人,用 George Orwell 小说 1984 中的引用回复某些单词(指定可能的'巨魔'单词)宝石。目前我的代码看起来像这样:
require 'yaml'
require 'twitter'
require 'thor'
require 'httparty'
require 'colorize'
puts '\|/|\|/'.red + ' Loading anti-troll tactical auto-canon! '.blue + '\|/|\|/'.red + "\n"
trollWords = ['Satan', 'Trump tower', 'libtard', 'nihilism', 'alt-right', 'feminazi', 'genocide', 'gulag', 'trigger-warning', 'special snowflake', 'privilege', 'ugly', 'moron', 'block-list', 'nazi']
quotes = ['Perhaps one did not want to be loved so much as to be understood.', 'Who controls the past controls the future. Who controls the present controls the past.', 'War is peace. Freedom is slavery. Ignorance is strength.', 'The best books... are those that tell you what you know already.', 'If you want to keep a secret, you must also hide it from yourself.', 'If you want a picture of the future, imagine a boot stamping on a human face — forever.', 'We shall meet in the place where there is no darkness.', 'But if thought corrupts language, language can also corrupt thought.', 'Doublethink means the power of holding two contradictory beliefs in one\'s mind simultaneously, and accepting both of them.', 'Until they became conscious they will never rebel, and until after they have rebelled they cannot become conscious.', 'The Party seeks power entirely for its own sake.', 'Russian Communists came very close to us in their methods, but they never had the courage to recognize their own motives.', 'Perhaps a lunatic was simply a minority of one.', 'If you loved someone, you loved him, and when you had nothing else to give, you still gave him love.', 'In the face of pain there are no heroes.', 'Big Brother is Watching You.', 'Reality exists in the human mind, and nowhere else.', 'Orthodoxy means not thinking--not needing to think. Orthodoxy is unconsciousness.', 'Nothing was your own except the few cubic centimetres inside your skull.', 'Confession is not betrayal.', 'Sanity is not statistical.']
client = Twitter::REST::Client.new do |config|
config.consumer_key = '[key]'
config.consumer_secret = '[secret]'
config.access_token = '[token]'
config.access_token_secret = '[token secret]'
end
word = trollWords.sample
quote = quotes.sample
def output_init_string(word, quote)
puts "Troll identification word: " + word + ".\n" + "Response quote: " + quote
end
client.search(word, count: 10).each do |t|
quote = quotes.sample
word = trollWords.sample
replystring = "@" + t.user.screen_name + " " + quote
puts "Found possible troll suspect: " + t.user.screen_name + "\nTweeting: " + t.text + "\nReplied with: " + replystring + "\n"
client.update(replystring, in_reply_to_status_id: t)
sleep(300)
end
它确实有效,但是当我在回复中扩展细节时,我看不到原始的推文,只有我的机器人的回复和@ [用户]。任何人都可以告诉我如何制作它,以便原始用户的推文在详细信息展开时可见吗? 因此,例如在控制台输出中,我可以看到:
但如果我点击机器人的回复,我就会看到:
在https://twitter.com/bravebot1984/status/832328576619921413,没有任何指示回复的推文。
这个问题不是链接到问题的重复,因为我已经使用建议'回复'的方法,并且该方法确实导致了各种回复,但它在详细信息展开时没有正确显示,因为我需要它。
答案 0 :(得分:0)
in_reply_to_status_id: t
t
必须是推文的id
。您当前的值看起来像对象。试试t.id
或t["id"]
答案 1 :(得分:0)
我了解t
是Twitter::Tweet
的一个实例。您可以使用in_reply_to_status
代替in_reply_to_status_id
,例如:
client.update(replystring, in_reply_to_status: t)
请参阅:http://www.rubydoc.info/gems/twitter/Twitter/REST/Tweets#update-instance_method