Updated Events and cronjobs (markdown)

Yessiest 2022-05-21 17:05:15 +00:00
parent 134fc2657f
commit 7fc083a82b
1 changed files with 44 additions and 4 deletions

@ -30,10 +30,13 @@ DD.MM.YY HH:MM command
DD.MM.YY is a date format, with day, month and year separated by a dot. HH:MM is a 24-hour time format. DD.MM.YY is a date format, with day, month and year separated by a dot. HH:MM is a 24-hour time format.
## Event directives ## Event directives
As with the modern `cron` implementations on Linux(Unix), there are multiple "directives" for cron. Unlike these implementations, directive syntax is a bit more complex, allowing matching against certain arguments passed along with the directive. Rather than explaining the directives from scratch, let's look at a practical example: As with the modern `cron` implementations on Linux(Unix), there are multiple "directives" for cron. Unlike these implementations, directive syntax is a bit more complex, allowing matching against certain arguments passed along with the directive.
### Directive example
Rather than explaining the directives from scratch, let's look at a practical example:
``` ```
@message /%sGNU\/Linux%s/ >913818433748086784 : &echo *funni stallman bad copypasta goes here* @message /%sGNU\/Linux%s/ >913818433748086784 : &echo *funni stallman bad copypasta goes here by $USERNAME*
@message /%sGNU\/Linux%s/ <913818433748086784 : &echo *funni stallman bad copypasta goes here* @message /%sGNU\/Linux%s/ <913818433748086784 : &echo *funni stallman bad copypasta goes here by $USERNAME*
``` ```
This might look very confusing to those of you who are used to the `@reboot` directive in cron. But in fact, it's not unlike that directive - it's just that after the `@message` directive we have 2 arguments that are being matched. In this case, it's the message itself and the message author's id. To separate the arguments list from the command, we use a colon `:` delimiter. Now, let's look at what each argument does: This might look very confusing to those of you who are used to the `@reboot` directive in cron. But in fact, it's not unlike that directive - it's just that after the `@message` directive we have 2 arguments that are being matched. In this case, it's the message itself and the message author's id. To separate the arguments list from the command, we use a colon `:` delimiter. Now, let's look at what each argument does:
@ -45,6 +48,14 @@ We finalize the argument list with `:`. Note that it should be separated from bo
There is also a channel id argument for message, but since the directives don't specify any patter to match it against, this argument is simply ignored. For any given directive, any amount of arguments can be ignored. There is also a channel id argument for message, but since the directives don't specify any patter to match it against, this argument is simply ignored. For any given directive, any amount of arguments can be ignored.
Last but not least, directives can pass certain arguments to the command itself as environment variables. In our example, `$USERNAME` is an environment variable. Those of you who are knowledgeable about the ways of Unix shells already know what this means. Those of you who don't might want to read the next paragraph.
### Environment variables
Most of the events that are currently available pass some environment variables to the command, which can be used to manipulate the command. For example, if a `@message` event is triggered, the `$USERNAME` environment variable is changed to the username of the message author. All environment variables are prefixed with a dollar sign `$` and can only be used inside of the command.
### Argument matching patterns
There are multiple patterns available, each one can be applied to any argument: There are multiple patterns available, each one can be applied to any argument:
1. `/.../` is a regex pattern that matches the argument against a Lua-style regular expression (See [Programming in Lua](https://www.lua.org/pil/20.2.html)) 1. `/.../` is a regex pattern that matches the argument against a Lua-style regular expression (See [Programming in Lua](https://www.lua.org/pil/20.2.html))
2. `>n`, `<n`, `>=n`, `<=n` is a numeric comparison pattern that converts argument to a numeric value (if possible) and then compares it against number `n` 2. `>n`, `<n`, `>=n`, `<=n` is a numeric comparison pattern that converts argument to a numeric value (if possible) and then compares it against number `n`
@ -56,7 +67,36 @@ Note that while both `"..."` and `n` are equivalent when used against numbers, `
## Available directives ## Available directives
Currently, the directives list is very short, but as updates will come along, this list will expand. Currently, the directives list is very short, but as updates will come along, this list will expand.
1. `@message` directive - triggered by a message sent to the guild in any channel. Arguments: message content, user id, channel id
Format is `@<directive name> <argument> <argument2> ... <$VARIABLE> <$VARIABLE2> <VARIABLE3>`
1. @message: content, userId, channelId, $USER, $USERNAME, $CHANNEL, $CONTENT
2. @messageOnce: content, userId, channelId, $USER, $USERNAME, $CHANNEL, $CONTENT
3. @ban: userId, $USER, $USERNAME
4. @banOnce: userId, $USER, $USERNAME
5. @unban: userId, $USER, $USERNAME
6. @unbanOnce: userId, $USER, $USERNAME
7. @join: userId, username, age, $USER, $USERNAME, $AGE, $DISCRIM, $TAG
8. @joinOnce: userId, username, age, $USER, $USERNAME, $AGE, $DISCRIM, $TAG
9. @leave: userId, username, role, $USER, $USERNAME, $AGE, $DISCRIM, $TAG, $GUILDTIME, $ROLE
10. @leave: userId, username, role, $USER, $USERNAME, $AGE, $DISCRIM, $TAG, $GUILDTIME, $ROLE
### Argument description:
- `content` - Message content.
- `userId` - Discord ID of the user that triggered the event.
- `username` - Discord username of the user that triggered the event.
- `age` - Discord account age in seconds.
- `role` - Primary role ID of the discord user that triggered the event.
- `channelId` - ID of the channel where the event was triggered.
### Environment variable description:
- `$USER` - User ID that triggered the event.
- `$USERNAME` - Username that triggered the event.
- `$AGE` - Discord account age in seconds.
- `$DISCRIM` - Discriminator (last 4 digits) of a full Discord tag.
- `$TAG` - Full discord tag.
- `$GUILDTIME` - Time spent in the guild in seconds.
- `$ROLE` - Primary role of the user.
- `$CHANNEL` - Channel where the event occured.
## Examples ## Examples