Giter Site home page Giter Site logo

horgh / twitter-tcl Goto Github PK

View Code? Open in Web Editor NEW
57.0 15.0 17.0 210 KB

An Eggdrop Tcl script that acts as a Twitter client/bridge on IRC. Also includes an OAuth library for authenticating with Twitter, and a Twitter client library.

License: GNU Affero General Public License v3.0

Tcl 100.00%
twitter irc eggdrop chat tcl bot twitter-library tweets oauth twitter-client

twitter-tcl's Introduction

twitter-tcl

This project provides an Eggdrop bot script to show tweets in IRC channels. You can also do things like tweet from IRC.

The repository contains libraries that are useful independently as well.

The scripts/libraries in this repository are:

  • twitoauth.tcl - A library to integrate with Twitter's OAuth.
  • twitlib.tcl - A Twitter API client library.
  • twitter.tcl - An Eggdrop IRC bot client/gateway script. You can use this to output Twitter home/mentions timeline statuses to IRC channels. You can also do things like tweet from IRC and follow/unfollow users.

Requirements

  • Eggdrop
  • tcllib
  • Tcl (8.5+)

Setup

  • Load twitoauth.tcl, twitlib.tcl, and twitter.tcl on to your bot. You should ensure they load in this order as the first two are libraries that the last depends on. Like other Eggdrop scripts, you can place them in a scripts subdirectory, and source them as usual in your configuration file.
  • Review the variables at the top of twitlib.tcl and twitter.tcl. You can change the options there if you like. The defaults are probably okay.
  • Copy twitter.conf.sample to your bot's directory root and name it twitter.conf. You don't need to change anything in this file. The bot updates it in some cases.
  • Register for a consumer key/secret at apps.twitter.com by creating an application. This is used for authentication with Twitter.
  • Make sure your Twitter application is set to have Read and Write permission. If it isn't then you will not be able to do things like follow people or tweet. There is a 3rd permission level where you can access direct messages, so if you want to be able to do that, you should enable that too. The permission settings are under the application's Permissions tab (at the time of writing).
  • Find your Twitter consumer key (API key) and consumer secret (API secret) for the application you registered. At the time of writing, this is under the Keys and Access Tokens tab for your application.
  • .chanset #channel +twitter to provide access to !commands in #channel. These channels also receive status update output. You issue this command in the Eggdrop's partyline which you can reach either through telnet or DCC chat. How you get on to the partyline depends on your configuration.
  • Say !twit_request_token in a channel you set +twitter. You will be given instructions on what to do after (calling !twit_access_token, etc). The bot should respond to you in the channel. If it does not, confirm the channel is +twitter and that it recognizes you as a +o user.

Options

There are more options than these. Refer to the header section of the scripts to see what else is available.

  • The script stores state (authentication keys, seen tweets, etc) in the file defined by the $state_file variable. This file is relative to the Eggdrop root directory. You can set it to any path.
  • The default time between tweet fetches is 10 minutes. You can alter the $update_time option to change this.

IRC channel commands

  • !twit / !tweet - Send a tweet
  • !twit_msg - Send a private message
  • !twit_trends - Look up trending hashtags
  • !follow - Follow an account
  • !unfollow - Unfollow an account
  • !twit_updates - Retrieve the most recent status updates
  • !twit_msgs - Retrieve direct messages
  • !twit_search - Search tweets
  • !twit_searchusers - Search users
  • !twit_get_tweet - Retrieve a particular tweet (by ID)
  • !followers - Show followers of a specified account (limited by the option followers_limit)
  • !following - Show who the specified account is following (limited by the option followers_limit)
  • !retweet - Retweet
  • !twitstatus - Show bot's Twitter status. Currently this shows its screen name.
  • !twit_request_token <consumer_key> <consumer_secret>
    • Initiate authentication. This is step one of the authentication process.
  • !twit_access_token <oauth_token> <oauth_token_secret> <PIN from authentication url of !twit_request_token>
    • Complete authentication. This is step two of the authentication process.

FAQ

  • How do I control what channels the bot shows tweets in?
    • You can set multiple channels that the bot outputs and accepts commands on by setting each channel .chanset #channel +twitter.
    • If you want to show tweets from particular accounts you show in particular channels, you can create a twitter.conf to map screen names to channels. There is an example in twitter.conf.sample.
  • Why isn't the bot responding to !commands?
    • First make sure the channel is set +twitter.
    • If it is, then you may not be recognized as +o by the bot. Many commands require that the bot recognizes you as +o. This is not the same as having operator status in the channel having operator status in the channel. It means you must be recognized as a user with +o permission by the bot in its user records.
  • Why do I see the error Update retrieval (mentions) failed: OAuth not initialised. in the bot's partyline?
    • This means you need to complete the OAuth authentication. To do this, see the setup points above. TL;DR: Issue !twit_request_token in a channel set +twitter. The bot should answer you.
  • Why do no status updates show?
    • Ensure that poll_home_timeline at the top of twitter.tcl is set to 1. This is the default.
  • How do I change the Twitter account used by the bot?
    • Call !twit_request_token again. This restarts the authentication process. Make sure you are logged into Twitter on the account you want and visit the authentication URL (or login to the account you want at this URL) and do !twit_access_token as when you initially set up the bot.
  • Why do I see errors like "Read-only application cannot POST" when trying to tweet or follow?
    • This means your bot's credentials do not have write permission. Ensure that the application you set up for the bot is set to have read and write permissions. Also ensure that the key and secret you use in !twit_request_token match after checking/updating the write permission. You should start over from !twit_request_token.

twitter-tcl's People

Contributors

bogenpirat avatar dereckson avatar horgh avatar jhobbs avatar vikyboss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-tcl's Issues

Error: Incorrect number of arguments

Hi, the tcl was working great. I had to rebuilt the vps, and then, one same eggdrop version that it was, same box, I always get in DCC:
<(s)twitter> [21:10:00] Update retrieval (home) failed: Incorrect number of arguments, must be an even number.

Or on chan:
!tweet boo
Tweet failed! (boo) Error: Incorrect number of arguments, must be an even number..
!twit_request_token (consumer key) (consumer secret)
Error: Incorrect number of arguments, must be an even number.

multiple oauth

I recently had twitter-tcl working great then it stopped making automatic posts in chans (possibly due to update interval being 1min and twitter blocked me?)
i made a new twitter app (deleted the original which was having problems) with new oauth details and still have the same problem..Any ideas how I can get this up and running again? I can manually !trigger the bot to msg tweets but the automatic (polling?) side has stopped for me..
Would love if I could find you on irc to talk? 👍
Love your work..

trying to fix cropped retweets

Let me preface this by saying that I both a) don't know how to program for beans and b) know zero TCL, so pardon my mess if I really tore this up in a bad way. Also apologies if I start mangling the terminology here. This is by no means a real patch since it's not 100% functional, plus I wouldn't know how to submit it properly through github anyway. :)

I was noticing that longer retweets were getting cropped and looked into it, and it seems that the $text in the initial dictionary is cropped to 140 chars, which includes the "RT @username" preamble and can preemptively shorten retweets. This is evidenced whenever the tweet ends with the "…".

So I dug around a bit and found that the full text of the retweet is found within a nested dictionary, retweeted_status, which only exists if you do an API call on an actual retweet (like https://api.twitter.com/1/statuses/user_timeline.json?user_id=60817704&count=1&include_rts=true). Unfortunately I couldn't discover any clean way to use "dict" to validate the existence or non-existence of the presence of retweeted_status (this post https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.tcl/KoH-qTvwy0s saved me a lot of heartache because dict exists was not at all doing what I'd have expected it to do) so I went a rougher route and just settled for regexp'ing the initial $text.

Additionally, I then created a new proc for retweets since they needed more manual construction since there's no real clean way to pull the whole RT @username bit out of the $text in retweeted_status, and you kind of have to build it yourself, I think.

Anywho, I added:

proc twitter::output_retweet {chan name rtname id str} {
    set out "\002$name\002: RT @$rtname: $str"
    if {$twitter::show_tweetid} {
        append out " ($id)"
    }
    twitter::output $chan $out
}

under the existing output_update proc.

In proc twitter::updates I replaced:

twitter::output_update $chan [dict get $user screen_name] $id $text

with:

if {[regexp {^RT @*} $text]} {
    twitter::output_retweet $chan [dict get $user screen_name] [dict get $retweeted_status user screen_name] $id [dict get $retweeted_status text]
} else {
    twitter::output_update $chan [dict get $user screen_name] $id $text
}

and in proc twitter::update I replaced:

twitter::output_update $ch [dict get $user screen_name] $id $text

with:

if {[regexp {^RT @*} $text]} {
    twitter::output_retweet $ch [dict get $user screen_name] [dict get $retweeted_status user screen_name] $id [dict get $retweeted_status text]
} else {
    twitter::output_update $ch [dict get $user screen_name] $id $text
}

Unfortunately, this is where I've hit the wall of my limited ability. The regexp is breakable by an empty retweet (ie, if someone just tweets RT @sondso stuff, without it actually being a real retweet) which effectively freezes the script in place since it can't parse that tweet to move on to the next.

I'm at a loss trying to figure out a more legitimate way to validate the dictionaries in the "if" expressions in order to figure out if "$retweeted_status text" is actually available to call with dict get. Using "dict" itself looks kind of like a dead end since either the target has to exist or it just throws an error, but the hacky regexp also isn't any good since it's breakable.

Sorry for inventing more problems, but if you've got some spare time and some ideas, that'd be super. :)

