mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2014
Posts: 12
W
Pikka bird
OP Offline
Pikka bird
W
Joined: Dec 2014
Posts: 12
I have an issue. Basically I'm trying to simulate Twitch chatters tmi thingy (tmi.twitch.tv/group/user/USERNAME/chatters) for active users on the channel. Everytime I write something on the file that contains $chr(160) it replaces it with "Â".

I know that's due to the abstence of BOM (byte order mark). How do I fix this?

ps: I'm using v7.36.
ps2: File is constantly being updated.

Last edited by WhatdaFox; 23/05/15 06:10 PM.
Joined: Dec 2014
Posts: 12
W
Pikka bird
OP Offline
Pikka bird
W
Joined: Dec 2014
Posts: 12
Okay... Apparently I can just write as a text file and then rename it.

*Edit* works manually but it doesn't when you try to automate it. Help?

Last edited by WhatdaFox; 23/05/15 06:43 PM.
Joined: Feb 2015
Posts: 243
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Feb 2015
Posts: 243
i don't know the answer to the 1st post but you can rename a file by using /rename filename newfilename
I'm not sure if it's going to change the file type though.. if this is what you're tring to do.

Joined: Dec 2014
Posts: 12
W
Pikka bird
OP Offline
Pikka bird
W
Joined: Dec 2014
Posts: 12
You can actually rename the file but it doesn't work. Once you do it, it replaces every space with "Â " (not on the file. if you upload it to a webserver, you will see that weird character).

Last edited by WhatdaFox; 23/05/15 06:53 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Configure your server to specify the charset in the content-type header: content-type:text/plain; charset=UTF-8

In nginx this is accomplished with the "charset UTF-8;" directive.

When the charset is not specified by the server Firefox and IE use Western encoding whereas Chrome uses Unicode.

----

Edit: Simply writing $chr(65279) as the first character will write the BOM

In general mIRC does not play well with the BOM, and subsequent calls to write the first line will remove the BOM.

I've created two methods to insert a BOM, the first attempts to prepend and rewrite the first line of the file; as usual mIRC will drop trailing/ending spaces. The second reads the entire file, writes the BOM, then rewrites the file. This may be less efficient than mIRC's write function but does not alter the file other than inserting the BOM.

Code:
alias bom return $chr(65279)

alias hasbom {
  var %file = $qt($1-)
  bread $qt(%file) 0 3 &test
  if ($bvar(&test,1-).text == $bom) { return $true }
  return $false
}

alias insertbom {
  var %file = $qt($1-)

  if ($hasbom(%file)) { return }

  if ($lines(%file)) {
    write -l1 %file $bom $+ $read(%file,n,1)
  }
  else {
    bset -t &bom 1 $bom
    bwrite %file 0 -1 &bom
  }
}

alias insertbom2 {
  var %file = $qt($1-)

  if ($hasbom(%file)) { return }

  if ($file(%file).size) {
    bread $qt(%file) 0 $v1 &read
  }

  bset &bom 1 239 187 191
  bwrite %file 0 -1 &bom
  
  if ($bvar(&read,0)) bwrite %file 3 -1 &read
}

Last edited by Loki12583; 24/05/15 05:31 AM.
Joined: Jul 2006
Posts: 4,146
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,146
Hum, your post is very very confusing.

Quote:
Everytime I write something on the file that contains $chr(160) it replaces it with "Â".
This doesn't mean anything, are you using /write with $chr(160) and it doesn't write the $chr(160) correctly? if so what does it write to the file, how are you checking that it didn't write to the file correctly?
If you are unaware, mIRC will write to the file with Unicode, that means $chr(160) will be wrote as the two bytes 194 and 160, which will, when $read back to mirc be combined to form the real $chr(160), could it be that you didn't know that and that's why got you confused?

In any case please describe as much as possible your problem and don't bring ttwich, it's not a problem with twitch.

@Loki, how do you figure it's a BOM problem? mIRC uses it fine, it's there if /write to a file (which is an unicode file already or doesn't exist)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
//write file.txt $chr(160) will result in the following file: c2 a0 0d 0a (no BOM)

Adding the BOM manually results in this file: ef bb bf c2 a0 0d 0a

//write -l1 file.txt $chr(160) results in the BOM being removed

Viewing the file without the BOM in Firefox or IE results in "Â" being displayed because they interpret it as Western encoding.

Joined: Dec 2014
Posts: 12
W
Pikka bird
OP Offline
Pikka bird
W
Joined: Dec 2014
Posts: 12
Originally Posted By: Wims
In any case please describe as much as possible your problem and don't bring ttwich, it's not a problem with twitch.


When did I say it was a twitch problem? Geez -_-


@Loki12583 thank you for your help, it's working now. I really appreciate it.

Last edited by WhatdaFox; 24/05/15 05:08 PM.
Joined: Jul 2006
Posts: 4,146
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,146
Hu, I was thinking mIRC was using BOM, for /write or whenever it could be required. I remember some thread about it,

@OP Didn't mean to be annoying, I didn't say you said it was a twitch problem, I just tried to understand, you didn't say how you were writting to the file and who was it that 'replaced' it with "Â" (it wasn't replaced then, just displayed/interpreted).


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard