#!/usr/bin/env perl
#
# ChivaNet AIM<>Discord Chat Sync Bot
# Copyright (C) 2024, 2025 Coherent Logic Development LLC
#
# Author: Serena Willis <snw@coherent-logic.com>
#
# Licensed AGPL-3.0
#
# $Log: chatsync.pl,v $
# Revision 1.2 2025/03/01 15:55:55 snw
# Remove chatsync engaged message
#
# Revision 1.1.1.1 2025/01/30 15:56:56 snw
# Initial commit
#
#
use Net::OSCAR qw(:standard);
use HTML::Strip;
use REST::Client;
use JSON::XS;
use Data::Dumper;
use Getopt::Long;
use WebService::Discord::Webhook;
my $botsn = '';
my $botsrv = '';
my $botpw = '';
my $chatroom = '';
my $webhook_url = '';
$chat = '';
GetOptions("aimsn=s" => \$botsn,
"aimhost=s" => \$botsrv,
"aimpw=s" => \$botpw,
"chatroom=s" => \$chatroom,
"url=s" => \$webhook_url)
or die("error in command line arguments");
%signon = (
screenname => $botsn,
password => $botpw,
host => $botsrv,
);
$oscar = Net::OSCAR->new();
$webhook = WebService::Discord::Webhook->new( $webhook_url );
print ("ChivaNet Discord AIM Synchronizer v0.0.1\n");
print (" Connecting to chat room $chatroom\n");
sub signon_done {
print "[OK]\n";
$chat = $oscar->chat_join($chatroom, 5);
$online = 1;
}
sub chat_joined {
my($oscar, $chatname, $chat) = @_;
print "discord chatsync engaged for $chatroom\n";
}
sub im_in {
my($oscar, $sender, $message, $is_away) = @_;
print "$sender: $message\n";
}
sub chat_im_in {
my($oscar, $who, $chat, $message) = @_;
my $hs = HTML::Strip->new();
my $msg = $hs->parse($message);
$msg =~ s/\@//g;
$msg =~ s/https/gopher/g;
$msg =~ s/http/gopher/g;
$msg =~ s/ftp/gopher/g;
$msg =~ s/:-\)/:smile:/g;
$msg =~ s/;-\)/:wink:/g;
$msg =~ s/:-$/:money_mouth:/g;
$msg =~ s/=-O/:astonished:/g;
$msg =~ s/:-X/:zipper_mouth:/g;
my $fmsg = "**$who**: $msg";
$webhook->execute($fmsg);
}
#OSCAR, SCREENNAME, CHAT, BUDDY DATA
sub chat_buddy_in {
my ($oscar, $who, $chat, $buddy) = @_;
my $fmsg = "*$who has joined the chat*";
sleep(1);
$webhook->execute($fmsg);
}
sub chat_buddy_out {
my ($oscar, $who, $chat) = @_;
my $fmsg = "*$who has left the chat*";
sleep(1);
$webhook->execute($fmsg);
}
$oscar->set_callback_signon_done(\&signon_done);
$oscar->set_callback_chat_joined(\&chat_joined);
$oscar->set_callback_im_in(\&im_in);
$oscar->set_callback_chat_im_in(\&chat_im_in);
#$oscar->set_callback_chat_buddy_in(\&chat_buddy_in);
#$oscar->set_callback_chat_buddy_out(\&chat_buddy_out);
print "chatsync: attempting to sign in... ";
$oscar->signon(%signon);
while(1) {
$oscar->do_one_loop();
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>