C#:
using Rust;
using UnityEngine;
using Oxide.Core.Libraries;
using System.Collections;
using System.Linq;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine.Networking;
using System.Text.RegularExpressions;
using System.Globalization;
using System;
namespace Oxide.Plugins
{
[Info("Plugin Info", "WOLF#4002", "0.0.1")]
[Description("Plugins Hook Time Top 20")]
class WPluginsInfo : RustPlugin
{
private class Configuration
{
[JsonProperty("COLOR")]
public List<int> colorLines = new List<int>();
[JsonProperty("WEB HOOK DISCORD")]
public string DS_Hook;
public int Time;
public static Configuration Generate()
{
return new Configuration
{
DS_Hook ="https://discord.com/api/webhooks/1117434687812534293/JwwSC5wSN9VJNLtzDmEZFRT1QCfr-IuriSy1yRbYJmIM_J7RsH222PUx8qeIEYKQ4dF6",
Time = 600,
colorLines = new List<int>
{
53380, 9359868, 11253955
},
};
}
}
private static Configuration Settings;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
}
catch
{
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
public List<string> ignoreList = new List<string>();
void Go()
{
int top = 1;
string text = string.Empty;
string text1 = $"{Name}";
var listPlugin = _instance.plugins.PluginManager.GetPlugins().Where(x => !ignoreList.Contains(x.Name)).OrderByDescending(x => x.TotalHookTime).Take(20);
foreach (var listPlugins in listPlugin)
{
text += $"\n\n#{top} ({listPlugins.Name} {listPlugins.Author})\nHook TIME: {listPlugins.TotalHookTime}s";
top++;
}
SendDiscordMessage(text1, new List<string> { text }, false);
}
[PluginReference] Plugin ImageLibrary, WBot;
private static WPluginsInfo _instance;
private void OnServerInitialized()
{
_instance = this;
timer.Every(Settings.Time, () => { Go(); });
Go();
}
public string message = string.Empty;
private void SendDiscordMessage(string title, List<string> embeds, bool inline = false)
{
Embed embed = new Embed();
foreach (var item in embeds)
{
embed.AddField(title, item, inline, Settings.colorLines.GetRandom());
}
webrequest.Enqueue(Settings.DS_Hook, new DiscordMessage(message, embed).ToJson(), (code, response) => { },
this,
RequestMethod.POST, new Dictionary<string, string>
{
{ "Content-Type", "application/json" }
});
}
private class DiscordMessage
{
public DiscordMessage(string content, params Embed[] embeds)
{
Content = content;
Embeds = embeds.ToList();
}
[JsonProperty("content")] public string Content { get; set; }
[JsonProperty("embeds")] public List<Embed> Embeds { get; set; }
public string ToJson()
{
return JsonConvert.SerializeObject(this);
}
}
private class Embed
{
public int color
{
get; set;
}
[JsonProperty("fields")] public List<Field> Fields { get; set; } = new List<Field>();
public Embed AddField(string name, string value, bool inline, int colors)
{
Fields.Add(new Field(name, Regex.Replace(value, "<.*?>", string.Empty), inline));
color = colors;
return this;
}
}
private class Field
{
public Field(string name, string value, bool inline)
{
Name = name;
Value = value;
Inline = inline;
}
[JsonProperty("name")] public string Name { get; set; }
[JsonProperty("value")] public string Value { get; set; }
[JsonProperty("inline")] public bool Inline { get; set; }
}
}
}