ICQ chat bot problems with encodings

173 views Asked by At

Yesterday I have been writing simple program in perl.

It is icq bot, you write a message as the math expression and it calculates the value.

The problem is that incoming message has not-single-byte encoding and when it is writing to file there are a lot of bad symbols and of course calc can't handle this file.

how can I convert incoming message to ASCII?

Here is the source:

#!/usr/bin/perl

use Net::OSCAR;
use Encode;
use strict;

my ($UIN, $PASSWORD, $oscar, $t, $msg);

$UIN='675349295';
$PASSWORD='passwd';

$oscar = Net::OSCAR->new();
$oscar->set_callback_im_in(\&send_answer);
$t = 0;

while (1)
{
    if (!$oscar->is_on && (time() - $t) > 120)
    {
        $oscar->signon($UIN, $PASSWORD);
        $t=time();
    }

    $oscar->do_one_loop();
}

sub send_answer()
{
    my($oscar, $sender, $msg) = @_;

    if ($msg eq "quit")
    {
        $oscar->signoff();
        exit();
    }

    open(my($fh), '>', '/tmp/msg');
    print $fh "$msg";
    close $fh;

    my($ans)=`calc -p -f /tmp/msg`;
    $oscar->send_im($sender, $ans);
}
0

There are 0 answers