=head1 NAME

tircd  - An ircd proxy to the twitter API

=head1 DESCRIPTION

tircd presents twitter as an irc channel.  You can connect to tircd with any irc client, and twitter as if you were on irc

=head1 INSTALLATION

tircd requires a recent version of perl, and the following modules:

L<POE>

L<POE::Filter::IRCD>

L<Net::Twitter::Lite::WithAPIv1_1>

L<JSON::Any>

L<Time::Local>

L<File::Glob>

L<IO::File>

L<LWP::UserAgent>

L<Storable>

L<URI>

L<List::Util>

L<HTML::Entities>

L<Digest::SHA1>


If you're using a redhat or debian based system, attempt to use the distrobutions CPAN module packages, in yum or apt.

To install all modules via CPAN:

B<cpan -i POE POE::Filter::IRCD Net::Twitter::Lite JSON::Any Time::Local File::Glob IO::File LWP::UserAgent Storable URI List::Util HTML::Entities Digest::SHA1>

=head1 USAGE

=over

=item Running tircd

B<./tircd.pl [/path/to/tircd.cfg]>

When started, tircd will look for a configuration file in the following places:

F<tircd.cfg> (in the current directory)

F<~/.tircd>

F</etc/tircd.cfg>

You can specify an alternate path to the configuration file on the commandline if you want to keep the configuration in another location.  There is an example config provided as part of the distribution. The easiest way to get started is to just rename that file from F<tircd.cfg.example> to F<tircd.cfg>

=back

=head2 Connecting

By default, tircd listens on localhost port 6667.

The first time you connect with a new twitter account you must specify a B<tircd> password for that nick. This password does not have to (and should not) be the same as your twitter password. This password will protect your tircd account from unauthorized usage. 

B<The above password is to protect your tircd account, and is not related to your twitter account. The tircd nick password will only be saved once you have logged into Twitter>

With many irc clients you can do this by issuing the command /SERVER localhost 6667 <B<tircd> password> <B<twitter> username>. Check your client's documentation for the appropirate syntax. 

Tircd will make an OAuth challenege to Twitter, and Twitter will return a link to a page where you can authorize the connection. This link will appear in your IRC connection status window.

Make sure you are either logged into twitter as the account you plan to use, or not logged in. Click the authorize link and log-in, then click "Allow". Twitter will then present you with a PIN number. B<To complete your connection to tircd>, type: B</stats pin <PIN NUMBER>>. On some clients you may have to type: B</quote stats pin <PIN NUMBER>>. 

If the PIN is accepted by Twitter, the connection will be established. You may now join #twitter to begin. If the PIN is not accepted, another authorization link will be generated.

=over

=item Account password protection

If your tircd installation is running in a shared environment (either listening on the localhost address on a shared computer, or listening on a public IP) you might want to password protect your account, or anyone can access your twitter account knowing the server address and your twitter username.
B<Your tircd-password do NOT need to be (and should not be!) the same as your twitter password.>

Tircd supports password protection in the following way.

=over

=item * The first time you connect to tircd with a new Username, no password checking is done.  You are presented with the OAuth URL, and need to log in to twitter on the web, and enter the PIN as described above.

=item * When the PIN is accepted, IF your client connected with a password set, this password is encrypted (hashed) and saved along with your twitter access-tokens.

=item * Next time you connect, tircd will first check to see if a password is saved in your F<Username.config>, and comapre it with the one your client sends.

=item * If they match, your connecton is allowed, and tircd continue to verify the OAuth tokens with twitter.

=item * If they don't match, the client is disconnected with an error message.

=item * If you want to change your password, or did not set one on your first connection, you can do so after you have connected to tircd with a simple C<< /STATS password <password> >>

=item * Be aware that if you do this, you will also have to make sure your client uses the same password next time you connect to tircd.

=item * If you want to remove the password, simply issue a C</STATS password> without any password set.

=back

There is currently no way of regaining access to your account if you forget it.  To reset your tircd password, you will have to remove your Username.config and authorize with twitter using OAuth and a PIN again.

=back

=head2 After connecting

Once connected C</JOIN #twitter> to get started.  The channel #twitter is where you will perform most opertions

=over

=item Updating your status

To update your status on twitter, simply send a message starting with "!t " to the #twitter channel.  The server will keep your most recent update in the topic at all times.

If you want to have all message you send to #twitter posted as tweets, you can set the config option "auto_post" to 1. Either in tircd.conf or via the /stats command. Messages beginning with an exclamation point ("!") will still be processed as commands, not tweeted.

