File:  [Coherent Logic Development] / ChivanetAimDiscordSyncBot / chatsync.pl
Revision 1.2: download - view: text, annotated - select for diffs
Sat Mar 1 15:55:55 2025 UTC (5 months ago) by snw
Branches: MAIN
CVS tags: HEAD
Remove chatsync engaged message

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

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