From 0b32a041f73370600ec9cb0f8cc681ebb5ee6726 Mon Sep 17 00:00:00 2001 From: alextitonis Date: Mon, 1 Aug 2022 11:29:15 +0300 Subject: [PATCH 1/3] added description to entity variables --- .../spells/windows/EntityWindow.tsx | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/client/src/workspaces/spells/windows/EntityWindow.tsx b/packages/client/src/workspaces/spells/windows/EntityWindow.tsx index f2a4eed8..7da0149e 100644 --- a/packages/client/src/workspaces/spells/windows/EntityWindow.tsx +++ b/packages/client/src/workspaces/spells/windows/EntityWindow.tsx @@ -877,7 +877,9 @@ const EntityWindow = ({ id, updateCallback }) => {
- Voice Default Phrases + + Voice Default Phrases - Separate using | (n1|n2|...|nN) + { {voice_provider === 'tiktalknet' && (
- Tiktalknet URL + + Tiktalknet URL - URL where Tiktalknet is hosted and the requests + will be sent there + {
- Discord Starting Words + + Discord Starting Words - Separated by , + {
- Discord Empty Responses + + Discord Empty Responses - Separated by | + {
- Empty Responses + + Empty Responses - Separated by | + { />
- Twitter Enable Twits + Twitter Enable Tweets { />
- Twitter Tweet Rules + + Twitter Tweet Rules - Regex rules for tweets to answer + automatically, Separated by , + {
- Twitter Auto Start Phrases + Twitter Auto Start Phrases - Separated by | { />
- Empty Responses + + Empty Responses - Separated by | + Date: Mon, 1 Aug 2022 16:05:38 +0300 Subject: [PATCH 2/3] updates on twitter --- .../spells/windows/EntityWindow.tsx | 47 ++++---- packages/core/src/components/components.ts | 2 + .../entities/CustomTextCompletion.ts | 6 - .../components/entities/InputDestructure.ts | 9 ++ .../components/utility/VariableReplacer.ts | 106 ++++++++++++++++++ .../server/src/databases/models/entities.ts | 14 +-- .../server/src/entities/CreateSpellHandler.ts | 4 +- packages/server/src/entities/Entity.ts | 14 ++- .../src/entities/connectors/discord-voice.ts | 3 +- .../server/src/entities/connectors/discord.ts | 6 +- .../src/entities/connectors/handleInput.ts | 4 +- .../src/entities/connectors/instagram.ts | 3 +- .../src/entities/connectors/messenger.ts | 3 +- .../server/src/entities/connectors/reddit.ts | 15 ++- .../server/src/entities/connectors/slack.ts | 3 +- .../src/entities/connectors/telegram.ts | 6 +- .../server/src/entities/connectors/twilio.ts | 3 +- .../server/src/entities/connectors/twitter.ts | 76 +++++-------- .../src/entities/connectors/xrengine.ts | 3 +- .../server/src/entities/connectors/zoom.ts | 3 +- 20 files changed, 227 insertions(+), 103 deletions(-) create mode 100644 packages/core/src/components/utility/VariableReplacer.ts diff --git a/packages/client/src/workspaces/spells/windows/EntityWindow.tsx b/packages/client/src/workspaces/spells/windows/EntityWindow.tsx index 7da0149e..4dd45f7a 100644 --- a/packages/client/src/workspaces/spells/windows/EntityWindow.tsx +++ b/packages/client/src/workspaces/spells/windows/EntityWindow.tsx @@ -88,12 +88,11 @@ const EntityWindow = ({ id, updateCallback }) => { useState('') const [twitter_auto_tweet_interval_max, setTwitterAutoTweetIntervalMax] = useState('') - const [twitter_auto_tweet_start_phrases, setTwitterAutoTweetStartPhrases] = - useState('') const [twitter_bot_name, setTwitterBotName] = useState('') const [twitter_bot_name_regex, setTwitterBotNameRegex] = useState('') const [twitter_spell_handler_incoming, setTwitterSpellHandlerIncoming] = useState('') + const [twitter_spell_handler_auto, setTwitterSpellHandlerAuto] = useState('') const [telegram_enabled, setTelegramEnabled] = useState('') const [telegram_bot_token, setTelegramBotToken] = useState('') @@ -256,12 +255,10 @@ const EntityWindow = ({ id, updateCallback }) => { setTwitterTweetRules(res.data.twitter_tweet_rules) setTwitterAutoTweetIntervalMin(res.data.twitter_auto_tweet_interval_min) setTwitterAutoTweetIntervalMax(res.data.twitter_auto_tweet_interval_max) - setTwitterAutoTweetStartPhrases( - res.data.twitter_auto_tweet_start_phrases - ) setTwitterBotName(res.data.twitter_bot_name) setTwitterBotNameRegex(res.data.twitter_bot_name_regex) setTwitterSpellHandlerIncoming(res.data.twitter_spell_handler_incoming) + setTwitterSpellHandlerAuto(res.data.twitter_spell_handler_auto) setTelegramEnabled(res.data.telegram_enabled === true) setTelegramBotToken(res.data.telegram_bot_token) @@ -403,10 +400,10 @@ const EntityWindow = ({ id, updateCallback }) => { twitter_tweet_rules, twitter_auto_tweet_interval_min, twitter_auto_tweet_interval_max, - twitter_auto_tweet_start_phrases, twitter_bot_name, twitter_bot_name_regex, twitter_spell_handler_incoming, + twitter_spell_handler_auto, telegram_enabled, telegram_bot_token, telegram_bot_name, @@ -515,14 +512,12 @@ const EntityWindow = ({ id, updateCallback }) => { setTwitterAutoTweetIntervalMax( responseData.twitter_auto_tweet_interval_max ) - setTwitterAutoTweetStartPhrases( - responseData.twitter_auto_tweet_start_phrases - ) setTwitterBotName(responseData.twitter_bot_name) setTwitterBotNameRegex(responseData.twitter_bot_name_regex) setTwitterSpellHandlerIncoming( responseData.twitter_spell_handler_incoming ) + setTwitterSpellHandlerAuto(responseData.twitter_spell_handler_auto) setTelegramEnabled(responseData.telegram_enabled) setTelegramBotToken(responseData.telegram_bot_token) @@ -641,10 +636,10 @@ const EntityWindow = ({ id, updateCallback }) => { twitter_tweet_rules, twitter_auto_tweet_interval_min, twitter_auto_tweet_interval_max, - twitter_auto_tweet_start_phrases, twitter_bot_name, twitter_bot_name_regex, twitter_spell_handler_incoming, + twitter_spell_handler_auto, telegram_enabled, telegram_bot_token, telegram_bot_name, @@ -1335,18 +1330,6 @@ const EntityWindow = ({ id, updateCallback }) => { }} />
-
- - Twitter Auto Start Phrases - Separated by | - - { - setTwitterAutoTweetStartPhrases(e.target.value) - }} - /> -
Bot Name { ))}
+
+ + Spell Handler (Auto tweets) + + +
)} diff --git a/packages/core/src/components/components.ts b/packages/core/src/components/components.ts index 813a0e46..62cabd35 100644 --- a/packages/core/src/components/components.ts +++ b/packages/core/src/components/components.ts @@ -71,6 +71,7 @@ import { DocumentSetMass } from './search/DocumentSetMass' import { RSSGet } from './search/RSSGet' import { CustomTextCompletion } from './entities/CustomTextCompletion' import { IsQuery } from './logic/IsQuery' +import { VariableReplacer } from './utility/VariableReplacer' // Here we load up all components of the builder into our editor for usage. // We might be able to programatically generate components from enki @@ -91,6 +92,7 @@ export const components = { entityDetector: () => new EntityDetector(), complexStringMatcher: () => new ComplexStringMatcher(), echo: () => new Echo(), + variableReplacer: () => new VariableReplacer(), SummarizeFacts: () => new SummarizeFacts(), textToSpeech: () => new TextToSpeech(), agentTextCompletion: () => new AgentTextCompletion(), diff --git a/packages/core/src/components/entities/CustomTextCompletion.ts b/packages/core/src/components/entities/CustomTextCompletion.ts index 43bc61ff..47440f9b 100644 --- a/packages/core/src/components/entities/CustomTextCompletion.ts +++ b/packages/core/src/components/entities/CustomTextCompletion.ts @@ -158,12 +158,6 @@ export class CustomTextCompletion extends ThothComponent< data += (inputs['Static Chat'] as string) ?? '' + '\n' data += inputs['Chat'] data += '\n' + agent + ':' - data = data - .replace(/ai/g, agent) - .replace(/agent/g, agent) - .replace(/human/g, speaker) - .replace(/speaker/g, speaker) - .replace(/\n/g, '\n') const settings = ((rawInputs.settings && rawInputs.settings[0]) ?? {}) as any diff --git a/packages/core/src/components/entities/InputDestructure.ts b/packages/core/src/components/entities/InputDestructure.ts index 5dfadf4b..7658432c 100644 --- a/packages/core/src/components/entities/InputDestructure.ts +++ b/packages/core/src/components/entities/InputDestructure.ts @@ -32,6 +32,7 @@ type InputReturn = { isBot: boolean info3d: string }[] + channel_type: string } export class InputDestructureComponent extends ThothComponent< @@ -52,6 +53,7 @@ export class InputDestructureComponent extends ThothComponent< channel: 'output', entity: 'output', roomInfo: 'output', + channel_type: 'output', trigger: 'option', }, init: (task = {} as Task, node: ThothNode) => { @@ -78,6 +80,11 @@ export class InputDestructureComponent extends ThothComponent< const channelId = new Rete.Output('channel', 'channel', stringSocket) const entity = new Rete.Output('entity', 'entity', stringSocket) const roomInfo = new Rete.Output('roomInfo', 'roomInfo', arraySocket) + const channel_type = new Rete.Output( + 'channel_type', + 'channel_type', + stringSocket + ) const dataOutput = new Rete.Output('trigger', 'Trigger', triggerSocket) return node @@ -89,6 +96,7 @@ export class InputDestructureComponent extends ThothComponent< .addOutput(channelId) .addOutput(entity) .addOutput(roomInfo) + .addOutput(channel_type) .addOutput(out) .addOutput(dataOutput) } @@ -115,6 +123,7 @@ export class InputDestructureComponent extends ThothComponent< channel: (input as any)['ChannelID'] ?? 'TestChannel', entity: (input as any)['Entity'], roomInfo: (input as any)['RoomInfo'], + channel_type: (input as any)['Channel'], } } } diff --git a/packages/core/src/components/utility/VariableReplacer.ts b/packages/core/src/components/utility/VariableReplacer.ts new file mode 100644 index 00000000..05434ca1 --- /dev/null +++ b/packages/core/src/components/utility/VariableReplacer.ts @@ -0,0 +1,106 @@ +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' + +/* eslint-disable no-async-promise-executor */ +/* eslint-disable camelcase */ +/* eslint-disable @typescript-eslint/no-inferrable-types */ +/* eslint-disable no-console */ +/* eslint-disable require-await */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import axios from 'axios' +import Rete from 'rete' + +import { + NodeData, + ThothNode, + ThothWorkerInputs, + ThothWorkerOutputs, + EngineContext, +} from '../../../types' +import { InputControl } from '../../dataControls/InputControl' +import { SocketGeneratorControl } from '../../dataControls/SocketGenerator' +import { triggerSocket, stringSocket, anySocket } from '../../sockets' +import { ThothComponent } from '../../thoth-component' + +const info = + 'Variable Replacer is used to replace keywords with new values in a text input.' + +type WorkerReturn = { + output: string +} + +export class VariableReplacer extends ThothComponent> { + constructor() { + super('Variable Replacer') + + this.task = { + outputs: { + output: 'output', + trigger: 'option', + }, + } + + this.category = 'Agents' + this.display = true + this.info = info + } + + builder(node: ThothNode) { + const strInput = new Rete.Input('inp', 'Input', stringSocket) + const agentInput = new Rete.Input('agent', 'Agent', stringSocket) + const speakerInput = new Rete.Input('speaker', 'Speaker', stringSocket) + const dataInput = new Rete.Input('trigger', 'Trigger', triggerSocket, true) + const dataOutput = new Rete.Output('trigger', 'Trigger', triggerSocket) + const outp = new Rete.Output('output', 'output', stringSocket) + + const inputGenerator = new SocketGeneratorControl({ + connectionType: 'input', + name: 'Input Sockets', + ignored: ['trigger'], + }) + + node.inspector.add(inputGenerator) + + return node + .addInput(strInput) + .addInput(agentInput) + .addInput(speakerInput) + .addInput(dataInput) + .addOutput(dataOutput) + .addOutput(outp) + } + + async worker( + node: NodeData, + rawInputs: ThothWorkerInputs, + outputs: ThothWorkerOutputs, + { silent, thoth }: { silent: boolean; thoth: EngineContext } + ) { + let input = rawInputs['inp'][0] as string + const agent = rawInputs['agent'][0] as string + const speaker = rawInputs['speaker'][0] as string + const inputs: any = Object.entries(rawInputs).reduce( + (acc, [key, value]) => { + console.log('key:', key, 'value:', value) + acc[key] = value[0] + return acc + }, + {} as Record + ) + + for (const key in inputs) { + if (input.includes(key)) { + if (key === 'agent') { + input = input.replace(key, agent) + } else if (key === 'speaker') { + input = input.replace(key, speaker) + } else { + input = input.replace(key, inputs[key]) + } + } + } + + return { + output: input, + } + } +} diff --git a/packages/server/src/databases/models/entities.ts b/packages/server/src/databases/models/entities.ts index b906881e..924bba55 100644 --- a/packages/server/src/databases/models/entities.ts +++ b/packages/server/src/databases/models/entities.ts @@ -45,10 +45,10 @@ export interface entitiesAttributes { twitter_tweet_rules?: string twitter_auto_tweet_interval_min?: string twitter_auto_tweet_interval_max?: string - twitter_auto_tweet_start_phrases?: string twitter_bot_name?: string twitter_bot_name_regex?: string twitter_spell_handler_incoming?: string + twitter_spell_handler_auto?: string telegram_enabled?: boolean telegram_bot_token?: string telegram_bot_name?: string @@ -136,10 +136,10 @@ export type entitiesOptionalAttributes = | 'twitter_tweet_rules' | 'twitter_auto_tweet_interval_min' | 'twitter_auto_tweet_interval_max' - | 'twitter_auto_tweet_start_phrases' | 'twitter_bot_name' | 'twitter_bot_name_regex' | 'twitter_spell_handler_incoming' + | 'twitter_spell_handler_auto' | 'telegram_enabled' | 'telegram_bot_token' | 'telegram_bot_name' @@ -240,10 +240,10 @@ export class entities twitter_tweet_rules?: string twitter_auto_tweet_interval_min?: string twitter_auto_tweet_interval_max?: string - twitter_auto_tweet_start_phrases?: string twitter_bot_name?: string twitter_bot_name_regex?: string twitter_spell_handler_incoming?: string + twitter_spell_handler_auto?: string telegram_enabled?: boolean telegram_bot_token?: string telegram_bot_name?: string @@ -465,10 +465,6 @@ export class entities type: DataTypes.TEXT, allowNull: true, }, - twitter_auto_tweet_start_phrases: { - type: DataTypes.TEXT, - allowNull: true, - }, twitter_bot_name: { type: DataTypes.TEXT, allowNull: true, @@ -481,6 +477,10 @@ export class entities type: DataTypes.TEXT, allowNull: true, }, + twitter_spell_handler_auto: { + type: DataTypes.TEXT, + allowNull: true, + }, telegram_enabled: { type: DataTypes.BOOLEAN, allowNull: true, diff --git a/packages/server/src/entities/CreateSpellHandler.ts b/packages/server/src/entities/CreateSpellHandler.ts index 053825f9..8c1626ea 100644 --- a/packages/server/src/entities/CreateSpellHandler.ts +++ b/packages/server/src/entities/CreateSpellHandler.ts @@ -138,7 +138,8 @@ export const CreateSpellHandler = async (props: { inConversation: boolean isBot: boolean info3d: string - }[] + }[], + channel: string ) { const spellInputs = { Input: message, @@ -148,6 +149,7 @@ export const CreateSpellHandler = async (props: { ChannelID: channelId, Entity: entity, RoomInfo: roomInfo, + Channel: channel, } as any // TODO: Remove this line diff --git a/packages/server/src/entities/Entity.ts b/packages/server/src/entities/Entity.ts index c09f95f9..ab888298 100644 --- a/packages/server/src/entities/Entity.ts +++ b/packages/server/src/entities/Entity.ts @@ -155,10 +155,10 @@ export class Entity { twitter_tweet_rules: any, twitter_auto_tweet_interval_min: any, twitter_auto_tweet_interval_max: any, - twitter_auto_tweet_start_phrases: any, twitter_bot_name: any, twitter_bot_name_regex: any, twitter_spell_handler_incoming: any, + twitter_spell_handler_auto: any, spell_version: string, entity: any ) { @@ -172,11 +172,16 @@ export class Entity { spell: twitter_spell_handler_incoming, version: spell_version, }) + const spellHandlerAuto = await CreateSpellHandler({ + spell: twitter_spell_handler_auto, + version: spell_version, + }) this.twitter = new twitter_client() console.log('createTwitterClient') await this.twitter.createTwitterClient( spellHandler, + spellHandlerAuto, { twitter_token, twitter_id, @@ -188,10 +193,10 @@ export class Entity { twitter_tweet_rules, twitter_auto_tweet_interval_min, twitter_auto_tweet_interval_max, - twitter_auto_tweet_start_phrases, twitter_bot_name, twitter_bot_name_regex, twitter_spell_handler_incoming, + twitter_spell_handler_auto, }, entity ) @@ -346,7 +351,8 @@ export class Entity { 'loop', 'loop', this, - [] + [], + 'auto' ) if (resp && (resp as string)?.length > 0) { console.log('Loop Response:', resp) @@ -666,10 +672,10 @@ export class Entity { data.twitter_tweet_rules, data.twitter_auto_tweet_interval_min, data.twitter_auto_tweet_interval_max, - data.twitter_auto_tweet_start_phrases, data.twitter_bot_name, data.twitter_bot_name_regex, data.twitter_spell_handler_incoming, + data.twitter_spell_handler_auto, data.spell_version, data ) diff --git a/packages/server/src/entities/connectors/discord-voice.ts b/packages/server/src/entities/connectors/discord-voice.ts index e5ae7a8f..e2b3cdce 100644 --- a/packages/server/src/entities/connectors/discord-voice.ts +++ b/packages/server/src/entities/connectors/discord-voice.ts @@ -62,7 +62,8 @@ export function initSpeechClient( 'discord', channel.id, entity, - roomInfo + roomInfo, + 'voice' ) ) if (response === undefined || !response || response.length <= 0) { diff --git a/packages/server/src/entities/connectors/discord.ts b/packages/server/src/entities/connectors/discord.ts index 7c4e07a1..389f3a38 100644 --- a/packages/server/src/entities/connectors/discord.ts +++ b/packages/server/src/entities/connectors/discord.ts @@ -436,7 +436,8 @@ export class discord_client { 'discord', message.channel.id, this.entity, - roomInfo + roomInfo, + 'msg' ) this.handlePingSoloAgent(message.channel.id, message.id, response, false) @@ -1330,7 +1331,8 @@ export class discord_client { inConversation: boolean isBot: boolean info3d: string - }[] + }[], + channel: string ) => Promise, use_voice, voice_provider, diff --git a/packages/server/src/entities/connectors/handleInput.ts b/packages/server/src/entities/connectors/handleInput.ts index 37a6ec34..0308ecc5 100644 --- a/packages/server/src/entities/connectors/handleInput.ts +++ b/packages/server/src/entities/connectors/handleInput.ts @@ -12,7 +12,8 @@ export async function handleInput( channelId: string, entity: number, spell_handler: string, - spell_version: string = 'latest' + spell_version: string = 'latest', + channel: string = 'msg' ) { if (spell_handler === undefined) { spell_handler = 'default' @@ -33,6 +34,7 @@ export async function handleInput( Client: client, ChannelID: channelId, Entity: entity, + Channel: channel, }, }) let index = undefined diff --git a/packages/server/src/entities/connectors/instagram.ts b/packages/server/src/entities/connectors/instagram.ts index 182373da..3a7d60e5 100644 --- a/packages/server/src/entities/connectors/instagram.ts +++ b/packages/server/src/entities/connectors/instagram.ts @@ -43,7 +43,8 @@ export class instagram_client { 'instagram', thread_v2_id, settings.entity, - [] + [], + 'msg' ) console.log('resp of spellHandler ::: ', resp) const thread = ig.entity.directThread(userIds) diff --git a/packages/server/src/entities/connectors/messenger.ts b/packages/server/src/entities/connectors/messenger.ts index 7e836959..811fc33f 100644 --- a/packages/server/src/entities/connectors/messenger.ts +++ b/packages/server/src/entities/connectors/messenger.ts @@ -25,7 +25,8 @@ export class messenger_client { 'messenger', senderPsid, null, - [] + [], + 'msg' ) this.callSendAPI(senderPsid, { text: resp }, resp) } diff --git a/packages/server/src/entities/connectors/reddit.ts b/packages/server/src/entities/connectors/reddit.ts index 29318ddb..8f88e640 100644 --- a/packages/server/src/entities/connectors/reddit.ts +++ b/packages/server/src/entities/connectors/reddit.ts @@ -162,7 +162,8 @@ export class reddit_client { 'reddit', chat_id, this.entity, - [] + [], + 'msg' ) await this.handleMessage(resp, id, chat_id, 'isPost', reddit) } else { @@ -178,7 +179,8 @@ export class reddit_client { 'reddit', chat_id, this.entity, - [] + [], + 'msg' ) await this.handleMessage(resp, id, chat_id, 'isPost', reddit) } @@ -207,7 +209,8 @@ export class reddit_client { 'reddit', chat_id, this.entity, - [] + [], + 'msg' ) await this.handleMessage(resp, id, chat_id, 'isPost', reddit) } else { @@ -223,7 +226,8 @@ export class reddit_client { 'reddit', chat_id, this.entity, - [] + [], + 'msg' ) await this.handleMessage(resp, id, chat_id, 'isPost', reddit) } @@ -243,7 +247,8 @@ export class reddit_client { 'reddit', chat_id, this.entity, - [] + [], + 'msg' ) await this.handleMessage(resp, id, chat_id, 'isChat', reddit) } diff --git a/packages/server/src/entities/connectors/slack.ts b/packages/server/src/entities/connectors/slack.ts index 1fd0aaa8..1e5dc13e 100644 --- a/packages/server/src/entities/connectors/slack.ts +++ b/packages/server/src/entities/connectors/slack.ts @@ -89,7 +89,8 @@ export class slack_client { 'slack', channel, this.entity, - [] + [], + 'msg' ) say(response) }) diff --git a/packages/server/src/entities/connectors/telegram.ts b/packages/server/src/entities/connectors/telegram.ts index 4b824f76..fec87a7f 100644 --- a/packages/server/src/entities/connectors/telegram.ts +++ b/packages/server/src/entities/connectors/telegram.ts @@ -165,7 +165,8 @@ export class telegram_client { 'telegram', msg.chat.id, this.entity, - [] + [], + 'msg' ) this.handleEditMessage( msg.chat.id, @@ -303,7 +304,8 @@ export class telegram_client { 'telegram', msg.chat.id, this.entity, - [] + [], + 'msg' ) console.log('GOT RESPONSE:', resp) this.handleEditMessage( diff --git a/packages/server/src/entities/connectors/twilio.ts b/packages/server/src/entities/connectors/twilio.ts index 60eb92bb..d64b9efe 100644 --- a/packages/server/src/entities/connectors/twilio.ts +++ b/packages/server/src/entities/connectors/twilio.ts @@ -44,7 +44,8 @@ export class twilio_client { 'twilio', req.body.From, this.settings.entity, - [] + [], + 'msg' ) await this.handleTwilioMsg(req.body.From, resp) } diff --git a/packages/server/src/entities/connectors/twitter.ts b/packages/server/src/entities/connectors/twitter.ts index 7d7d6fc7..c9fdd847 100644 --- a/packages/server/src/entities/connectors/twitter.ts +++ b/packages/server/src/entities/connectors/twitter.ts @@ -7,7 +7,6 @@ import { database } from '../../database' import { TwitterApi, ETwitterStreamEvent } from 'twitter-api-v2' -import { handleInput } from './handleInput' import { randomInt } from './utils' function log(...s: (string | boolean)[]) { @@ -40,36 +39,33 @@ const createTwitterClientV2 = (bearerKey: string) => { export class twitter_client { automatic_tweet = async spellHandler => { - const interval = - randomInt( + const interval = 6000 + /*randomInt( this.twitter_auto_tweet_interval_min, this.twitter_auto_tweet_interval_max - ) * 60000 - sleep(interval) - - const input = - this.twitter_auto_tweet_start_phrases[ - randomInt(0, this.twitter_auto_tweet_start_phrases.length - 1) - ] + ) * 60000*/ + console.log('await interval:', interval) + await sleep(interval) const resp = await spellHandler( - input, + '', 'user', this.settings.twitter_bot_name ?? 'Agent', 'twitter', 'auto_tweet', this.settings.entity, - [] + [], + 'auto' ) console.log('generated automatic tweet:', resp) - this.twitterv1.v1.tweet(resp) - this.automatic_tweet(spellHandler) + //this.twitterv1.v1.tweet(resp) + //this.automatic_tweet(spellHandler) } - async handleMessage(response, chat_id, args, twitter, twitterV1, localUser) { + async handleMessage(response, chat_id, args) { if (args === 'DM') { - const dmSent = await twitterV1.v1.sendDm({ + const dmSent = await this.twitterV1.v1.sendDm({ recipient_id: chat_id, text: response, }) @@ -96,17 +92,23 @@ export class twitter_client { twitterv1: TwitterApi twitterv2: TwitterApi spellHandler + spellHandlerAuto settings entity twitter_enable_twits: boolean = false twitter_tweet_rules: string = '' twitter_auto_tweet_interval_min: number = 0 twitter_auto_tweet_interval_max: number = 0 - twitter_auto_tweet_start_phrases: string[] = [] - createTwitterClient = async (spellHandler, settings, entity) => { + createTwitterClient = async ( + spellHandler, + spellHandlerAuto, + settings, + entity + ) => { console.log('TWITTER SETTINGS:', settings) this.spellHandler = spellHandler + this.spellHandlerAuto = spellHandlerAuto this.settings = settings this.entity = entity this.twitter_enable_twits = @@ -129,14 +131,6 @@ export class twitter_client { this.twitter_auto_tweet_interval_max = parseInt(temp_max) } - if ( - settings.twitter_auto_tweet_start_phrases && - settings.twitter_auto_tweet_start_phrases?.length > 0 - ) { - this.twitter_auto_tweet_start_phrases = - settings.twitter_auto_tweet_start_phrases.split('|') - } - const bearerToken = settings.twitter_token const twitterUser = settings.twitter_id const twitterAppToken = settings.twitter_app_token @@ -164,17 +158,17 @@ export class twitter_client { twitterAccessTokenSecret ) console.log('creating v2') - /* + this.twitterv2 = createTwitterClientV2(bearerToken) const localUser = await this.twitterv2.v2.userByUsername(twitterUser) - setInterval(async () => { + /*setInterval(async () => { const tv1 = this.twitterv1 try { console.log('requesting events') const eventsPaginator = await this.twitterv1.v1.listDmEvents() console.log('events:', eventsPaginator) for await (const event of eventsPaginator) { - log( + log(p 'Event: ' + JSON.stringify(event.message_create.message_data.text) ) if (event.type == 'message_create') { @@ -196,15 +190,13 @@ export class twitter_client { 'twitter', event.id, settings.entity, - [] + [], + 'dm' ) /* await this.handleMessage( resp, event.id, 'DM', - twitter, - tv1, - localUser ) } } @@ -216,13 +208,13 @@ export class twitter_client { if ( this.twitter_auto_tweet_interval_min > 0 && this.twitter_auto_tweet_interval_max > 0 && - this.twitter_auto_tweet_start_phrases.length > 0 && this.twitter_auto_tweet_interval_min < this.twitter_auto_tweet_interval_max ) { - this.automatic_tweet(spellHandler) + this.automatic_tweet(spellHandlerAuto) } + this.twitter_enable_twits = false if (this.twitter_enable_twits) { const client = this.twitterv2 const rules = await client.v2.streamRules() @@ -231,7 +223,7 @@ export class twitter_client { delete: { ids: rules.data.map(rule => rule.id) }, }) } - const tweetRules = 'digital,being,digital being'.split(',') + const tweetRules = this.twitter_tweet_rules.split(',') const _rules = [] const regex = [] for (let x in tweetRules) { @@ -280,16 +272,10 @@ export class twitter_client { 'twitter', twit.data.id, settings.entity, - [] - ) - await this.handleMessage( - resp, - twit.data.id, - 'Twit', - this.twitter, - null, - localUser + [], + 'tweet' ) + await this.handleMessage(resp, twit.data.id, 'Twit') database.instance.setDataHandled(twit.data.id, 'twitter') } diff --git a/packages/server/src/entities/connectors/xrengine.ts b/packages/server/src/entities/connectors/xrengine.ts index 58e95782..9b338147 100644 --- a/packages/server/src/entities/connectors/xrengine.ts +++ b/packages/server/src/entities/connectors/xrengine.ts @@ -426,8 +426,7 @@ export class xrengine_client { channelId, this.entity, roomInfo, - this.settings.xrengine_spell_handler_incoming, - this.spell_version + 'msg' ) console.log('got response:', response) diff --git a/packages/server/src/entities/connectors/zoom.ts b/packages/server/src/entities/connectors/zoom.ts index 0d60af60..5e23e0ca 100644 --- a/packages/server/src/entities/connectors/zoom.ts +++ b/packages/server/src/entities/connectors/zoom.ts @@ -191,7 +191,8 @@ export class zoom { 'zoom', this.settings.zoom_invitation_link, this.entity, - [] + [], + 'msg' ) const tempResp = response console.log('RESP:', response) From 217cf430f01425eacc7dbd70f581e82c3ed1ff8c Mon Sep 17 00:00:00 2001 From: alextitonis Date: Mon, 1 Aug 2022 16:09:01 +0300 Subject: [PATCH 3/3] Update twitter.ts --- packages/server/src/entities/connectors/twitter.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/server/src/entities/connectors/twitter.ts b/packages/server/src/entities/connectors/twitter.ts index c9fdd847..649a3420 100644 --- a/packages/server/src/entities/connectors/twitter.ts +++ b/packages/server/src/entities/connectors/twitter.ts @@ -39,11 +39,11 @@ const createTwitterClientV2 = (bearerKey: string) => { export class twitter_client { automatic_tweet = async spellHandler => { - const interval = 6000 - /*randomInt( + const interval = + randomInt( this.twitter_auto_tweet_interval_min, this.twitter_auto_tweet_interval_max - ) * 60000*/ + ) * 60000 console.log('await interval:', interval) await sleep(interval) @@ -59,8 +59,8 @@ export class twitter_client { ) console.log('generated automatic tweet:', resp) - //this.twitterv1.v1.tweet(resp) - //this.automatic_tweet(spellHandler) + this.twitterv1.v1.tweet(resp) + this.automatic_tweet(spellHandler) } async handleMessage(response, chat_id, args) { @@ -214,7 +214,6 @@ export class twitter_client { this.automatic_tweet(spellHandlerAuto) } - this.twitter_enable_twits = false if (this.twitter_enable_twits) { const client = this.twitterv2 const rules = await client.v2.streamRules()