C#:
using System;
using System.Collections.Generic;
using System.Linq;
namespace Oxide.Plugins
{
[Info("AutoReply", "anhe", "1.0.0")]
[Description("Automatically replies to player messages based on keywords.")]
public class AutoReply : RustPlugin
{
private Configuration config;
public class Configuration
{
public Dictionary<string, string> Replies = new()
{
["wipe|wiep|wpie|вайп"] = "This server wipes on the first Thursday of each month, 6:45 pm (London time). Blueprints are wiped too.",
["discor|discr|дискор"] = "You can join our Discord at frust.org/discord",
["web|сайт"] = "Visit our website at frust.org",
["repor|admi|suppor|адми|репор|cheat|чит"] = "Please report any issues to our Discord at frust.org/discord"
};
}
protected override void LoadDefaultConfig()
{
config = new Configuration();
SaveConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>();
if (config == null)
throw new Exception();
}
catch
{
PrintWarning("Configuration is invalid, creating a new one.");
LoadDefaultConfig();
}
}
protected override void SaveConfig()
{
Config.WriteObject(config, true);
}
private void OnPlayerChat(BasePlayer player, string message)
{
var response = config.Replies
.FirstOrDefault(pair =>
pair.Key
.Split('|')
.Any(keyword => message.Contains(keyword, StringComparison.OrdinalIgnoreCase)))
.Value;
if (!string.IsNullOrEmpty(response))
NextTick(() => player.ChatMessage(response));
}
}
}