Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Net;
- using System.Globalization;
- using Newtonsoft.Json;
- using Oxide.Core;
- using Oxide.Core.Plugins;
- using UnityEngine;
- using Oxide.Ext.Discord;
- using Oxide.Ext.Discord.Attributes;
- using Oxide.Ext.Discord.DiscordObjects;
- using Oxide.Core.Libraries.Covalence;
- namespace Oxide.Plugins
- {
- [Info("Fantasmeo Bot", "Kashix.", "0.1.0")]
- [Description("Discord Bot for Fantasmeo Island server.")]
- class Fantasmeo : RustPlugin{
- [PluginReference] Plugin Discord;
- [DiscordClient] private DiscordClient _client;
- private Settings _settings;
- private Timer StatusTimer = null;
- private Presence DiscordPresence = new Presence()
- {
- Game = new Ext.Discord.DiscordObjects.Game()
- {
- Type = ActivityType.Game,
- Name = "Fanstameo cargando..."
- }
- };
- // Configuration
- private class Settings
- {
- public string Apikey { get; set; }
- public bool AutoReloadPlugin { get; set; }
- public int AutoReloadTime { get; set; }
- public bool EnableBotStatus { get; set; }
- }
- // Channel configuration
- public class Channel
- {
- public string Channelid { get; set; }
- public List<string> perms { get; set; }
- }
- private Settings GetDefaultSettings()
- {
- return new Settings
- {
- ApiKey = "Nzc0MjQ0NzYxMDkxNDQwNjUw.X6U9nw.pgBxizR282mw19Wp6p2ytKVW04s",
- AutoReloadPlugin = true,
- AutoReloadTime = 900
- };
- }
- protected override void LoadDefaultConfig()
- {
- PrintWarning("Intentando crear un nuevo archivo de configuración...");
- Config.Clear();
- Config.WriteObject(GetDefaultSettings(), true);
- Config.Save();
- }
- private void OnServerInitialized()
- {
- var reloadtime = _settings.AutoReloadTime;
- if (_settings.AutoReloadPlugin && _settings.AutoReloadTime > 59)
- {
- timer.Every(reloadtime, () => Reload());
- }
- }
- private void Loaded()
- {
- _settings = Config.ReadObject<Settings>();
- // Asegurar que la configuración está guardada
- if (_settings.Channels == null)
- _settings.Channels = new List<Settings.Channel>();
- Config.WriteObject(_settings, true);
- if (string.IsNullOrEmpty(_settings.Apikey) || _settings.Apikey == null || _settings.Apikey == "BotToken")
- {
- PrintError("La clave API no es correcta o no está configurada.");
- return;
- }
- bool flag = true;
- try
- {
- Oxide.Ext.Discord.Discord.CreateClient(this, _settings.Apikey);
- }
- catch (Exception e)
- {
- flag = false;
- PrintError($"No se ha podido crear un cliente de Discord, error: {e.Message}");
- }
- }
- private void Reload()
- {
- rust.RunServerCommand("oxide.reload FanstasmeoBot");
- }
- private void Unload()
- {
- if (StatusTimer != null && !StatusTimer.Destroyed)
- {
- StatusTimer.Destroy();
- }
- if (_settings.EnableCustomLogging)
- UnityEngine.Application.logMessageReceived -= ConsoleLog;
- Discord.CloseClient(_client);
- }
- void Discord_Ready(Oxide.Ext.Discord.DiscordEvents.Ready rdy)
- {
- //_settings.Botid(rdy.User.id);
- _channelCount = _settings?.Channels.Count;
- if (_settings.EnableBotStatus)
- {
- NextFrame(() =>
- {
- if (StatusTimer != null && !StatusTimer.Destroyed)
- {
- StatusTimer.Destroy();
- }
- StatusTimer = timer.Every(10f, () =>
- {
- var text = new Dictionary<string, string>
- {
- ["players"] = Convert.ToString(BasePlayer.activePlayerList.Count),
- ["maxplayers"] = Convert.ToString(ConVar.Server.maxplayers),
- ["sleepers"] = Convert.ToString(BasePlayer.sleepingPlayerList.Count)
- };
- var msg = Translate("Discord_Status", text);
- DiscordPresence.Game.Name = string.IsNullOrEmpty(msg) ? "Iniciando bot..." : msg;
- _client.UpdateStatus(DiscordPresence);
- });
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement