Functions

Last updated: Mar 09th, 2017

Introductions

Functions was the first step to a completely dynamic storage system in attempts to simplify bigger A.R.S Rules with specific changes.

Local functions can be created on your server to help minify long A.R.S Rules that you use repeatedly with small changes.

Purpose of Functions

There are a lot of keys out there that can get huge, and people (including myself)
Get tired of having to re-write the same big rule and only make one or two changes to it
For example say you want to have a bunch of secure commands, but all for different channels.

Local Functions

Creating your Function.

Let's start you off with a simple one, this function has no parameters.
.define func HelloUser():Hello {/user}!!

Looks easy enough right? Now when you type that it will be stored in your guilds `Defines` object. Allowing you to easily access that function in your server with any A.R.S Rule. Let's give you an example how to use the function in our A.R.S.
.auto .hello={init}
call::HelloUser();
Now when you type .hello you will get your pre-defined function's response.
More Advanced Example
The function below has two parameters. And will redirect their message to a channel.
.define func HelloUser(ChannelID, Message):{redirect:{0}}{1}
Alright now before we teach you how to use this function in your A.R.S Rules let's explain.. What we're doing here is creating a function with Two parameters. And than defining those parameters using the
{0}
for ChannelID and
{1}
for Message.

When you think about it, it's pretty simple. You can have an unlimited amount of parameters in your function However You need to define those parameters with a {num} counterpart. Meaning.
If you have a function with 4 paramters HelloUser(Param1, Params2, Params3, Params4)
you will need to define them in the functions response as such
{0}=Param1, {1}=Params2, {2}=Params3, {3}=Params4

Using the Function

Technically there are a few different ways to do this, let's try to cover them! This one will post a pre-defined message to a channel the user types with the command.
.auto &.hello {params}={init}
call::HelloUser({params}, This message is pre-defined);

Ok, now if the user types
.hello CHANNELID-HERE
the predfined message will be sent to the channel id they type.
Now let's switch it up, do the opposite!
.auto &.hello {params}={init}
call::HelloUser(1268555466456789, {params});

Ok now when someone types
.hello What is up guys!
Their message will be redirected to the channel: 1268555466456789 And since the {redirect} key requires the channel id. We need to make sure to place the channel ID not the name.

Deleting Functions

Ok lets pretend we are deleting the HelloUser function we created above.
.delfunc HelloUser
Pretty easy right? Now the HelloUser function is no longer available to use.
Make sure you remove any A.R.S Rules calling the function.

Listing Functions

Currently it's not pretty to list functions and it's limited which we will attempt to fix soon.
Until than if your functions get too big Echo will not display due to discords 2000 character limit.
.deflist

Wiping Functions

This will wipe your entire functions database. Make sure you remove any call to the functions in your rules
.wipedefs

Remote Functions

Remote Functions are hosted on your Github page or the main Github for Repos
if you are wanting to get into system/messages package which is available to everyone.
We will need to follow a few steps, and make sure you remember. Security!
You don't want to offer someone a module that has {role:} Where it's open to all.
Make sure you add a {req} or {exc} key to any moderation commands!

Package Structure

{
"Defines": [
  {
     "Name": "UserMessageSend",
     "Params": [
        "UserID",
        "Message"
     ],
     "Content": "{pm:{0}}{1}"
  }
}
}
Alright now what you're looking at above is a function to send a custom user a custom message. Make sure you have read up on the Github Main README.md if you don't understand the {0},{1}
Multiple defined functions in a page below:
{
"Defines": [
  {
     "Name": "UserMessageSend",
     "Params": [
        "UserID",
        "Message"
     ],
     "Content": "{pm:{0}}{1}"
  },
  {
     "Name": "ActiveMessageSend",
     "Params": [
        "Message"
     ],
     "Content": "{pm}{0}"
  }
}
Now your package will include the UserMessageSend & ActiveMessageSend. What's the difference? UserMessageSend will direct message a defined user. or you can set it up to pm multiple. ActiveMessageSend will message the user who triggers the function. Or whoever is mentioned in the trigger.

Check your Syntax

Checking your package syntax is very important! Otherwise Echo will ignore the import.
We recommend one of these:
http://jsonlint.com/ https://jsonformatter.curiousconcept.com/

Naming your Package

Make sure to keep your package name simple so you can remember!
Your package name won't conflict with others because of the github account prefix in the import.
So you can make your own messages.json package and run it alongside the system/messages package.

Uploading to Github

Echo will use github api to connect to and execute your functions.
An example would be proxikal/EchoRepository/packagename
don't add the .json
this means that I (proxikal) have a repository on github named (EchoRepository)
And in the main repo directory i have the file (packagename).json!
Again remember to leave the .json out when importing the file.

Import Packages

.auto &.giveme {params}={init}
import "githubaccount/reponame/packagefile"
call::GiveMeRole(Admin, {params});
Ok now we are using the GiveMeRole example in the Secure Commands Example.
What we're having echo do here is. IF the user has the role Admin they can type .giveme Role Name and echo will give them that role As long as his role is above theirs