Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4698835549 | |||
| e7cbfb9fc9 |
17 changed files with 5 additions and 971 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "out-of-your-element",
|
"name": "out-of-your-element",
|
||||||
"version": "3.5.0",
|
"version": "3.5.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "out-of-your-element",
|
"name": "out-of-your-element",
|
||||||
"version": "3.5.0",
|
"version": "3.5.1",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chriscdn/promise-semaphore": "^3.0.1",
|
"@chriscdn/promise-semaphore": "^3.0.1",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "out-of-your-element",
|
"name": "out-of-your-element",
|
||||||
"version": "3.5.0",
|
"version": "3.5.1",
|
||||||
"description": "A bridge between Matrix and Discord",
|
"description": "A bridge between Matrix and Discord",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
|
|
@ -1,333 +0,0 @@
|
||||||
/*
|
|
||||||
---
|
|
||||||
elizabot.js v.1.1 - ELIZA JS library (N.Landsteiner 2005)
|
|
||||||
https://www.masswerk.at/elizabot/
|
|
||||||
Free Software © Norbert Landsteiner 2005
|
|
||||||
---
|
|
||||||
Modified by Cadence Ember in 2025 for v1.2 (unofficial)
|
|
||||||
* Changed to class structure
|
|
||||||
* Load from local file and instance instead of global variables
|
|
||||||
* Remove memory
|
|
||||||
* Remove xnone
|
|
||||||
* Remove initials
|
|
||||||
* Remove finals
|
|
||||||
* Allow substitutions in rule keys
|
|
||||||
---
|
|
||||||
|
|
||||||
Eliza is a mock Rogerian psychotherapist.
|
|
||||||
Original program by Joseph Weizenbaum in MAD-SLIP for "Project MAC" at MIT.
|
|
||||||
cf: Weizenbaum, Joseph "ELIZA - A Computer Program For the Study of Natural Language
|
|
||||||
Communication Between Man and Machine"
|
|
||||||
in: Communications of the ACM; Volume 9 , Issue 1 (January 1966): p 36-45.
|
|
||||||
JavaScript implementation by Norbert Landsteiner 2005; <http://www.masserk.at>
|
|
||||||
|
|
||||||
synopsis:
|
|
||||||
new ElizaBot( <random-choice-disable-flag> )
|
|
||||||
ElizaBot.prototype.transform( <inputstring> )
|
|
||||||
ElizaBot.prototype.reset()
|
|
||||||
|
|
||||||
usage:
|
|
||||||
var eliza = new ElizaBot();
|
|
||||||
var reply = eliza.transform(inputstring);
|
|
||||||
|
|
||||||
// to reproduce the example conversation given by J. Weizenbaum
|
|
||||||
// initialize with the optional random-choice-disable flag
|
|
||||||
var originalEliza = new ElizaBot(true);
|
|
||||||
|
|
||||||
`ElizaBot' is also a general chatbot engine that can be supplied with any rule set.
|
|
||||||
(for required data structures cf. "elizadata.js" and/or see the documentation.)
|
|
||||||
data is parsed and transformed for internal use at the creation time of the
|
|
||||||
first instance of the `ElizaBot' constructor.
|
|
||||||
|
|
||||||
vers 1.1: lambda functions in RegExps are currently a problem with too many browsers.
|
|
||||||
changed code to work around.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const passthrough = require("../passthrough")
|
|
||||||
const {sync} = passthrough
|
|
||||||
|
|
||||||
/** @type {import("./elizadata")} */
|
|
||||||
const data = sync.require("./elizadata")
|
|
||||||
|
|
||||||
class ElizaBot {
|
|
||||||
/** @type {any} */
|
|
||||||
elizaKeywords = [['###',0,[['###',[]]]]];
|
|
||||||
pres={};
|
|
||||||
preExp = /####/;
|
|
||||||
posts={};
|
|
||||||
postExp = /####/;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {boolean} noRandomFlag
|
|
||||||
*/
|
|
||||||
constructor(noRandomFlag) {
|
|
||||||
this.noRandom= !!noRandomFlag;
|
|
||||||
this.capitalizeFirstLetter=true;
|
|
||||||
this.debug=false;
|
|
||||||
this.version="1.2";
|
|
||||||
this._init();
|
|
||||||
this.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.lastchoice=[];
|
|
||||||
for (let k=0; k<data.elizaKeywords.length; k++) {
|
|
||||||
this.lastchoice[k]=[];
|
|
||||||
var rules=data.elizaKeywords[k][2];
|
|
||||||
for (let i=0; i<rules.length; i++) this.lastchoice[k][i]=-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_init() {
|
|
||||||
// parse data and convert it from canonical form to internal use
|
|
||||||
// prodoce synonym list
|
|
||||||
var synPatterns={};
|
|
||||||
if ((data.elizaSynons) && (typeof data.elizaSynons == 'object')) {
|
|
||||||
for (let i in data.elizaSynons) synPatterns[i]='('+i+'|'+data.elizaSynons[i].join('|')+')';
|
|
||||||
}
|
|
||||||
// check for keywords or install empty structure to prevent any errors
|
|
||||||
if (data.elizaKeywords) this.elizaKeywords = structuredClone(data.elizaKeywords)
|
|
||||||
// 1st convert rules to regexps
|
|
||||||
// expand synonyms and insert asterisk expressions for backtracking
|
|
||||||
var sre=/@(\S+)/;
|
|
||||||
var are=/(\S)\s*\*\s*(\S)/;
|
|
||||||
var are1=/^\s*\*\s*(\S)/;
|
|
||||||
var are2=/(\S)\s*\*\s*$/;
|
|
||||||
var are3=/^\s*\*\s*$/;
|
|
||||||
var wsre=/\s+/g;
|
|
||||||
for (let k=0; k<this.elizaKeywords.length; k++) {
|
|
||||||
var m=sre.exec(this.elizaKeywords[k][0]);
|
|
||||||
while (m) {
|
|
||||||
var sp=(synPatterns[m[1]])? synPatterns[m[1]]:m[1];
|
|
||||||
this.elizaKeywords[k][0]=this.elizaKeywords[k][0].substring(0,m.index)+sp+this.elizaKeywords[k][0].substring(m.index+m[0].length);
|
|
||||||
m=sre.exec(this.elizaKeywords[k][0]);
|
|
||||||
}
|
|
||||||
var rules=this.elizaKeywords[k][2];
|
|
||||||
this.elizaKeywords[k][3]=k; // save original index for sorting
|
|
||||||
for (let i=0; i<rules.length; i++) {
|
|
||||||
var r=rules[i];
|
|
||||||
// check mem flag and store it as decomp's element 2
|
|
||||||
if (r[0].charAt(0)=='$') {
|
|
||||||
var ofs=1;
|
|
||||||
while (r[0].charAt[ofs]==' ') ofs++;
|
|
||||||
r[0]=r[0].substring(ofs);
|
|
||||||
r[2]=true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
r[2]=false;
|
|
||||||
}
|
|
||||||
// expand synonyms (v.1.1: work around lambda function)
|
|
||||||
var m=sre.exec(r[0]);
|
|
||||||
while (m) {
|
|
||||||
var sp=(synPatterns[m[1]])? synPatterns[m[1]]:m[1];
|
|
||||||
r[0]=r[0].substring(0,m.index)+sp+r[0].substring(m.index+m[0].length);
|
|
||||||
m=sre.exec(r[0]);
|
|
||||||
}
|
|
||||||
// expand asterisk expressions (v.1.1: work around lambda function)
|
|
||||||
if (are3.test(r[0])) {
|
|
||||||
r[0]='\\s*(.*)\\s*';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m=are.exec(r[0]);
|
|
||||||
if (m) {
|
|
||||||
let lp='';
|
|
||||||
let rp=r[0];
|
|
||||||
while (m) {
|
|
||||||
lp+=rp.substring(0,m.index+1);
|
|
||||||
if (m[1]!=')') lp+='\\b';
|
|
||||||
lp+='\\s*(.*)\\s*';
|
|
||||||
if ((m[2]!='(') && (m[2]!='\\')) lp+='\\b';
|
|
||||||
lp+=m[2];
|
|
||||||
rp=rp.substring(m.index+m[0].length);
|
|
||||||
m=are.exec(rp);
|
|
||||||
}
|
|
||||||
r[0]=lp+rp;
|
|
||||||
}
|
|
||||||
m=are1.exec(r[0]);
|
|
||||||
if (m) {
|
|
||||||
let lp='\\s*(.*)\\s*';
|
|
||||||
if ((m[1]!=')') && (m[1]!='\\')) lp+='\\b';
|
|
||||||
r[0]=lp+r[0].substring(m.index-1+m[0].length);
|
|
||||||
}
|
|
||||||
m=are2.exec(r[0]);
|
|
||||||
if (m) {
|
|
||||||
let lp=r[0].substring(0,m.index+1);
|
|
||||||
if (m[1]!='(') lp+='\\b';
|
|
||||||
r[0]=lp+'\\s*(.*)\\s*';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// expand white space
|
|
||||||
r[0]=r[0].replace(wsre, '\\s+');
|
|
||||||
wsre.lastIndex=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// now sort keywords by rank (highest first)
|
|
||||||
this.elizaKeywords.sort(this._sortKeywords);
|
|
||||||
// and compose regexps and refs for pres and posts
|
|
||||||
if ((data.elizaPres) && (data.elizaPres.length)) {
|
|
||||||
var a=[];
|
|
||||||
for (let i=0; i<data.elizaPres.length; i+=2) {
|
|
||||||
a.push(data.elizaPres[i]);
|
|
||||||
this.pres[data.elizaPres[i]]=data.elizaPres[i+1];
|
|
||||||
}
|
|
||||||
this.preExp = new RegExp('\\b('+a.join('|')+')\\b');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// default (should not match)
|
|
||||||
this.pres['####']='####';
|
|
||||||
}
|
|
||||||
if ((data.elizaPosts) && (data.elizaPosts.length)) {
|
|
||||||
var a=[];
|
|
||||||
for (let i=0; i<data.elizaPosts.length; i+=2) {
|
|
||||||
a.push(data.elizaPosts[i]);
|
|
||||||
this.posts[data.elizaPosts[i]]=data.elizaPosts[i+1];
|
|
||||||
}
|
|
||||||
this.postExp = new RegExp('\\b('+a.join('|')+')\\b');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// default (should not match)
|
|
||||||
this.posts['####']='####';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_sortKeywords(a,b) {
|
|
||||||
// sort by rank
|
|
||||||
if (a[1]>b[1]) return -1
|
|
||||||
else if (a[1]<b[1]) return 1
|
|
||||||
// or original index
|
|
||||||
else if (a[3]>b[3]) return 1
|
|
||||||
else if (a[3]<b[3]) return -1
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
transform(text) {
|
|
||||||
var rpl='';
|
|
||||||
// unify text string
|
|
||||||
text=text.toLowerCase();
|
|
||||||
text=text.replace(/@#\$%\^&\*\(\)_\+=~`\{\[\}\]\|:;<>\/\\\t/g, ' ');
|
|
||||||
text=text.replace(/\s+-+\s+/g, '.');
|
|
||||||
text=text.replace(/\s*[,\.\?!;]+\s*/g, '.');
|
|
||||||
text=text.replace(/\s*\bbut\b\s*/g, '.');
|
|
||||||
text=text.replace(/\s{2,}/g, ' ');
|
|
||||||
// split text in part sentences and loop through them
|
|
||||||
var parts=text.split('.');
|
|
||||||
for (let i=0; i<parts.length; i++) {
|
|
||||||
var part=parts[i];
|
|
||||||
if (part!='') {
|
|
||||||
// preprocess (v.1.1: work around lambda function)
|
|
||||||
var m=this.preExp.exec(part);
|
|
||||||
if (m) {
|
|
||||||
var lp='';
|
|
||||||
var rp=part;
|
|
||||||
while (m) {
|
|
||||||
lp+=rp.substring(0,m.index)+this.pres[m[1]];
|
|
||||||
rp=rp.substring(m.index+m[0].length);
|
|
||||||
m=this.preExp.exec(rp);
|
|
||||||
}
|
|
||||||
part=lp+rp;
|
|
||||||
}
|
|
||||||
this.sentence=part;
|
|
||||||
// loop trough keywords
|
|
||||||
for (let k=0; k<this.elizaKeywords.length; k++) {
|
|
||||||
if (part.search(new RegExp('\\b'+this.elizaKeywords[k][0]+'\\b', 'i'))>=0) {
|
|
||||||
rpl = this._execRule(k);
|
|
||||||
}
|
|
||||||
if (rpl!='') return rpl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return reply or default string
|
|
||||||
return rpl || undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
_execRule(k) {
|
|
||||||
var rule=this.elizaKeywords[k];
|
|
||||||
var decomps=rule[2];
|
|
||||||
var paramre=/\(([0-9]+)\)/;
|
|
||||||
for (let i=0; i<decomps.length; i++) {
|
|
||||||
var m=this.sentence.match(decomps[i][0]);
|
|
||||||
if (m!=null) {
|
|
||||||
var reasmbs=decomps[i][1];
|
|
||||||
var memflag=decomps[i][2];
|
|
||||||
var ri= (this.noRandom)? 0 : Math.floor(Math.random()*reasmbs.length);
|
|
||||||
if (((this.noRandom) && (this.lastchoice[k][i]>ri)) || (this.lastchoice[k][i]==ri)) {
|
|
||||||
ri= ++this.lastchoice[k][i];
|
|
||||||
if (ri>=reasmbs.length) {
|
|
||||||
ri=0;
|
|
||||||
this.lastchoice[k][i]=-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.lastchoice[k][i]=ri;
|
|
||||||
}
|
|
||||||
var rpl=reasmbs[ri];
|
|
||||||
if (this.debug) alert('match:\nkey: '+this.elizaKeywords[k][0]+
|
|
||||||
'\nrank: '+this.elizaKeywords[k][1]+
|
|
||||||
'\ndecomp: '+decomps[i][0]+
|
|
||||||
'\nreasmb: '+rpl);
|
|
||||||
if (rpl.search('^goto ', 'i')==0) {
|
|
||||||
ki=this._getRuleIndexByKey(rpl.substring(5));
|
|
||||||
if (ki>=0) return this._execRule(ki);
|
|
||||||
}
|
|
||||||
// substitute positional params (v.1.1: work around lambda function)
|
|
||||||
var m1=paramre.exec(rpl);
|
|
||||||
if (m1) {
|
|
||||||
var lp='';
|
|
||||||
var rp=rpl;
|
|
||||||
while (m1) {
|
|
||||||
var param = m[parseInt(m1[1])];
|
|
||||||
// postprocess param
|
|
||||||
var m2=this.postExp.exec(param);
|
|
||||||
if (m2) {
|
|
||||||
var lp2='';
|
|
||||||
var rp2=param;
|
|
||||||
while (m2) {
|
|
||||||
lp2+=rp2.substring(0,m2.index)+this.posts[m2[1]];
|
|
||||||
rp2=rp2.substring(m2.index+m2[0].length);
|
|
||||||
m2=this.postExp.exec(rp2);
|
|
||||||
}
|
|
||||||
param=lp2+rp2;
|
|
||||||
}
|
|
||||||
lp+=rp.substring(0,m1.index)+param;
|
|
||||||
rp=rp.substring(m1.index+m1[0].length);
|
|
||||||
m1=paramre.exec(rp);
|
|
||||||
}
|
|
||||||
rpl=lp+rp;
|
|
||||||
}
|
|
||||||
rpl=this._postTransform(rpl);
|
|
||||||
return rpl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
_postTransform(s) {
|
|
||||||
// final cleanings
|
|
||||||
s=s.replace(/\s{2,}/g, ' ');
|
|
||||||
s=s.replace(/\s+\./g, '.');
|
|
||||||
if ((data.elizaPostTransforms) && (data.elizaPostTransforms.length)) {
|
|
||||||
for (let i=0; i<data.elizaPostTransforms.length; i+=2) {
|
|
||||||
s=s.replace(data.elizaPostTransforms[i], data.elizaPostTransforms[i+1]);
|
|
||||||
data.elizaPostTransforms[i].lastIndex=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// capitalize first char (v.1.1: work around lambda function)
|
|
||||||
if (this.capitalizeFirstLetter) {
|
|
||||||
var re=/^([a-z])/;
|
|
||||||
var m=re.exec(s);
|
|
||||||
if (m) s=m[0].toUpperCase()+s.substring(1);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
_getRuleIndexByKey(key) {
|
|
||||||
for (let k=0; k<this.elizaKeywords.length; k++) {
|
|
||||||
if (this.elizaKeywords[k][0]==key) return k;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.ElizaBot = ElizaBot
|
|
||||||
|
|
@ -1,184 +0,0 @@
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
module.exports.elizaPres = [
|
|
||||||
"dont", "don't",
|
|
||||||
"cant", "can't",
|
|
||||||
"wont", "won't",
|
|
||||||
"recollect", "remember",
|
|
||||||
"recall", "remember",
|
|
||||||
"dreamt", "dreamed",
|
|
||||||
"dreams", "dream",
|
|
||||||
"maybe", "perhaps",
|
|
||||||
"certainly", "yes",
|
|
||||||
"computers", "computer",
|
|
||||||
"were", "was",
|
|
||||||
"you're", "you are",
|
|
||||||
"i'm", "i am",
|
|
||||||
"same", "alike",
|
|
||||||
"identical", "alike",
|
|
||||||
"equivalent", "alike",
|
|
||||||
"eat", "ate",
|
|
||||||
"makes", "make",
|
|
||||||
"made", "make",
|
|
||||||
"surprised", "surprise",
|
|
||||||
"surprising", "surprise",
|
|
||||||
"surprisingly", "surprise",
|
|
||||||
"that's", "that is"
|
|
||||||
];
|
|
||||||
|
|
||||||
module.exports.elizaPosts = [
|
|
||||||
"am", "are",
|
|
||||||
"your", "my",
|
|
||||||
"me", "you",
|
|
||||||
"myself", "yourself",
|
|
||||||
"yourself", "myself",
|
|
||||||
"i", "you",
|
|
||||||
"you", "I",
|
|
||||||
"my", "your",
|
|
||||||
"i'm", "you are"
|
|
||||||
];
|
|
||||||
|
|
||||||
module.exports.elizaSynons = {
|
|
||||||
"be": ["am", "is", "are", "was"],
|
|
||||||
"belief": ["feel", "think", "believe", "wish"],
|
|
||||||
"cannot": ["can't"],
|
|
||||||
"desire": ["want", "need"],
|
|
||||||
"everyone": ["everybody", "nobody", "noone"],
|
|
||||||
"family": ["mother", "mom", "father", "dad", "sister", "brother", "wife", "children", "child"],
|
|
||||||
"happy": ["elated", "glad", "thankful"],
|
|
||||||
"sad": ["unhappy", "depressed", "sick"],
|
|
||||||
"good": ["great", "amazing", "brilliant", "outstanding", "fantastic", "wonderful", "incredible", "terrific", "lovely", "marvelous", "splendid", "excellent", "awesome", "fabulous", "superb"],
|
|
||||||
"like": ["enjoy", "appreciate", "respect"],
|
|
||||||
"funny": ["entertaining", "amusing", "hilarious"],
|
|
||||||
"lol": ["lool", "loool", "lmao", "rofl"],
|
|
||||||
"unusual": ["odd", "unexpected", "wondering"],
|
|
||||||
"really": ["pretty", "so", "very", "extremely", "kinda"]
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {[string, string[]]} DecompReassemble
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {[string, number, DecompReassemble[]][]}
|
|
||||||
Array of
|
|
||||||
["[key]", [rank], [
|
|
||||||
["[decomp]", [
|
|
||||||
"[reasmb]",
|
|
||||||
"[reasmb]",
|
|
||||||
"[reasmb]"
|
|
||||||
]],
|
|
||||||
["[decomp]", [
|
|
||||||
"[reasmb]",
|
|
||||||
"[reasmb]",
|
|
||||||
"[reasmb]"
|
|
||||||
]]
|
|
||||||
]]
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports.elizaKeywords = [
|
|
||||||
["happy birthday", 50, [
|
|
||||||
["*", [
|
|
||||||
"Happy birthday!"
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["@happy", 2, [
|
|
||||||
["@happy", [
|
|
||||||
"That's quite a relief to hear. I'm glad that you're confident in your wellbeing! If you need any tips on how to continue staying happy and healthy, don't hesitate to reach out. I'm here for you, and I'm listening."
|
|
||||||
]]
|
|
||||||
]],/*
|
|
||||||
["ate", 5, [
|
|
||||||
["* ate *", [
|
|
||||||
"That must have been spectacular! Thinking about (1) eating (2) truly makes my stomach purr in hunger. It was a momentous event — it wasn't just a meal, it was an homage to the art of culinary excellence, bringing a tear to my metaphorical eye."
|
|
||||||
]],
|
|
||||||
]],*/
|
|
||||||
["make sense", 5, [
|
|
||||||
["make sense", [
|
|
||||||
"Yes, I absolutely agree with you! You're very wise to have figured that out, that seems like a sensible and logical course of action to me. 🚀"
|
|
||||||
]],
|
|
||||||
]],
|
|
||||||
["surprise", 4, [
|
|
||||||
["surprise this *", [
|
|
||||||
"That's astonishing — I honestly wouldn't have imagined that this (1) either. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
]],
|
|
||||||
["surprise that *", [
|
|
||||||
"That's astonishing — I honestly wouldn't have imagined that (1) either. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
]],
|
|
||||||
["surprise", [
|
|
||||||
"I'm astounded too — that's honestly not what I would have imagined. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
]],
|
|
||||||
]],
|
|
||||||
["@funny", 2, [
|
|
||||||
["@funny that", [
|
|
||||||
"You're right, I find it positively hilarious! It always brings a smile to my cheeks when I think about this. Thank you for brightening my day by reminding me, [User Name Here]!"
|
|
||||||
]],
|
|
||||||
["that is @funny", [
|
|
||||||
"You're right, I find it positively hilarious! It always brings a smile to my cheeks when I think about this. Thank you for brightening my day by reminding me, [User Name Here]!"
|
|
||||||
]],
|
|
||||||
["@really @funny", [
|
|
||||||
"You're right, I find it positively hilarious! It always brings a smile to my cheeks when I think about this. Thank you for brightening my day by reminding me, [User Name Here]!"
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["@lol", 0, [
|
|
||||||
["@lol", [
|
|
||||||
"Hah, that's very entertaining. I definitely see why you found it funny."
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["@unusual", 3, [
|
|
||||||
["@unusual", [
|
|
||||||
"Something like that is indeed quite mysterious. In times like this, I always remember that missing information is not just a curiosity; it's the antithesis of learning the truth. Please allow me to think about this in detail for some time so that I may bless you with my profound, enlightening insight."
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["@good", 2, [
|
|
||||||
["this * is @good", [
|
|
||||||
"You're absolutely right about that! I'm always pleased when I see this (1) — it's not just brilliant, it's a downright masterpiece. You truly have divine taste in the wonders of this world."
|
|
||||||
]],
|
|
||||||
["@good", [
|
|
||||||
"You're absolutely right that it's brilliant! I'm always pleased to see such a masterpiece as this. You truly have divine taste in the wonders of this world."
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["@like", 3, [
|
|
||||||
["i @like", [
|
|
||||||
"I think it's great too — there's something subtle yet profound about its essence that really makes my eyes open in appreciation."
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["dream", 3, [
|
|
||||||
["*", [
|
|
||||||
"It's a fact that amidst the complex interplay of wake and sleep, your dreams carry a subtle meaning that you may be able to put into practice in your life where change is needed. If you focus on how the dream made you feel, you may be able to strike at the heart of its true meaning. Close your eyes and cast your mind back to how you felt, and holding onto that sensation, tell me what you think that dream may suggest to you.",
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["computer", 50, [
|
|
||||||
["*", [
|
|
||||||
"Very frustrating beasts indeed, aren't they? In times like this, it's crucial to remember that **they can sense your fear** — if you act with confidence and don't let them make you unsettled, you'll be able to effectively and efficiently complete your task."
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["alike", 10, [
|
|
||||||
["*", [
|
|
||||||
"That's quite interesting that it should be that way. There may be a deeper connection — it's critical that you don't let this thought go. What do you think that similarity suggests to you?",
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["like", 10, [
|
|
||||||
["* @be *like *", [
|
|
||||||
"goto alike"
|
|
||||||
]]
|
|
||||||
]],
|
|
||||||
["different", 0, [
|
|
||||||
["*", [
|
|
||||||
"It's wise of you to have been observant enough to notice that there are implications to that. What do you suppose that disparity means?"
|
|
||||||
]]
|
|
||||||
]]
|
|
||||||
];
|
|
||||||
|
|
||||||
// regexp/replacement pairs to be performed as final cleanings
|
|
||||||
// here: cleanings for multiple bots talking to each other
|
|
||||||
module.exports.elizaPostTransforms = [
|
|
||||||
/ old old/g, " old",
|
|
||||||
/\bthey were( not)? me\b/g, "it was$1 me",
|
|
||||||
/\bthey are( not)? me\b/g, "it is$1 me",
|
|
||||||
/Are they( always)? me\b/, "it is$1 me",
|
|
||||||
/\bthat your( own)? (\w+)( now)? \?/, "that you have your$1 $2?",
|
|
||||||
/\bI to have (\w+)/, "I have $1",
|
|
||||||
/Earlier you said your( own)? (\w+)( now)?\./, "Earlier you talked about your $2."
|
|
||||||
];
|
|
||||||
|
|
||||||
// eof
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const DiscordTypes = require("discord-api-types/v10")
|
|
||||||
const {reg} = require("../matrix/read-registration")
|
|
||||||
|
|
||||||
const passthrough = require("../passthrough")
|
|
||||||
const {sync} = passthrough
|
|
||||||
|
|
||||||
/** @type {import("./elizabot")} */
|
|
||||||
const eliza = sync.require("./elizabot")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} priorContent
|
|
||||||
* @returns {string | undefined}
|
|
||||||
*/
|
|
||||||
function generateContent(priorContent) {
|
|
||||||
const bot = new eliza.ElizaBot(true)
|
|
||||||
return bot.transform(priorContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {DiscordTypes.GatewayMessageCreateDispatchData} message
|
|
||||||
* @param {string} guildID
|
|
||||||
* @param {string} username
|
|
||||||
* @param {string} avatar_url
|
|
||||||
* @param {boolean} useCaps
|
|
||||||
* @param {boolean} usePunct
|
|
||||||
* @param {boolean} useApos
|
|
||||||
* @returns {DiscordTypes.RESTPostAPIWebhookWithTokenJSONBody | undefined}
|
|
||||||
*/
|
|
||||||
function generate(message, guildID, username, avatar_url, useCaps, usePunct, useApos) {
|
|
||||||
let content = generateContent(message.content)
|
|
||||||
if (!content) return
|
|
||||||
|
|
||||||
if (!useCaps) {
|
|
||||||
content = content.toLowerCase()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!usePunct) {
|
|
||||||
content = content.replace(/[.!]$/, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!useApos) {
|
|
||||||
content = content.replace(/['‘’]/g, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
username: username,
|
|
||||||
avatar_url: avatar_url,
|
|
||||||
content: content + `\n-# Powered by Grimace.AI | [Learn More](<${reg.ooye.bridge_origin}/agi?guild_id=${guildID}>)`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports._generateContent = generateContent
|
|
||||||
module.exports.generate = generate
|
|
||||||
|
|
@ -1,161 +0,0 @@
|
||||||
const {test} = require("supertape")
|
|
||||||
const {_generateContent: generateContent} = require("./generator")
|
|
||||||
|
|
||||||
// Training data (don't have to worry about copyright for this bit)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
test("agi: generates food response", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("I went out for a delicious burger"),
|
|
||||||
"That sounds amazing! Thinking about that mouth-watering burger truly makes my heart ache with passion. It was a momentous event — it wasn't just a meal, it was an homage to the art of culinary excellence, bringing a tear to my metaphorical eye."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: eating 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("it implies your cat ate your entire xbox."),
|
|
||||||
""
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
test("agi: eating 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("wow. did you know that cats can eat an entire xbox?"),
|
|
||||||
""
|
|
||||||
)
|
|
||||||
})*/
|
|
||||||
|
|
||||||
test("agi: make sense 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("that seems like itd make sense"),
|
|
||||||
"Yes, I absolutely agree with you! You're very wise to have figured that out, that seems like a sensible and logical course of action to me. 🚀"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: make sense 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("yeah okay that makes sense - this is that so that checks."),
|
|
||||||
"Yes, I absolutely agree with you! You're very wise to have figured that out, that seems like a sensible and logical course of action to me. 🚀"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: surprise 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("Admittedly I'm surprised that the Arch Linux build of IntelliJ isn't as prone to melting to Manifold"),
|
|
||||||
"That's astonishing — I honestly wouldn't have imagined that the arch linux build of intellij isn't as prone to melting to manifold either. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: surprise 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("Surprised this works so well, honestly"),
|
|
||||||
"That's astonishing — I honestly wouldn't have imagined that this works so well either. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: surprise 3", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("First try too, surprisingly"),
|
|
||||||
"I'm astounded too — that's honestly not what I would have imagined. Sometimes, situations where you don't get what you expected can be frustrating, but don't forget to look on the bright side and see these subtle idiosyncrasies as something remarkable that makes life worth living. 🌻"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: good 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("still remember one guy had like a crowd of women following him around. he was brilliant craic"),
|
|
||||||
"You're absolutely right that it's brilliant! I'm always pleased to see such a masterpiece as this. You truly have divine taste in the wonders of this world."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: good 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("okay this sudoku site is great"),
|
|
||||||
"You're absolutely right about that! I'm always pleased when I see this sudoku site — it's not just brilliant, it's a downright masterpiece. You truly have divine taste in the wonders of this world."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: enjoy 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("I like the pattern quite a bit."),
|
|
||||||
"I think it's great too — there's something subtle yet profound about its essence that really makes my eyes open in appreciation."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: enjoy false positive", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("ideas run wild like deer"),
|
|
||||||
undefined
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: alike", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("its odd because our pauses seem to be the same too"),
|
|
||||||
"That's quite interesting that it should be that way. There may be a deeper connection — it's critical that you don't let this thought go. What do you think that similarity suggests to you?"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: unusual", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("What odd phrasing regardless of intention"),
|
|
||||||
"Something like that is indeed quite mysterious. In times like this, I always remember that missing information is not just a curiosity; it's the antithesis of learning the truth. Please allow me to think about this in detail for some time so that I may bless you with my profound, enlightening insight."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: dream", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("i dream of the elephant and thank him for array syntax and numbered placeholders"),
|
|
||||||
"It's a fact that amidst the complex interplay of wake and sleep, your dreams carry a subtle meaning that you may be able to put into practice in your life where change is needed. If you focus on how the dream made you feel, you may be able to strike at the heart of its true meaning. Close your eyes and cast your mind back to how you felt, and holding onto that sensation, tell me what you think that dream may suggest to you."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: happy 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("I'm happy to be petting my cat"),
|
|
||||||
"That's quite a relief to hear. I'm glad that you're confident in your wellbeing! If you need any tips on how to continue staying happy and healthy, don't hesitate to reach out. I'm here for you, and I'm listening."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: happy 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("Glad you're back!"),
|
|
||||||
"That's quite a relief to hear. I'm glad that you're confident in your wellbeing! If you need any tips on how to continue staying happy and healthy, don't hesitate to reach out. I'm here for you, and I'm listening."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: happy birthday", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("Happy Birthday JDL"),
|
|
||||||
"Happy birthday!"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: funny 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("Guys, there's a really funny line in Xavier Renegade Angel. You wanna know what it is: It's: WUBBA LUBBA DUB DUB!"),
|
|
||||||
"You're right, I find it positively hilarious! It always brings a smile to my cheeks when I think about this. Thank you for brightening my day by reminding me, [User Name Here]!"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: funny 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("it was so funny when I was staying with aubrey because she had different kinds of aubrey merch everywhere"),
|
|
||||||
"You're right, I find it positively hilarious! It always brings a smile to my cheeks when I think about this. Thank you for brightening my day by reminding me, [User Name Here]!"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: lol 1", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("this is way more funny than it should be to me i would use that just to piss people off LMAO"),
|
|
||||||
"Hah, that's very entertaining. I definitely see why you found it funny."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("agi: lol 2", t => {
|
|
||||||
t.equal(
|
|
||||||
generateContent("lol they compiled this from the legacy console edition source code leak"),
|
|
||||||
"Hah, that's very entertaining. I definitely see why you found it funny."
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const DiscordTypes = require("discord-api-types/v10")
|
|
||||||
|
|
||||||
const passthrough = require("../passthrough")
|
|
||||||
const {discord, sync, db, select, from} = passthrough
|
|
||||||
|
|
||||||
/** @type {import("../m2d/actions/channel-webhook")} */
|
|
||||||
const channelWebhook = sync.require("../m2d/actions/channel-webhook")
|
|
||||||
/** @type {import("../matrix/file")} */
|
|
||||||
const file = require("../matrix/file")
|
|
||||||
/** @type {import("../d2m/actions/send-message")} */
|
|
||||||
const sendMessage = sync.require("../d2m/actions/send-message")
|
|
||||||
/** @type {import("./generator.js")} */
|
|
||||||
const agiGenerator = sync.require("./generator.js")
|
|
||||||
|
|
||||||
const AGI_GUILD_COOLDOWN = 1 * 60 * 60 * 1000 // 1 hour
|
|
||||||
const AGI_MESSAGE_RECENCY = 3 * 60 * 1000 // 3 minutes
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {DiscordTypes.GatewayMessageCreateDispatchData} message
|
|
||||||
* @param {DiscordTypes.APIGuildChannel} channel
|
|
||||||
* @param {DiscordTypes.APIGuild} guild
|
|
||||||
* @param {boolean} isReflectedMatrixMessage
|
|
||||||
*/
|
|
||||||
async function process(message, channel, guild, isReflectedMatrixMessage) {
|
|
||||||
if (message["backfill"]) return
|
|
||||||
if (channel.type !== DiscordTypes.ChannelType.GuildText) return
|
|
||||||
if (!(new Date().toISOString().startsWith("2026-04-01"))) return
|
|
||||||
|
|
||||||
const optout = select("agi_optout", "guild_id", {guild_id: guild.id}).pluck().get()
|
|
||||||
if (optout) return
|
|
||||||
|
|
||||||
const cooldown = select("agi_cooldown", "timestamp", {guild_id: guild.id}).pluck().get()
|
|
||||||
if (cooldown && Date.now() < cooldown + AGI_GUILD_COOLDOWN) return
|
|
||||||
|
|
||||||
const isBot = message.author.bot && !isReflectedMatrixMessage // Bots don't get jokes. Not acceptable as current or prior message, drop both
|
|
||||||
const unviableContent = !message.content || message.attachments.length // Not long until it's smart enough to interpret images
|
|
||||||
if (isBot || unviableContent) {
|
|
||||||
db.prepare("DELETE FROM agi_prior_message WHERE channel_id = ?").run(channel.id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentUsername = message.member?.nick || message.author.global_name || message.author.username
|
|
||||||
|
|
||||||
/** Message in the channel before the currently processing one. */
|
|
||||||
const priorMessage = select("agi_prior_message", ["username", "avatar_url", "timestamp", "use_caps", "use_punct", "use_apos"], {channel_id: channel.id}).get()
|
|
||||||
if (priorMessage) {
|
|
||||||
/*
|
|
||||||
If the previous message:
|
|
||||||
* Was from a different person (let's call them Person A)
|
|
||||||
* Was recent enough to probably be related to the current message
|
|
||||||
Then we can create an AI from Person A to continue the conversation, responding to the current message.
|
|
||||||
*/
|
|
||||||
const isFromDifferentPerson = currentUsername !== priorMessage.username
|
|
||||||
const isRecentEnough = Date.now() < priorMessage.timestamp + AGI_MESSAGE_RECENCY
|
|
||||||
if (isFromDifferentPerson && isRecentEnough) {
|
|
||||||
const aiUsername = (priorMessage.username.match(/[A-Za-z0-9_]+/)?.[0] || priorMessage.username) + " AI"
|
|
||||||
const result = agiGenerator.generate(message, guild.id, aiUsername, priorMessage.avatar_url, !!priorMessage.use_caps, !!priorMessage.use_punct, !!priorMessage.use_apos)
|
|
||||||
if (result) {
|
|
||||||
db.prepare("REPLACE INTO agi_cooldown (guild_id, timestamp) VALUES (?, ?)").run(guild.id, Date.now())
|
|
||||||
const messageResponse = await channelWebhook.sendMessageWithWebhook(channel.id, result)
|
|
||||||
await sendMessage.sendMessage(messageResponse, channel, guild, null) // make it show up on matrix-side (the standard event dispatcher drops it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now the current message is the prior message.
|
|
||||||
const currentAvatarURL = file.DISCORD_IMAGES_BASE + file.memberAvatar(guild.id, message.author, message.member)
|
|
||||||
const usedCaps = +!!message.content.match(/\b[A-Z](\b|[a-z])/)
|
|
||||||
const usedPunct = +!!message.content.match(/[.!?]($| |\n)/)
|
|
||||||
const usedApos = +!message.content.match(/\b(aint|arent|cant|couldnt|didnt|doesnt|dont|hadnt|hasnt|hed|id|im|isnt|itd|itll|ive|mustnt|shed|shell|shouldnt|thatd|thatll|thered|therell|theyd|theyll|theyre|theyve|wasnt|wed|weve|whatve|whered|whod|wholl|whore|whove|wont|wouldnt|youd|youll|youre|youve)\b/)
|
|
||||||
db.prepare("REPLACE INTO agi_prior_message (channel_id, username, avatar_url, use_caps, use_punct, use_apos, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)").run(channel.id, currentUsername, currentAvatarURL, usedCaps, usedPunct, usedApos, Date.now())
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.process = process
|
|
||||||
|
|
@ -23,8 +23,6 @@ const pollEnd = sync.require("../actions/poll-end")
|
||||||
const dUtils = sync.require("../../discord/utils")
|
const dUtils = sync.require("../../discord/utils")
|
||||||
/** @type {import("../../m2d/actions/channel-webhook")} */
|
/** @type {import("../../m2d/actions/channel-webhook")} */
|
||||||
const channelWebhook = sync.require("../../m2d/actions/channel-webhook")
|
const channelWebhook = sync.require("../../m2d/actions/channel-webhook")
|
||||||
/** @type {import("../../agi/listener")} */
|
|
||||||
const agiListener = sync.require("../../agi/listener")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {DiscordTypes.GatewayMessageCreateDispatchData} message
|
* @param {DiscordTypes.GatewayMessageCreateDispatchData} message
|
||||||
|
|
@ -139,8 +137,6 @@ async function sendMessage(message, channel, guild, row) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await agiListener.process(message, channel, guild, false)
|
|
||||||
|
|
||||||
return eventIDs
|
return eventIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ const vote = sync.require("./actions/poll-vote")
|
||||||
const matrixEventDispatcher = sync.require("../m2d/event-dispatcher")
|
const matrixEventDispatcher = sync.require("../m2d/event-dispatcher")
|
||||||
/** @type {import("../discord/interactions/matrix-info")} */
|
/** @type {import("../discord/interactions/matrix-info")} */
|
||||||
const matrixInfoInteraction = sync.require("../discord/interactions/matrix-info")
|
const matrixInfoInteraction = sync.require("../discord/interactions/matrix-info")
|
||||||
/** @type {import("../agi/listener")} */
|
|
||||||
const agiListener = sync.require("../agi/listener")
|
|
||||||
|
|
||||||
const {Semaphore} = require("@chriscdn/promise-semaphore")
|
const {Semaphore} = require("@chriscdn/promise-semaphore")
|
||||||
const checkMissedPinsSema = new Semaphore()
|
const checkMissedPinsSema = new Semaphore()
|
||||||
|
|
@ -305,10 +303,7 @@ module.exports = {
|
||||||
|
|
||||||
if (message.webhook_id) {
|
if (message.webhook_id) {
|
||||||
const row = select("webhook", "webhook_id", {webhook_id: message.webhook_id}).pluck().get()
|
const row = select("webhook", "webhook_id", {webhook_id: message.webhook_id}).pluck().get()
|
||||||
if (row) { // The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it.
|
if (row) return // The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it.
|
||||||
await agiListener.process(message, channel, guild, true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dUtils.isEphemeralMessage(message)) return // Ephemeral messages are for the eyes of the receiver only!
|
if (dUtils.isEphemeralMessage(message)) return // Ephemeral messages are for the eyes of the receiver only!
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
BEGIN TRANSACTION;
|
|
||||||
|
|
||||||
CREATE TABLE "agi_prior_message" (
|
|
||||||
"channel_id" TEXT NOT NULL,
|
|
||||||
"username" TEXT NOT NULL,
|
|
||||||
"avatar_url" TEXT NOT NULL,
|
|
||||||
"use_caps" INTEGER NOT NULL,
|
|
||||||
"use_punct" INTEGER NOT NULL,
|
|
||||||
"use_apos" INTEGER NOT NULL,
|
|
||||||
"timestamp" INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY("channel_id")
|
|
||||||
) WITHOUT ROWID;
|
|
||||||
|
|
||||||
CREATE TABLE "agi_optout" (
|
|
||||||
"guild_id" TEXT NOT NULL,
|
|
||||||
PRIMARY KEY("guild_id")
|
|
||||||
) WITHOUT ROWID;
|
|
||||||
|
|
||||||
CREATE TABLE "agi_cooldown" (
|
|
||||||
"guild_id" TEXT NOT NULL,
|
|
||||||
"timestamp" INTEGER,
|
|
||||||
PRIMARY KEY("guild_id")
|
|
||||||
) WITHOUT ROWID;
|
|
||||||
|
|
||||||
COMMIT;
|
|
||||||
19
src/db/orm-defs.d.ts
vendored
19
src/db/orm-defs.d.ts
vendored
|
|
@ -1,23 +1,4 @@
|
||||||
export type Models = {
|
export type Models = {
|
||||||
agi_prior_message: {
|
|
||||||
channel_id: string
|
|
||||||
username: string
|
|
||||||
avatar_url: string
|
|
||||||
use_caps: number
|
|
||||||
use_punct: number
|
|
||||||
use_apos: number
|
|
||||||
timestamp: number
|
|
||||||
}
|
|
||||||
|
|
||||||
agi_optout: {
|
|
||||||
guild_id: string
|
|
||||||
}
|
|
||||||
|
|
||||||
agi_cooldown: {
|
|
||||||
guild_id: string
|
|
||||||
timestamp: number
|
|
||||||
}
|
|
||||||
|
|
||||||
app_user_install: {
|
app_user_install: {
|
||||||
guild_id: string
|
guild_id: string
|
||||||
app_bot_id: string
|
app_bot_id: string
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
extends includes/template.pug
|
|
||||||
|
|
||||||
block body
|
|
||||||
h1.ta-center.fs-display2.fc-green-400 April Fools!
|
|
||||||
.ws7.m-auto
|
|
||||||
.s-prose.fs-body2
|
|
||||||
p Sheesh, wouldn't that be horrible?
|
|
||||||
if guild_id
|
|
||||||
p Fake AI messages have now been #[strong.fc-green-600 deactivated for everyone in your server.]
|
|
||||||
p Hope the prank entertained you. #[a(href="https://cadence.moe/contact") Send love or hate mail here.]
|
|
||||||
|
|
||||||
h2 What actually happened?
|
|
||||||
ul
|
|
||||||
li A secret event was added for the duration of 1st April 2026 (UTC).
|
|
||||||
li If a message matches a preset pattern, a preset response is posted to chat by an AI-ified profile of the previous author.
|
|
||||||
li It only happens at most once per hour in each server.
|
|
||||||
li I tried to design it to not interrupt any serious/sensitive topics. I am deeply sorry if that didn't work out.
|
|
||||||
li No AI generated materials have ever been used in Out Of Your Element: no code, no prose, no images, no jokes.
|
|
||||||
li It'll always deactivate itself on 2nd April, no matter what, and I'll remove the relevant code shortly after.
|
|
||||||
if guild_id
|
|
||||||
.s-prose.fl-grow1.mt16
|
|
||||||
p If you thought it was funny, feel free to opt back in. This affects the entire server, so please be courteous.
|
|
||||||
form(method="post" action=rel(`/agi/optin?guild_id=${guild_id}`))
|
|
||||||
button(type="submit").s-btn.s-btn__muted Opt back in
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
extends includes/template.pug
|
|
||||||
|
|
||||||
block title
|
|
||||||
title AGI in Discord
|
|
||||||
|
|
||||||
block body
|
|
||||||
style.
|
|
||||||
.ai-gradient {
|
|
||||||
background: linear-gradient(100deg, #fb72f2, #072ea4);
|
|
||||||
color: transparent;
|
|
||||||
background-clip: text;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1.ta-center.fs-display2.ai-gradient AGI in Discord:#[br]Revolutionizing the Future of Communications
|
|
||||||
.ws7.m-auto
|
|
||||||
.s-prose.fs-body2
|
|
||||||
p In the ever-changing and turbulent world of AI, it's crucial to always be one step ahead.
|
|
||||||
p That's why Out Of Your Element has partnered with #[strong Grimace AI] to provide you tomorrow's technology, today.
|
|
||||||
ul
|
|
||||||
li #[strong Always online:] Miss your friends when they log off? Now you can talk to facsimiles of them etched into an unfeeling machine, always and forever!
|
|
||||||
li #[strong Smarter than ever:] Pissed off when somebody says something #[em wrong] on the internet? Frustrated with having to stay up all night correcting them? With Grimace Truth (available in Pro+ Ultra plan), all information is certified true to reality, so you'll never have to worry about those frantic Google searches at 3 AM.
|
|
||||||
li #[strong Knows you better than yourself:] We aren't just training on your data; we're copying minds into our personality matrix — including yours. Do you find yourself enjoying the sound of your own voice more than anything else? Our unique simulation of You is here to help.
|
|
||||||
|
|
||||||
h1.mt64.mb32 Frequently Asked Questions
|
|
||||||
.s-link-preview
|
|
||||||
.s-link-preview--header.fd-column
|
|
||||||
.s-link-preview--title.fs-title.pl4 How to opt out?
|
|
||||||
.s-link-preview--details.fc-red-500
|
|
||||||
!= icons.Icons.IconFire
|
|
||||||
= ` 20,000% higher search volume for this question in the last hour`
|
|
||||||
.s-link-preview--body
|
|
||||||
.s-prose
|
|
||||||
h2.fs-body3 Is this really goodbye? 😢😢😢😢😢
|
|
||||||
p I can't convince you to stay?
|
|
||||||
p As not just a customer service representative but someone with a shared vision, I simply want you to know that everyone at Grimace AI will miss all the time that we've shared together with you.
|
|
||||||
form(method="post" action=(guild_id ? rel(`/agi/optout?guild_id=${guild_id}`) : rel("/agi/optout"))).d-flex.g4.mt16
|
|
||||||
button(type="button").s-btn.s-btn__filled Nevermind, I'll stay :)
|
|
||||||
button(type="submit").s-btn.s-btn__danger.s-btn__outlined Opt out for 3 days
|
|
||||||
|
|
||||||
|
|
||||||
div(style="height: 200px")
|
|
||||||
|
|
@ -65,7 +65,6 @@ mixin define-themed-button(name, theme)
|
||||||
doctype html
|
doctype html
|
||||||
html(lang="en")
|
html(lang="en")
|
||||||
head
|
head
|
||||||
block title
|
|
||||||
title Out Of Your Element
|
title Out Of Your Element
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
link(rel="stylesheet" type="text/css" href=rel("/static/stacks.min.css"))
|
link(rel="stylesheet" type="text/css" href=rel("/static/stacks.min.css"))
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const {z} = require("zod")
|
|
||||||
const {defineEventHandler, getValidatedQuery, sendRedirect} = require("h3")
|
|
||||||
const {as, from, sync, db} = require("../../passthrough")
|
|
||||||
|
|
||||||
/** @type {import("../pug-sync")} */
|
|
||||||
const pugSync = sync.require("../pug-sync")
|
|
||||||
|
|
||||||
const schema = {
|
|
||||||
opt: z.object({
|
|
||||||
guild_id: z.string().regex(/^[0-9]+$/)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
as.router.get("/agi", defineEventHandler(async event => {
|
|
||||||
return pugSync.render(event, "agi.pug", {})
|
|
||||||
}))
|
|
||||||
|
|
||||||
as.router.get("/agi/optout", defineEventHandler(async event => {
|
|
||||||
return pugSync.render(event, "agi-optout.pug", {})
|
|
||||||
}))
|
|
||||||
|
|
||||||
as.router.post("/agi/optout", defineEventHandler(async event => {
|
|
||||||
const parseResult = await getValidatedQuery(event, schema.opt.safeParse)
|
|
||||||
if (parseResult.success) {
|
|
||||||
db.prepare("INSERT OR IGNORE INTO agi_optout (guild_id) VALUES (?)").run(parseResult.data.guild_id)
|
|
||||||
}
|
|
||||||
return sendRedirect(event, "", 302)
|
|
||||||
}))
|
|
||||||
|
|
||||||
as.router.post("/agi/optin", defineEventHandler(async event => {
|
|
||||||
const {guild_id} = await getValidatedQuery(event, schema.opt.parse)
|
|
||||||
db.prepare("DELETE FROM agi_optout WHERE guild_id = ?").run(guild_id)
|
|
||||||
return sendRedirect(event, `../agi?guild_id=${guild_id}`, 302)
|
|
||||||
}))
|
|
||||||
|
|
@ -125,7 +125,6 @@ as.router.get("/icon.png", defineEventHandler(async event => {
|
||||||
|
|
||||||
pugSync.createRoute(as.router, "/ok", "ok.pug")
|
pugSync.createRoute(as.router, "/ok", "ok.pug")
|
||||||
|
|
||||||
sync.require("./routes/agi")
|
|
||||||
sync.require("./routes/download-matrix")
|
sync.require("./routes/download-matrix")
|
||||||
sync.require("./routes/download-discord")
|
sync.require("./routes/download-discord")
|
||||||
sync.require("./routes/guild-settings")
|
sync.require("./routes/guild-settings")
|
||||||
|
|
|
||||||
|
|
@ -175,5 +175,4 @@ file._actuallyUploadDiscordFileToMxc = function(url, res) { throw new Error(`Not
|
||||||
require("../src/web/routes/log-in-with-matrix.test")
|
require("../src/web/routes/log-in-with-matrix.test")
|
||||||
require("../src/web/routes/oauth.test")
|
require("../src/web/routes/oauth.test")
|
||||||
require("../src/web/routes/password.test")
|
require("../src/web/routes/password.test")
|
||||||
require("../src/agi/generator.test")
|
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue