a small collection of personal scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
880B

  1. use strict;
  2. use warnings;
  3. weechat::register ("fortune", "shmibs", "0.1", "GPL", "set the topic to a fortune <= 140 chars (/fortune)", "", "");
  4. weechat::hook_command("fortune", "", "", "", "", "settopic", "");
  5. sub settopic{
  6. my $buffer=$_[1];
  7. my $tempstr='';
  8. while($tempstr eq '' || length($tempstr) > 140){
  9. $tempstr=`fortune`;
  10. $tempstr=~s/\n/ /g;
  11. $tempstr=~s/ //g;
  12. }
  13. my @tempar=split(//, $tempstr);
  14. my $output="";
  15. my $bool=1;
  16. my $i;
  17. for($i=0; $i<length($tempstr); $i++) {
  18. if($tempar[$i] eq '"') {
  19. if($bool) {
  20. $output.="\x{03}03\"";
  21. $bool=0;
  22. } else {
  23. $output.="\"\x{03}";
  24. $bool=1;
  25. }
  26. } else {
  27. if($i,length($tempstr)-1) {
  28. if($tempar[$i] eq '-' and $tempar[$i+1] eq '-') {
  29. $output.="\x{03}14";
  30. }
  31. }
  32. $output.=$tempar[$i];
  33. }
  34. }
  35. weechat::command($buffer, "/topic $output");
  36. return weechat::WEECHAT_RC_OK;
  37. }