Project

General

Profile

Ruby scripts

Added by Dirk Meyer almost 8 years ago

Examples how to use "ruby_script"


Replies (11)

Autovoice in a channel. - Added by Dirk Meyer almost 8 years ago

This scripts give "voice" to users in a channel who post a line with "iroffer-dinoex"

# Do not change the name of this class.
class IrofferEvent
  # called on each privms, including channel posts
  def on_privmsg
    # trigger on text anywhere in the message
    if /iroffer-dinoex/.match( message )
      msg = "Thanks for using iroffer." 
      # send text to user
      privmsg( nick, msg )
      # log a warning in the iroffer logfile
      warning( nick + " uses iroffer in " + channel + " on " + network )
      # give voice to user in channel
      mode( channel, "+v " + nick )
    end
  end
end

AUTOADD trigger - Added by Dirk Meyer almost 8 years ago

This script generates an "AUTOADD" command on the trigger "!autoadd" in the channel.

# Do not change the name of this class.
class IrofferEvent
  # called on each privms, including channel posts
  def on_privmsg
    # trigger on exact text
    if message == "!autoadd" 
      # execute admin command
      command( "msg", config[ "owner_nick" ], "!autoadd was triggered" )
      command( "autoadd" )
    end
  end
end

HOP trigger - Added by Dirk Meyer almost 8 years ago

This script will make the PART and JOIN the current channel to regain status.

# Do not change the name of this class.
class IrofferEvent
  # called on each privms, including channel posts
  def on_privmsg
    # trigger on text
    if message == "!hop" 
      # execute admin command
      command( "HOP", channel, network )
    end
  end
end

Custom ANNOUNCE message - Added by Dirk Meyer almost 8 years ago

This script will generate a custom ANNOUNCE message on AUTOADD

# Do not change the name of this class.
class IrofferEvent
  # called on each pack added
  def on_added
    group = info_pack(added_pack, "group" )
    desc = info_pack(added_pack, "desc" )
    bytes = info_pack(added_pack, "bytes" )
    megabytes = info_pack(added_pack, "size" ) # human readable
    crc = info_pack(added_pack, "crc32" )
    md5 = info_pack(added_pack, "md5sum" )
    xtime = info_pack(added_pack, "xtime" ) # added_time

    # custom announce
    text = "\"addded " 
    text << "\00304" # color red
    text << desc
    text << "\003\017" # end color
    text << " - " 
    text << megabytes.to_s
    if not group.nil?
      text << " in " 
      text << group
    end
    text << " CRC " 
    text << crc
    text << " - /MSG mybot XDCC SEND " 
    text << added_pack.to_s
    text << "\"" 
    command( "AMSG", text )
  end
end

AUTOSEND - Added by Dirk Meyer almost 8 years ago

This script will send newly added packs to other bots or users.

# Do not change the name of this class.
class IrofferEvent
  # called on each pack added
  def on_added
    # backup pack to a some other bots
    command( "BATCH", "XDCC|Archiv1", added_pack.to_s )
    command( "BATCH", "XDCC|Archiv2", added_pack.to_s )
  end
end

Create a new TRIGGER on AUTOADD - Added by Dirk Meyer almost 8 years ago

This script will generate a Trigger for new added packs.

# Do not change the name of this class.
class IrofferEvent
  # called on each pack added
  def on_added
    group = info_pack(added_pack, "group" )
    # generate a trigger for each new pack.
    command( "CHTRIGGER", added_pack.to_s, "#{group}#{added_pack}" )
  end
end

RE: Ruby scripts - Added by joe raffert over 7 years ago

I'm sorry for posting this here and will delete it once i find the answer or make even more scripts for others

im trying to figure out how to use !list command using ruby
but how to you get it to send a channel msg to only the user that request it
like the reg !list built in to iroffer
add ruby ignores "!" for some reason

psend is useless on my bot even on minimal or summary it sends 1 line then lists packs (i have over 4200 packs )

can someone list all the commands both ruby and iroffer-dinoex can use ? (other then ones in admin help file)
dose it have a command to get slots/total # packs/bandwidth ?

here is the basic idea
but when it responds every one can see it not just the person that used !list

# Do not change the name of this class.
class IrofferEvent
  # called on each privms, including channel posts
  def on_privmsg
    # trigger on text
    if "!list".match( message )    
    # custom announce
    text = "\00306" # color purpal
    text << "Just look you know you want to " 
    text << "\00311" # color cyan
    text << "[ [XDCC] over 4200 packs thats [1TB] and growing [!new, !list, @find, xdcc owner, xdcc Batch, xdcc Send #] ]" 
    text << "\00303" # color green
    text << "-[(500KBs) max (5) slots (200)Queue]" 
    text << "\00304" # color red
    text << "-[/msg A|Tech|Bot XDCC SEND #1 for pack list](Brought to you by TechMasterJoe)" 
    text << "\00306" # color purpal
    text << " Well did you look ? =iroffer-dinoex=" 
    text << "\003\017" # end color
    command( "msg", channel, text )
    end
  end
end

RE: Ruby scripts - Added by Dirk Meyer over 7 years ago

joe raffert wrote:

ruby ignores "!" for some reason

if message == "!list" 

psend is useless on my bot even on minimal or summary it sends 1 line then lists packs (i have over 4200 packs )

Then something is wrong with psend, please check.

Try:
PSEND #somechannel summary

This should output only:
  • For a listing type: "/MSG mybot XDCC LIST" **

can someone list all the commands both ruby and iroffer-dinoex can use ? (other then ones in admin help file)

see the README.modDinoex, look for entries with "ruby_script"

dose it have a command to get slots/total # packs/bandwidth ?

total slots:

   text << config[ "slotsmax" ]

total packs:

   ## very slow to get number of packs:
   found = 0
   1.upto( 10000 ) do |i|
     if info_pack(i, "bytes" ).nil?
       break
     end
     found = i
   end
   text << found

used slots and Bandwith:

  ## Gets stats from xdcclistfile
  stats = File.read( config[ "xddclistfile" ] ).split( "\n" )
  stats.each do |line|
    case line
    when /slots open/
      text << line
    when /Bandwidth/
      text << line
    end
 end

The current values of uses slots and bandwidth are not direct accessible in 3.26.

here is the basic idea
but when it responds every one can see it not just the person that used !list

replace channel with nick in the msg command:

 command( "msg", nick, text )

RE: Ruby scripts - Added by joe raffert over 7 years ago

thanks a lot you helped me more then you know
here i will share my Modded added script

# Do not change the name of this class.
class IrofferEvent
  # called on each pack added
  def on_added
    group = info_pack(added_pack, "group" )
    desc = info_pack(added_pack, "desc" )
    bytes = info_pack(added_pack, "bytes" )
    megabytes = info_pack(added_pack, "size" ) # human readable
    crc = info_pack(added_pack, "crc32" )
    md5 = info_pack(added_pack, "md5sum" )
    xtime = info_pack(added_pack, "xtime" ) # added_time

    # custom announce
    text = "\00306" # color red
    text << "\[Addded] " 
    text << "\00314" # color red
    text << " >>> " 
    text << "\00304" # color red
    text << desc
    text << "\00314" # color red
    text << " >>" 
    text << "\00305" # color red
    text << " [/msg A|Tech|bot xdcc send #1 for packlist or http://99.73.210.122:82/]" 
    text << "\003\017" # end color
    command( "AMSG", text )
    if not group.nil?
      else
      command( "autogroup" )
    end
  end
end

note it runs auto group only if it has no group witch is set to use folder in config as i have some what clean folder structure.
using only if command made a error i was not able to get around with out using else
and do to the size and number of files in my bot i cut a lot of info out (i add as much as 200 files a day)
here is what it looks like

this is my forum sig it uses the xml it get basic bot info
autoadd.rb (939 Bytes) autoadd.rb the script as seen

RE: Ruby scripts - Added by Dirk Meyer almost 7 years ago

If you want remove all files with the same name:

# Do not change the name of this class.
class IrofferEvent
  # Admin Command: RUBY rdup
  def rmdup
    seen = Hash.new
    pack = 1
    while true do
      file = info_pack(pack, "file" ).sub( /^.*\//, '' )
      if file.nil?
        break
      end
      if seen.has_key?( file )
         command( "remove", pack )
         next
      end
      seen[ file ] = true
      pack += 1
    end
  end
end

RE: Ruby scripts - Added by Dirk Meyer over 6 years ago

A trigger ".uptime" that make the bot respond via channel or /msg

# Do not change the name of this class.
class IrofferEvent
  def on_privmsg
    # trigger on on exact text
    if message == '.uptime'
      command( "msg", nick, "bot running for", irconfig( "uptime" ) )
    end
  end
end
    (1-11/11)