Annotation of ChivanetAimDiscordSyncBot/chatsync.pl, revision 1.1.1.1

1.1       snw         1: #!/usr/bin/env perl
                      2: 
                      3: # 
                      4: # ChivaNet AIM<>Discord Chat Sync Bot 
                      5: #  Copyright (C) 2024, 2025 Coherent Logic Development LLC
                      6: #
                      7: # Author: Serena Willis <snw@coherent-logic.com>
                      8: #
                      9: # Licensed AGPL-3.0
                     10: #
                     11: # $Log$
                     12: #
                     13: 
                     14: use Net::OSCAR qw(:standard);
                     15: use HTML::Strip;
                     16: use REST::Client;
                     17: use JSON::XS;
                     18: use Data::Dumper;
                     19: use Getopt::Long;
                     20: use WebService::Discord::Webhook;
                     21: 
                     22: my $botsn = '';
                     23: my $botsrv = '';
                     24: my $botpw = '';
                     25: my $chatroom = '';
                     26: my $webhook_url = '';
                     27: 
                     28: $chat = '';
                     29: 
                     30: GetOptions("aimsn=s" => \$botsn,
                     31:             "aimhost=s" => \$botsrv,
                     32:             "aimpw=s" => \$botpw,
                     33:             "chatroom=s" => \$chatroom,
                     34:             "url=s" => \$webhook_url)
                     35:             or die("error in command line arguments");
                     36: 
                     37: %signon = (
                     38:         screenname => $botsn,
                     39:         password => $botpw,
                     40:         host => $botsrv,
                     41: );       
                     42: 
                     43: $oscar = Net::OSCAR->new();
                     44: $webhook = WebService::Discord::Webhook->new( $webhook_url );
                     45: 
                     46: print ("ChivaNet Discord AIM Synchronizer v0.0.1\n");
                     47: print ("  Connecting to chat room $chatroom\n");
                     48: 
                     49: sub signon_done {
                     50:         print "[OK]\n";
                     51:         $chat = $oscar->chat_join($chatroom, 5);        
                     52:         $online = 1;
                     53: }
                     54: 
                     55: sub chat_joined {
                     56:     my($oscar, $chatname, $chat) = @_;
                     57: 
                     58:     $chat->chat_send("discord chatsync engaged for $chatroom");
                     59: }
                     60: 
                     61: sub im_in {
                     62:     my($oscar, $sender, $message, $is_away) = @_;
                     63:     print "$sender: $message\n";
                     64: }
                     65: 
                     66: sub chat_im_in {
                     67:     my($oscar, $who, $chat, $message) = @_;
                     68:     
                     69:     my $hs = HTML::Strip->new();
                     70:     my $msg = $hs->parse($message);
                     71:     $msg =~ s/\@//g;
                     72:     $msg =~ s/https/gopher/g;
                     73:     $msg =~ s/http/gopher/g;
                     74:     $msg =~ s/ftp/gopher/g;
                     75: 
                     76:     $msg =~ s/:-\)/:smile:/g;
                     77:     $msg =~ s/;-\)/:wink:/g;
                     78:     $msg =~ s/:-$/:money_mouth:/g;
                     79:     $msg =~ s/=-O/:astonished:/g;
                     80:     $msg =~ s/:-X/:zipper_mouth:/g;
                     81: 
                     82:     
                     83:     
                     84:     my $fmsg = "**$who**: $msg";
                     85: 
                     86:     $webhook->execute($fmsg);
                     87: }
                     88: 
                     89: #OSCAR, SCREENNAME, CHAT, BUDDY DATA
                     90: sub chat_buddy_in {
                     91:     my ($oscar, $who, $chat, $buddy) = @_;
                     92:     my $fmsg = "*$who has joined the chat*";
                     93:     sleep(1);
                     94:     $webhook->execute($fmsg);
                     95: }
                     96: 
                     97: sub chat_buddy_out {
                     98:     my ($oscar, $who, $chat) = @_;
                     99:     my $fmsg = "*$who has left the chat*";
                    100:     sleep(1);
                    101:     $webhook->execute($fmsg);
                    102: }
                    103: 
                    104: 
                    105: 
                    106: $oscar->set_callback_signon_done(\&signon_done);
                    107: $oscar->set_callback_chat_joined(\&chat_joined);
                    108: $oscar->set_callback_im_in(\&im_in);
                    109: $oscar->set_callback_chat_im_in(\&chat_im_in);
                    110: #$oscar->set_callback_chat_buddy_in(\&chat_buddy_in);
                    111: #$oscar->set_callback_chat_buddy_out(\&chat_buddy_out);
                    112: 
                    113: print "chatsync:  attempting to sign in... ";
                    114: $oscar->signon(%signon);
                    115: 
                    116: while(1) {
                    117:     $oscar->do_one_loop();        
                    118: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>