egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can i use regsub command for web read?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Regex
Voice


Joined: 19 Mar 2011
Posts: 19

PostPosted: Tue Feb 07, 2012 6:39 pm    Post subject: How can i use regsub command for web read? Reply with quote

Hi dear egghelp.org moderators,

I'm searching regsub command for web read.

Code:

# Komutun Kullanılacağı Kanal
set cmd_chan "#OperLog"

bind pub - !ingilizce msg_english
proc msg_english {nick uhost hand chan text} {
  global botnick cmd_chan
  if {![string match -nocase "$cmd_chan" $chan]} {return}
  regsub -all "ç" $text "%C3%A7" text
  regsub -all "Ç" $text "%C3%87" text
  regsub -all "ğ" $text "%C4%9F" text
  regsub -all "Ğ" $text "%C4%9E" text
  regsub -all "ı" $text "%C4%B1" text
  regsub -all "İ" $text "%C4%B0" text
  regsub -all "ö" $text "%C3%B6" text
  regsub -all "Ö" $text "%C3%96" text
  regsub -all "ş" $text "%C5%9F" text
  regsub -all "Ş" $text "%C5%9E" text
  regsub -all "ü" $text "%C3%BC" text
  regsub -all "Ü" $text "%C3%9C" text
  set (document) ""
  set ("#history-button") ""
  set ("#history") ""
  set ("#history-clear") ""
  set connect [::http::geturl http://www.sozluk.com.tr/sozluk.php?word=$text]
  set files [::http::data $connect]
  set list [split [subst -nocommands $files] "\n"]
  foreach i $list {
    regexp -- {<td class="col-t">(.+?)</td>} $i - translation
    if {[info exists translation]} {
      regsub -all "%C3%A7" $text "ç" text
      regsub -all "%C3%87" $text "Ç" text
      regsub -all "%C4%9F" $text "ğ" text
      regsub -all "%C4%9E" $text "Ğ" text
      regsub -all "%C4%B1" $text "ı" text
      regsub -all "%C4%B0" $text "İ" text
      regsub -all "%C3%B6" $text "ö" text
      regsub -all "%C3%96" $text "Ö" text
      regsub -all "%C5%9F" $text "ş" text
      regsub -all "%C5%9E" $text "Ş" text
      regsub -all "%C3%BC" $text "ü" text
      regsub -all "%C3%9C" $text "Ü" text
      regsub -all "ç" $translation "ç" translation
      regsub -all "Ç" $translation "Ç" translation
      regsub -all "ÄŸ" $translation "ğ" translation
      regsub -all "ı" $translation "ı" translation
      regsub -all "İ" $translation "İ" translation
      regsub -all "ö" $translation "ö" translation
      regsub -all "Ö" $translation "Ö" translation
      regsub -all "ŞŸ" $translation "ş" translation
      regsub -all "Å" $translation "Ş" translation
      regsub -all "ü" $translation "ü" translation
      regsub -all "Ü" $translation "Ü" translation
      putquick "privmsg $cmd_chan 3$text: 1$ translation"
      unset translation
    }
  }
  ::http::cleanup $files
}
putlog "Dictionary TCL - Written By CLubber"


Shortly, regsub -all "ç" $translation "ç" translation < this command in my script isn't working.

How can correct turkish characters?

«00:30:47» <07ZaL> !ingilizce divine
«00:30:48» <Eggdrop> divine: Tanrı gibi olan

I wanna correct this "ı" => "ı"

I hope i could explain my problem.

Thx for your concers.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Feb 08, 2012 3:40 am    Post subject: Reply with quote

I think you could use string map -nocase instead of the regsub lines, for example:
Code:

set text "one TWO TeN"
set text [string map -nocase {one 1 two 2 ten 10} $text]

I tried your letters to figure out if it will work or not, but my copy/paste fails to copy the correct letters in my shell prompt for some reason, for example the ğ ends up as a . (dot). Rolling Eyes

Anyway, i think you can replace:
Code:

  regsub -all "ç" $text "%C3%A7" text
  regsub -all "Ç" $text "%C3%87" text
  regsub -all "ğ" $text "%C4%9F" text
  regsub -all "Ğ" $text "%C4%9E" text
  regsub -all "ı" $text "%C4%B1" text
  regsub -all "İ" $text "%C4%B0" text
  regsub -all "ö" $text "%C3%B6" text
  regsub -all "Ö" $text "%C3%96" text
  regsub -all "ş" $text "%C5%9F" text
  regsub -all "Ş" $text "%C5%9E" text
  regsub -all "ü" $text "%C3%BC" text
  regsub -all "Ü" $text "%C3%9C" text

with:
Code:

string map -nocase {ç %C3%A7 Ç %C3%87 ğ %C4%9F Ğ %C4%9E ı %C4%B1 İ %C4%B0 ö %C3%B6 Ö %C3%96 ş %C5%9F Ş %C5%9E ü %C3%BC Ü %C3%9C} $text

and:
Code:

      regsub -all "%C3%A7" $text "ç" text
      regsub -all "%C3%87" $text "Ç" text
      regsub -all "%C4%9F" $text "ğ" text
      regsub -all "%C4%9E" $text "Ğ" text
      regsub -all "%C4%B1" $text "ı" text
      regsub -all "%C4%B0" $text "İ" text
      regsub -all "%C3%B6" $text "ö" text
      regsub -all "%C3%96" $text "Ö" text
      regsub -all "%C5%9F" $text "ş" text
      regsub -all "%C5%9E" $text "Ş" text
      regsub -all "%C3%BC" $text "ü" text
      regsub -all "%C3%9C" $text "Ü" text
      regsub -all "ç" $translation "ç" translation
      regsub -all "Ç" $translation "Ç" translation
      regsub -all "ÄŸ" $translation "ğ" translation
      regsub -all "ı" $translation "ı" translation
      regsub -all "İ" $translation "İ" translation
      regsub -all "ö" $translation "ö" translation
      regsub -all "Ö" $translation "Ö" translation
      regsub -all "ŞŸ" $translation "ş" translation
      regsub -all "Å" $translation "Ş" translation
      regsub -all "ü" $translation "ü" translation
      regsub -all "Ü" $translation "Ü" translation

with:
Code:

string map -nocase {%C3%A7 ç %C3%87 Ç %C4%9F ğ %C4%9E Ğ %C4%B1 ı %C4%B0 İ %C3%B6 ö %C3%96 Ö %C5%9F ş %C5%9E Ş %C3%BC ü %C3%9C Ü} $text
string map -nocase {ç ç Ç Ç ÄŸ ğ ı ı İ İ Ã¶ ö Ö Ö ŞŸ ş Å Ş Ã¼ ü Ü Ü} $translation

You will have to test this by yourself as my copy/paste fails miserably. Rolling Eyes
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Regex
Voice


Joined: 19 Mar 2011
Posts: 19

PostPosted: Wed Feb 08, 2012 9:47 am    Post subject: Reply with quote

@caesar thanks for your concern but still aint workin.

«15:43:01» <ZaL> !ingilizce Turk
«15:43:02» <SEO> Turk: Türk soyundan kimse

Just utf-8 characters making this.

How can we correct this with other ways?
Back to top
View user's profile Send private message
Johannes13
Halfop


Joined: 10 Oct 2010
Posts: 46

PostPosted: Wed Feb 08, 2012 12:12 pm    Post subject: Reply with quote

Code:

   proc enc v {
      subst [regsub -all {[^a-zA-Z0-9\-_\.~]} [encoding convertto utf-8 $v] {[format %%%02X [scan {\0} %c]]}]
   }

   proc decode v {
      encoding convertfrom utf-8 [subst -nocommands -novariables [regsub -all {%([a-fA-F0-9]{2})} $v {\u\1}]]
   }


should work.

Why make such a big string map/regexp thing that slows down everything?
(and is complex to maintain)
Back to top
View user's profile Send private message
Johannes13
Halfop


Joined: 10 Oct 2010
Posts: 46

PostPosted: Wed Feb 08, 2012 12:38 pm    Post subject: Reply with quote

Ohh, and why do you subst when you got the page contents?

It can be (ab)used to inject commands.

And you know that there is a command called ::http::formatQuery?

It does basicaly the same thing as my enc proc does.


Code:

bind pub - !ingilizce msg_english
proc msg_english {nick uhost hand chan text} {
  global botnick cmd_chan
  if {![string match -nocase "$cmd_chan" $chan]} {return}
  set connect [::http::geturl http://www.sozluk.com.tr/sozluk.php?[::http::formatQuery word $text]]
  set files [::http::data $connect]
  set list [split $files "\n"]
  foreach i $list {
    if {[regexp -- {<td class="col-t">(.+?)</td>} $i - translation]} {
      set translation [encoding convertfrom utf-8 [subst -nocommands -novariables [regsub -all {%([a-fA-F0-9]{2})} $translation {\u\1}]]]
      putquick "privmsg $cmd_chan \0033$text: $translation"
      unset translation
    }
  }
  ::http::cleanup $files
}
putlog "Dictionary TCL - Idea By CLubber"
Back to top
View user's profile Send private message
Regex
Voice


Joined: 19 Mar 2011
Posts: 19

PostPosted: Wed Feb 08, 2012 6:24 pm    Post subject: Reply with quote

@Johannes13 thanks for your concern

Currently, my script is working with any problems.

Thank you so much! Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Feb 09, 2012 2:12 am    Post subject: Reply with quote

@Johannes13 : Interesting. Thanks for sharing. Smile
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber