Preview / How it Works: https://image.ibb.co/eVLwGe/serverconsole.png
Requirements
Preview / How it Works: https://image.ibb.co/eVLwGe/serverconsole.png
Requirements
options: | |
# The Discord bot token from https://discordapp.com/developers/applications | |
botToken: "" | |
# ID of the console channel | |
channel: "312345678910101214" | |
# Who can send console commands | |
admins: "012345678910111213", "312111019876543210" or "981713114610522013" | |
bot: "ServerConsole" | |
variable: ServerConsole | |
import: | |
java.lang.Runtime | |
java.util.regex.Pattern | |
org.bukkit.Bukkit | |
on skript load: | |
set {{@variable}::pluginManager} to Bukkit.getServer().getPluginManager() | |
set {{@variable}::queue} to "" | |
on load: | |
if {@bot} parsed as bot is not set: | |
login to {@botToken} with name {@bot} | |
set status of {@bot} to online | |
set {{@variable}::consoleChannel} to channel with id {@channel} | |
set {{@variable}::URLRegex} to Pattern.compile("(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?") | |
on unload: | |
set status of {@bot} to do not disturb | |
on log: | |
set {_line} to uncolored logged message | |
set {_loggerName} to logger name | |
if {_loggerName} is set: | |
if {{@variable}::pluginManager}.isPluginEnabled({_loggerName}): | |
set {_prefix} to "[%{_loggerName}%] " | |
else if logger name contains "jda": | |
set {_prefix} to "[%{_loggerName}%] " | |
else: | |
set {_prefix} to "" | |
else: | |
set {_prefix} to "" | |
set {_line} to "[%now formatted as ""HH:mm:ss""% %log level in upper case%] %{_prefix}%%uncolored {_line}%" | |
set {{@variable}::queue} to "%{{@variable}::queue}%%nl%%{_line}%" | |
# Surround links with < > so they won't show link preview embeds in the Discord console. | |
# I don't know why but it makes the links <<link>> (double) when i use regex replace? | |
function noURLPreviews(text: text) :: text: | |
if {_text} contains "s://" or "p://": | |
set {_matcher} to {{@variable}::URLRegex}.matcher({_text}) | |
while {_matcher}.find(): | |
set {_group} to {_matcher}.group(0) | |
replace {_group} with "<%{_group}%>" in {_text} | |
return {_text} | |
every a second: | |
if {{@variable}::queue} is not "": | |
set {{@variable}::queue} to noURLPreviews({{@variable}::queue}) | |
if length of {{@variable}::queue} is greater than 2000: | |
set {_split::*} to split {{@variable}::queue} at nl | |
while {_split::*} is set: | |
set {_message} to "" | |
loop {_split::*}: | |
if length of {_message} + length of loop-value + 1 is smaller than 2000: | |
set {_message} to "%{_message}%%nl%%loop-value%" | |
delete {_split::%loop-index%} | |
send {_message} to {{@variable}::consoleChannel} with {@bot} | |
else: | |
send {{@variable}::queue} to {{@variable}::consoleChannel} with {@bot} | |
set {{@variable}::queue} to "" | |
function maxRAM() :: number: | |
return rounded (Runtime.getRuntime().maxMemory() / 1024) / 1024 | |
function freeRAM() :: number: | |
return rounded (Runtime.getRuntime().freeMemory() / 1024) / 1024 | |
function usedRAM() :: number: | |
set {_max} to maxRAM() | |
return {_max} - freeRAM() | |
every 3 second: | |
if {@bot} parsed as bot is set: | |
set topic of {{@variable}::consoleChannel} to "TPS from last 1m, 5m, 15m: %tps from last 1m%, %tps from last 5m%, %tps from last 15m% — RAM: %usedRAM()%/%maxRAM()%MB" with {@bot} parsed as bot | |
on guild message received seen by {@bot}: | |
if id of event-channel is {@channel}: | |
if id of event-user is {@admins}: | |
execute console command event-string | |
delete event-message with event-bot | |
on command: | |
if executor is console: | |
send ":arrow_right: %noURLPreviews(full command)%" to {{@variable}::consoleChannel} with {@bot} and store it in {_message} | |
add reaction ":repeat:" to reactions of (random message of {_message}) with {@bot} | |
on reaction added seen by {@bot}: | |
if id of event-channel is {@channel}: | |
if id of event-user is {@admins}: | |
if name of event-emote is "repeat": | |
execute console command subtext of (content of event-message) from character 15 to length of (content of event-message) | |
remove event-emote added by event-user from event-message |