same error on all triggers

Im getting the following error when trying to fetch trends followers and following Tcl error [::keyword::pubm]: invalid command name "isnumber".

The only thing working correctly is the tweets from people im following. Any help with this error would be appreciated thank you. Also have tweet function working so just the two errors.

Also getting this error
Tcl error [twitter::followers]: list element in quotes followed by ":[{"code":37,"messag" instead of space

Tweet format in #channel

Not an issue, but a request please.
How can I set the format output of each tweet posted in the channel to show the tweet handle (@user) to show up in bold as is shows better in-channel rather than a bland unformatted plain text all the way.

Example:

@nasa: Earth isn't the only place with rivers, lakes & seas. Saturn’s moon Titan has them, too — not of water, but liquid methane & ethane! This frigid world even hides a liquid water ocean deep beneath its surface.

Something like above...

extended tweet mode

I noticed that during retweets, they are truncated, and you even have some code in there to detect it when 'retweeted_status' is in the JSON response and prepend 'RT @name:' to the tweet output. Twitter added the ability to provide 'tweet_mode=extended' in the GET request, which gives a full_text value instead of the usual text value containing the tweet itself, but I'm running into some weirdness that I don't fully understand and hope maybe you can help. I'm more of a sysadmin than a programmer and don't do any coding, but if I stare at some code and look at the logic long enough I can start to get an idea of what's going on, but this eludes me.

Despite adding 'tweet_mode=extended' to the GET request and changing text to full_text in various areas of twitlib.tcl and twitter.tcl, I seem to still be getting a shorter version of the actual tweet, at least while I've been testing using !twit_updates until a new retweet comes along from someone I'm following.

I'm using the following recent retweet as a baseline for my testing: https://twitter.com/ThoughtsOnCyber/status/911697583525023746

I used Twitter's API console to get the extended and nonextended responses, which I've pastebinned below:
nonextended: https://pastebin.com/cxF0K92P
extended: https://pastebin.com/61uDdetZ

What's weird is that in both responses there are two text values and two full_text values. The first text value in the nonextended response is shorter than the actual retweet, despite having a truncated value of false. The second text value in the nonextended response is truncated as expected with the addition of the unicode ellipses.

For the extended response, the first full_text value is the same shortened value provided by the nonextended response, however the second full_text value in the extended response is the expected entirety of the retweet without any truncation, however I am supplied still with the first shortened value by your script, and I don't understand why. What am I missing?

I've pastebinned the files as I've modified them as well (I made a few other personal tweaks like changing the trigger and formatting of output_update to give the tweet URL):
twitlib.tcl: https://pastebin.com/ZPEnhfQw
twitter.tcl: https://pastebin.com/K0wWfSXT

It is worth noting that before I made any changes to get the extended response, the automatic announcement of the tweet (::twitlib::get_unseen_updates) gave me the actual truncated version with ellipses, while doing !twit_updates gave me the first shorter text value (the one with truncated:false in the nonextended response).

Tcl error [::twitter::status]: Incorrect number of arguments, must be an even number.

After upgrading from Debian 9 to Debian 11, I suppose Tcl was updated and now our eggdrop is no longer able to fetch tweets. The log file gives us this:

[13:44:15] Update retrieval (home) failed: Incorrect number of arguments, must be an even number.
[13:49:53] Last message repeated 5 time(s).
[13:49:53] Tcl error [::twitter::status]: Incorrect number of arguments, must be an even number.

I understand if you don't have time for a patch but if you could point me in the right direction, I can probably write one. Thank you. 👍🏻

Update retrieval (home) failed: Unsupported URL type "https"

I am getting this when I have other tcl scripts i believe that use the http package?

Update retrieval (home) failed: Unsupported URL type "https"

Is there a way to avoid this problem while using other script.
If I disable twitter script and enable weather & google sepparte scripts, this problem does not arise.

Direct messages not working

I have API access set for DMs but whenever I try to do it I get a HTTP 404 error:

Message to venatiodecorus failed (OAuth HTTP request failure: HTTP 404: {"errors":[{"code":34,"message":"Sorry, that page does not exist."}]})! Are they following you?

Install Guide

I already have eggdrop setup and need a little hand holding on installing. I already have the required twitter aouth keys.

Stopped Working

Hello, I have noticed over the last couple of days the bot had stopped announcing tweets. When I logged into the telnet every time the script goes to check for new tweets it shows an error of:

[17:55:00] Update retrieval (home) failed: Incorrect number of arguments, must be an even number.

I assume something has changed on twitters end, any help would be appreciated.

tweet urls

I have noticed that some tweets that are displayed are have most of the url missing?