=item Getting your friend's status

When users you follow update their status, it will be sent to the channel as a message from them. Each status will be preceded by a 3 letter identifier such as [a7f]. This identifier is used for retweeting and replying to tweets.

@replies are also sent to the channel as messages.

=item Retweeting a status

To retweet a status, use the offerbot command !retweet followed by the 3 letter tweet identifier.

B<!retweet a7f>

=item Replying to a status

To reply to a status update, use the offerbot command !retweet followed by the 3 letter tweet identifier.

B<!reply 6eb @tircdbot not today! >

=item Favoriting a tweet

To favorite a tweet use the offerbot command !favorite followed by the 3 letter tweet identifier.

B<!favorite a44>

=item Listing the users you follow

Each user you follow will be in the #twitter channel.  If you follow a new user outside of tircd, that user will join the channel the first time they update their status.  People who follow you back are given voice (+v) to indicate that fact.

=item Direct Messages

Direct messages to you will show up as a private message from the user.

To send a direct message, simply send a private message to the user you want to dm.

=item Getting additional information on users

You can /WHO or /WHOIS a user to view their Location / Bio / Website. Their last status update (and time sent) will also be returned.

Issuing a /WHOIS on your own user name will also provide the number of API calls that have been used in the last hour.

=item Following new users

To begin following a new user, simply /INVITE them to #twitter.  The user will join the channel if the request to follow was successful.  If you attempt to invite a user who protects their updates, you will receive a notice that you have requested to follow them.  The user will join the channel if they accept your request and update their status.

B<!invite> is the analagous offerbot command.

=item Unfollowing / removing users

To stop following a user, /KICK them from #twitter.

B<!kick> is the analagous offerbot command.

=item Blocking users 

To block a user /BAN them.  
There is currently no way to get a list of users you've currently blocked via the API, so listing the bans in #twitter will only return users you've blocked in the current session.

=item Unblocking users

To unblock a user /UNBAN them.

=item Multiple Channels / Groups

If you want to create a channel with just a subset of the people you follow, you can C<< /JOIN <any channel> >> and then /INVITE them to the channel.  tircd will send a user's updates to #twitter and any other channels you have invited a user to.

=item Search

If you want to have updated search results for a specific term delivered, you can C<< /JOIN <any channel> >> then set the /topic for the channnel to your search query.  Results that match that query will be sent to that channel. The /TOPIC can be almost anything supported by the twitter search (see L<http://support.twitter.com/articles/71577-how-to-use-advanced-twitter-search> for exmaples).  Using the 'near' option is not currently supported.

=item User config

Certain options are changeable at runtime and set per user. To see a list of options and their current values simply send an C</STATS m> command to the server.

These options are saved in a file with the name F<Username.config> (where Username is your twitter username) located in a directory set in the global config file (default: F</tmp/tricd>)

=item Offerbot commands

Tircd supports offerbot style control. All functions available through the offerbot are available as they're metaphorically appropriate IRC functions. Therefore, retweeting, replying to a specific tweet, and saving the user configuration are B<only> available through the offerbot.

B<![update|up|refresh]> - Updates the #twitter stream immediately.

B<![tweet|t] <text of tweet>> - Posts the given text as an update to your feed.

B<![retweet|rt] <tweed-id>> - Posts a retweet. tweet-id is the 3 digit code preceding the tweet.

B<![reply|re] <tweet-id> <message text>> - Replies to a tweet. tweet-id is a the 3 digit code preceding the tweet.

B<![conversation|conv] <tweet-id>> - Replay a conversation from begining. If tweet is not a reply, shows related tweets.

B<![add|invite|follow] <username>> - Begin following the specified twitter username.

B<![remove|kick|unfollow] <username>> - Remove the username from the list of people your account follows.

B<!save> - Saves twitter-username specific configuration immediately.

B<!help> - Shows this help message.

=back

=head1 AUTHOR

Tim Sogard <tircd@timsogard.com> [2010-2011]

Ola Thoresen <olen@inni.no> [2010-2011]

Chris Nelson <cnelson@crazybrain.org>  [2009]

=head1 LICENSE

This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details.

=head1 SEE ALSO

L<POE>

L<POE::Filter::IRCD>

L<Net::Twitter::Lite>

L<JSON::Any>

L<Time::Local>

L<File::Glob>

L<IO::File>

L<LWP::UserAgent>

L<Storable>

L<URI>

L<List::Util>

L<HTML::Entities>

L<Digest::SHA1>

