-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfranklin_profiler.pl
151 lines (145 loc) · 6.65 KB
/
franklin_profiler.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
# Author: by oxagast
#
# Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
# , .
# ,- | | o
# | ;-. ,-: ;-. | , | . ;-.
# |- | | | | | |< | | | |
# | ' `-` ' ' ' ` ' ' ' '
# -'
use Irssi;
use Data::Dumper;
use vars qw($VERSION %IRSSI);
use utf8;
use JSON::Create 'create_json';
use JSON::Parse ':all';
use Proc::Simple;
use POSIX qw(strftime);
$userfile = "1.3.1";
$franklinver = "4.5.0";
%IRSSI = (
authors => 'oxagast',
contact => '[email protected]',
name => 'franklin_helper',
description => 'Franklin LLM AI bot',
license => 'BSD',
url => 'http://franklin.oxasploits.com',
changed => 'Mar, 11th 2024',
);
Irssi::signal_add_last('message public', 'catchmsg');
my $sdbloc = "/home/franklin/Franklin/fprofiles/"; # this is the location of the dbase dir
sub buildjson {
my ($nick, $hostn, $oper, $create_date, $change_date, $totmsgs, $msg, $queries, $messages, $queries_per_day, $messages_per_day, $day, $average_line_length, @lastm, $rndmm) = @_;
if (1 == int(rand(25))) {
push(@rndm, $rndmm);
}
if (scalar(@lastm) > 8) {
shift(@lastm); # this stuff makes it so that there i
}
if (scalar(@rndm) > 8) {
shift(@rndm);
}
# maximum of x items in the 'last' array
($sec, $min, $hour, $day, $mon, $year_1900, $wday, $yday, $isdst) = localtime;
my ($qpd, $mnpd, $msd);
if ($change_date != strftime("%m-%d-%Y", localtime)) {
$day++;
}
if ($msg =~ m/^Franklin[:|,] /) {
$queries++;
$qpd = $queries / $day; # franklin was called, we know it was a query
}
$messages++;
$mspd = $messages / $day; # this is reset every morning at midnight
my $alll = ($average_line_length + length($msg)) / 2; # calcs avg line len
my $totm = $totmsgs + 1;
# the json should look something like the below after generation
## {"versions":{"userfile":"1.0.0","franklin":"4.0.0"},"nick":"oxagast","create_date":
## "04182024","change_date":"04192024","total_messages":55,"queries_per_day":12,"menti
## ons_per_day":3,"messages_per_day":2,"average_message_length":77,"operator":true,"me
## ssages":{"last":["hello how are you","oh yeah im fine","yeah my name is oxagast, wh
## ats yours"],"random":["blah","no i like girls toes","Franklin: tell me about nyc"]},
## "checksum":"B2CCA97A"}
%summdb = (
(versions => {selfver => $userfile, frankver => $franklinver}),
(
$nick => { # all this gets rewritten back in json after modificaions
create_date => "$create_date",
change_date => "$change_date",
total_messages => "$totm",
queries => "$queries",
messages => "$messages",
queries_per_day => "$qpd",
messages_per_day => "$mpd",
average_message_length => "$alll",
day => "$day",
hostname => "$hostn",
operator => $oper,
(
messages => {
last => [@lastm],
random => [@rndm]
}
)
}
)
);
return create_json(\%summdb); # return the json hash
}
#my $cmn = $server->channel_find($channel)->nick_find($server->{nick});
# this could maybe work like ...
# have all nicks in one json string, oxagast => { ... }, billybob => { ... }, lisab => { ... }, ......
# then copy parts that dont need changing, only pull, edit, and reinsert pieces of json that are
# altered when that user speaks in channels, then written back to file.
sub catchmsg {
my ($server, $msg, $nick, $address, $channel) = @_;
my $injson = "";
if (!-f "$sdbloc/$nick") { # checks if the user is already in the database ad creates it if not
@init = (); # so that the random comes in blanked out
$newjsonout = buildjson($nick, "localhost", 0, strftime("%m-%d-%Y", localtime), strftime("%m-%d-%Y", localtime), 1, 1, 1, 0, $msg, @init); # the final $msg is needed to
# add to the 'last' space in json
open(SDBN, '>', "$sdbloc/$nick"); # opens user's profile
print SDBN $newjsonout; # creates profile
close(SDBN);
$injson = $newjsonout;
}
if (-e "$sdbloc/$nick") {
open(SDBI, '<', "$sdbloc/$nick");
$injson = <SDBI>;
close(SDBI);
}
$lmn{$nick} = \@lm;
$rmn{$nick} = \@rm;
my $dstruct = parse_json($injson);
my $queries = $dstruct->{$nick}->{queries};
my $messages = $dstruct->{$nick}->{messages};
my $queries_per_day = $dstruct->{$nick}->{queries_per_day};
my $messages_per_day = $dstruct->{$nick}->{messages_per_day};
my $create_date = $dstruct->{$nick}->{create_date};
my $change_date = $dstruct->{$nick}->{change_date};
my $average_message_length = $dstruct->{$nick}->{average_message_length};
my $day = $dstruct->{$nick}->{day};
my $ttls = $dstruct->{$nick}->{total_messages};
@lm = @{$dstruct->{$nick}->{messages}->{last}}; # this has to be encased in @{} to denote that is indeed an array ref
my $hostn;
foreach $n ($server->channel_find($channel)->nicks) {
if ($n->{nick} eq $nick) {
$hostn = $n->{host};
}
if ($n->{nick} eq $nick) {
if ($n->{op} != 0) {
$oper = true;
}
else { $oper = false; }
}
}
if ($create_date eq "") {
$create_date = strftime("%m-%d-%Y", localtime);
}
my $change_date = strftime("%m-%d-%Y", localtime);
my $sdbjson = buildjson($nick, $hostn, $oper, $create_date, $change_date, $ttls, $msg, $queries, $messages, $queries_per_day, $messages_per_day, $day, $average_message_length, @lm, $msg);
open(SDBO, '>', "$sdbloc/$nick");
print SDBO $sdbjson; # update the user in dbase
close(SDBO);
}