eg. +Twitter> johnkobani99: RT @Truth2Pwer: @AngelaLoRosso @bebird where I think possibilities could lead. Area between Efrin and Kobane will be a 4 way struggle http:…

  • This looks to have the URL cut off

+Twitter> IRCUndernetOrg: RT @herszenhorn: Shortly after start of Minsk ceasefire, at midnight in east #Ukraine, initial reports are of quiet in #Debaltseve, #Donets…

  • This looks to be missing the end of the tweet?

Is the bot limiting the length of each message it displays and can this be increased or removed?
Looks like this could be related to Issue #8 Was there any progress with this?

Thanks

Oauth FAILED ()

Hello Oauth is not working for me anymore, well in one word i can't get the request_token, even if i`ve recreated the APP permissions, even created a new API, nothing works ...
I get:
Error: OAuth failure: (code: )

Update Intervals of 5 and 10 Minutes Prevent Periodic Updates

On Eggdrop 1.6.21, the "update" function will not fire if an update interval of 5 or 10 minutes is specified either in the script configuration or by !update_interval.

The issue appears to be isolated to line 135 of twitter.tcl where the "bind time" command is issued. The use of the '/' character is not valid for eggdrop 1.6 and therefore a 5 or 10 minute update interval never gets properly scheduled. An earlier version of this code seems to be more functional.

oauth not working anymore

It's impossible to use oauth. Twitter changed the address for request_token to https. I tried to change the url in oauth.tcl to https for request_token_url, but it didn't work.
namespace eval oauth {
variable request_token_url http://api.twitter.com/oauth/request_token
variable authorize_url https://api.twitter.com/oauth/authorize
variable access_token_url http://api.twitter.com/oauth/access_token

# timeout for http requests (ms)
variable timeout 60000

}

If I use: !twit_request_token
It gives the following error on the partyline:
[12:08:00] Twitter is busy. (error: can't read "twitter::oauth_token": no such variable)

Update retrieval (home) failed: OAuth HTTP request failure: HTTP 401

Getting this error looping round in telnet console for my eggdrop:
Update retrieval (home) failed: OAuth HTTP request failure: HTTP 401: {"errors":[{"code":32,"message":"Could not authenticate you."}]}

Have checked on Twitter deleveloper, under my Project section amd see under my App details that my project is flagged as "SUSPENDED" with following message:
"Update retrieval (home) failed: OAuth HTTP request failure: HTTP 401: {"errors":[{"code":32,"message":"Could not authenticate you."}]}"

Been using this twitter developer app with very little down time over the past 2.5years, but over the past few days my eggdrop failed to do any tweets from those it follows into the channel.

Have looked on twitter help center but dont see much in way to point out how to find out what the issue was or why its suspended.

Anyone else encountered this problem recently?

POST news !!!

i`v just loaded your tcl and works great now i have a question is there a way to AUTO write in IRC channels at X/Y interval of minutes/hours the !twit_updates and be able to set for example to post the last ones ? for example i am following @NASA/@space now to be able to see the last post in IRC channel i must call/give the manual command !twit_updates # , i am asking for an auto script to be able to make the bot to give the latest news/posts from twits that i Follow i dont know if you understand !! but i hope you do :P) thank you in advance !!!

can't find package dict

I have dict installed. I can run it from the console. I have TCL 8.3, 8.4 and 8.5 installed. But I'm still getting this error:

[02:12:37] Tcl error in file 'eggdrop.conf':
[02:12:37] can't find package dict
while executing
"package require dict"
invoked from within
"if {$::tcl_version < 8.5} {
package require dict
}"
(file "/usr/share/tcltk/tcllib1.12/json/json.tcl" line 11)
invoked from within
"source /usr/share/tcltk/tcllib1.12/json/json.tcl"
("package ifneeded" script)
invoked from within
"package require json"
(file "scripts/twitter.tcl" line 82)
invoked from within
"source scripts/twitter.tcl"
(file "eggdrop.conf" line 1343)
[02:12:37] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)

Update retrieval (home) failed

[20:47:00] Update retrieval (home) failed: OAuth failure: (code: 429) {"errors":[{"message":"Rate limit exceeded","code":88}]}

V2

This ueful project needs to be upgraded from v1.1 to v2.

Home Timeline being sent as POST, not GET

Change line #279 from
if {[catch {twitter::query $twitter::home_url [list count $argv]} result]} {
to
if {[catch {twitter::query $twitter::home_url [list count $argv] GET} result]} {

and line #487 from
if {[catch {twitter::query $twitter::home_url [list since_id $twitter::last_id count $twitter::max_updates]} result]} {
to
if {[catch {twitter::query $twitter::home_url [list since_id $twitter::last_id count $twitter::max_updates] GET} result]} {

Enhanced feature

Have !follow <screen_name> <#channel,etc> written to twitter.conf

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.