Last active
November 11, 2017 10:09
-
-
Save Snow-Pyon/df5e1aa9ee0d52feef5e8c4dfbbfd2c0 to your computer and use it in GitHub Desktop.
Skript eval command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Eval command. | |
#Dependencies: | |
#- MundoSK | |
#- TuSKe | |
#- skQuery | |
#- Vixio | |
options: | |
#Change this to your bot's name. | |
bot: Fujinomiya | |
#Makes a codeblock with the specified message and language. | |
#Parameters: | |
#{_message} = the message that will be into the codeblock. | |
#{_language} (optional) = the language/syntax highlight to use. | |
#Examples: | |
#can be seen below. | |
function makeCodeblock(message: text, language: text = "") :: text: | |
return "```%{_language}%%nl%%{_message}%%nl%```" | |
on skript load: | |
#Setting up stuff... | |
login to user with token "token here" with name "{@bot}" | |
make embed "Result" | |
set {embed::success-color} to "##40FF00" | |
set {embed::failure-color} to "##FF0000" | |
set {embed::success-title} to "Successfully evaluated:" | |
set {embed::failure-title} to "Couldn't evaluate!" | |
on guild message receive seen by "{@bot}": | |
#Make sure it doesn't trigger for every message. | |
mentions in message event-message contains event-bot #Nvm, it still throws it. | |
set {_message} to event-string | |
#Gets the command, should be a command of 4 letters max | |
set {_command} to subtext of {_message} from (length of "@{@bot} " + 1) to (length of "@{@bot} " + 4) | |
#This is kinda useless in this case, but if you have more commands it's better to use a switch statement, Fujinomiya has but I removed them here. | |
switch {_command}: | |
case "eval": | |
set {_message::*} to split {_message} by new line | |
#Checks if it's a codeblock or an in-line evaluation | |
if {_message::2} contains "```": | |
#removes the codeblock characters, mention and command | |
set {_last} to size of {_message::*} | |
delete {_message::1}, {_message::2} and {_message::%{_last}%} | |
set {_evaluate} to join {_message::*} by new line | |
else: | |
#removes the mention and command | |
set {_evaluate} to subtext of {_message} from (length of "@{@bot} " + length of {_command} + 2) to (length of {_message}) | |
#Evaluates here so it can use effects like "reply with" and the event-values of this event. | |
{_evaluate} is set | |
evaluate logging errors in {_errors::*}: "%{_evaluate}%" | |
set {_details::*} to {_evaluate} and event-channel | |
set {_args::*} to {_errors::*} | |
call custom event "command-%{_command}%" to details {_details::*} arguments {_args::*} | |
event "command-eval": | |
loop custom event's args: | |
set {_current-error::*} to loop-value parsed as "%text%: %text% \(%text%.sk, line %number%: %text%'\)" | |
add "%{_current-error::1}%: %{_current-error::2}% (line %{_current-error::4}%)" to {_errors::*} | |
set {_errors} to join {_errors::*} by new line | |
set {_state} to {_errors::1} == null ? "success" : "failure" | |
set {_icon} to "http://frankkusmiruk.tk/Screenshots/%{_state}%-icon.png" | |
set {_desc} to {_state} == "failure" ? {_errors} : event-string | |
set author of embed "Result" to embed titled {embed::%{_state}%-title}, with hyperlink {_icon}, iconurl {_icon} | |
set desc of embed "Result" to makeCodeblock({_desc}) | |
set color of embed "Result" to {embed::%{_state}%-color} | |
send embed "Result" to channel event-channel with "{@bot}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment