EToS
{ ADMIN }
posts: 11
last: 02-Aug-2008
TITLE: Using Twitter API with Eggdrop Bot in TCL
DESCRIPTION: A simple Eggdrop twitter bot example using CURL and Twitter API
Submitted: 06-Jun-2008 11:38:14 ( 13w 2d 23h ago ) Language: TCL (*.tcl *.tk)
Views: 202 Lines of Code: 57 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 3.50 / 5 }
Difficulty: Intermediate
Bookmark
#  Author: EToS
#  Date: 30/04/2008
#  Filename: twitter.tcl
#  Function: Eggdrop interface to twitters API via Curl
#
#  Notes: Enable with .chanset #channel +twitter
#
#  History:  - added some namespace stuff
#            - added some special char fixing


# work chan flags ..
setudef flag twitter

# vars
set ::setup(trigger)   "!twitter"

set ::setup(apibase)   "http://twitter.com/"
set ::setup(apiupdate) "statuses/update.xml"
set ::setup(url)       $::setup(apibase)$::setup(apiupdate)

set ::setup(user)      "USERNAME"
set ::setup(pass)      "PASSWORD"
set ::setup(curl)      "/usr/bin/curl"

set ::setup(confirm)   "\002Success!\017 @ $::setup(apibase)$::setup(user)"

# binds
bind pub - $::setup(trigger) twitcl:twitter

############################################


proc twitcl:twitter {nick uhost handle channel text} {
  global twitcl
  set text [twitcl:mapevil $text]

  if {[catch {exec $::setup(curl) -u $::setup(user):$::setup(pass) -s -F status=$text $::setup(url)} result]} {

      putquick "PRIVMSG $channel : \002Err.. Something b0rked!\017"

  } else {

      putquick "PRIVMSG $channel : $::setup(confirm)"
  }

}


# map 'em evil chars
proc twitcl:mapevil {string} {
  global twitcl
  return [string map {\< &lt; \> &gt;} $string]
}


putlog "Script loaded: Twitter v1.1 *BeTA* \00302\002(C) 2008 EToS"