• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

Private Messaging through bot

jasiubor

Member
Hi guys, anyone know script that allow me to message through bot ?
Something like !msg <nick/UID> <message> ? I wanna do commands through bot to bot, so the message should fit chars like "!" and ".".
 

Lukas Westholt

Well-Known Member
Contributor
No i don't know a script that can do that, but its not that complicated to script that. Try it. https://sinusbot.github.io/scripting-docs/#clientchat

something like that:

JavaScript:
var engine = require('engine');
var backend = require('backend');

String.prototype.startsWith = function(needle)
{
    return this.indexOf(needle) === 0;
};

       
function send_msg(msg, clientId, mode)
          {
            switch(mode)
            {
              case 1:
                  backend.getClientByID(clientId).chat(msg);
                  break;
              case 2:
                  backend.getClientByID(clientId).getChannels()[0].chat(msg);
                  break;
              case 3:
                  backend.chat(msg);
                  break;

            }
          }

event.on('chat', function(ev) {
        if (ev.text.startsWith("!msg") || ev.text.startsWith("!send")) {
            send_msg(ev.text.split("\"")[1], ev.text.split("\"")[2], ev.text.split("\"")[3]);
        }
    });
GER/DE:
Das ganze funktioniert dann so "!msg" oder "!send" und dann "text"clientID"mode
also als Beispiel: !msg "!say Hello"nwlEPCmJ4rb+Uy8HJhylEhlQd1o="3 und er schreibt !say Hello in den Server Chat.

Achtung: Das ganze Script ist komplett ungetestet und innerhalb 1 min zusammen gebastelt.

EN:
The whole works then so "!msg" or "!send" and then "text"clientID"mode

as an example: !msg "! say Hello"nwlEPCmJ4rb+Uy8HJhylEhlQd1o="3 and he writes !say Hello into the server chat.

Note: The whole script is completely untested and made in 1 min.

Best regards,
Lukas Westholt
 
Last edited:

jasiubor

Member
EN:
The whole works then so "!msg" or "!send" and then "text"clientID"mode

as an example: !msg "! say Hello"nwlEPCmJ4rb+Uy8HJhylEhlQd1o="3 and he writes !say Hello into the server chat.

Lukas Westholt

I got troubled by those quotes so I just wanna make sure - for example I wanna make bot write "!wyslij 5 jasiubor" to UID xyz so I should type something like this:
!msg "!wyslij 5 Janekk"xyz"
right ? :)
 

jasiubor

Member
Appears an error, like:
Could not parse script: ReferenceError - "require" is not defined at <anonymous>:1:14
 

Lukas Westholt

Well-Known Member
Contributor
oh ok, you are a really beginner in Sinusbot scripting but ok, you need to setup a registerPlugin. So:

JavaScript:
registerPlugin({
    name: 'myscript',
    version: '1.0',
    description: 'This is my script description',
    author: 'jasiubor',
},

function (sinusbot, config) {
    var engine = require('engine');
    var backend = require('backend');

   String.prototype.startsWith = function(needle) {
   return this.indexOf(needle) === 0;
   };

     
function send_msg(msg, clientId, mode)
          {
            switch(mode)
            {
              case 1:
                  backend.getClientByID(clientId).chat(msg);
                  break;
              case 2:
                  backend.getClientByID(clientId).getChannels()[0].chat(msg);
                  break;
              case 3:
                  backend.chat(msg);
                  break;

            }
          }

event.on('chat', function(ev) {
        if (ev.text.startsWith("!msg") || ev.text.startsWith("!send")) {
            send_msg(ev.text.split("\"")[1], ev.text.split("\"")[2], ev.text.split("\"")[3]);
        }
    });
});

You need to copy the code into a .js file with a random name in the "scripts" folder.

And I think then you can do the command
!msg "!wyslij 5 Janekk"xyz"1
for sending the command !wyslij 5 Janekk to xyz in private chat.

if you want to send it in global server chat you can do this:
!msg "!wyslij 5 Janekk""3

and if you want to send it in channel chat of the user (I do not know if it works.):
!msg "!wyslij 5 Janekk"xyz"2

So the last digit is:
1 - private
2 - channel
3 - global server

Good luck ;),
Lukas
 

Lukas Westholt

Well-Known Member
Contributor
try this

If it should come to errors or ambiguities, I will work again tomorrow.
 

Attachments

  • helper.js
    1 KB · Views: 14
Last edited:

jasiubor

Member
Script loads normally, but error appears when I want send msg like this: !msg "!wyslij 15 Janekk"4AZNMz1GE874YYFplPTMPRJQYpM="1
Error:

WARN Error in script (event chat): TypeError: Cannot access member 'chat' of undefined
at send_msg (helper.js:22:5)
at helper.js:39:4
 

Everlike

Well-Known Member
Contributor
Yes, check case 3, there you can see it’s only backend.chat, the client or recipient is missing.
Write backend.client.chat or do it, as it is in case 1 or 2
„backend.getClientByUniqueID(clientId).getChannels()[0].chat(msg);“ or whatever you want.
 

jasiubor

Member
Yes, check case 3, there you can see it’s only backend.chat, the client or recipient is missing.
Write backend.client.chat or do it, as it is in case 1 or 2
„backend.getClientByUniqueID(clientId).getChannels()[0].chat(msg);“ or whatever you want.
I'm sorry, but I cannot do anything with the code, I just don't know it :/
 

Lukas Westholt

Well-Known Member
Contributor
Script loads normally, but error appears when I want send msg like this: !msg "!wyslij 15 Janekk"4AZNMz1GE874YYFplPTMPRJQYpM="1
Error:

WARN Error in script (event chat): TypeError: Cannot access member 'chat' of undefined
at send_msg (helper.js:22:5)
at helper.js:39:4

I check that when i come to home. :)
 

jasiubor

Member
Make sure that the UniqueID is correct
Actually I'm not sure, because the bot is actually a Query bot that connects to server through ts3admin php class, but when I link the bot to chat, I can see a chain of chars like normal UID

(ofc normally I can chat with the bot)
 
Last edited:

jasiubor

Member
Testing with !msg "siema"8hIt+RqMlF4byDHdDUvzrVzvq0w="1
Your logs:
helper (1):18 siema8h...id...=1
helper (1):21 case 1
helper (1):32 Client wrong!
 

jasiubor

Member
Appears message:
CHAT 1 [admin @ Janekk] < !msg "!wyslij 15 Janekk"Centrum <pointsBot>"1 > / NOTFOUND/NOPRIV
I think the bot isn't found by my bot or it just can't be pw'ed.
Is there any way to message him ? I tried with custom commands, bcuz this bot on the connect messages u on priv with text, but the custom command must be sent in one message alone, for example command "Hi !" does'nt work on "Hi Janekk ! My name is BOT Paul.."cuz it's made out of multiple words and also it doesn't work with the link.
 

Everlike

Well-Known Member
Contributor
Okay dude, so you want to write something like "!msg UIDhere messageHere" to your sinusbot, and the sinusbot should write a message to the uid with the content of messsageHere, am I right? You want to use this for real clients or your querybot?
 
Top