示例#1
0
 public BotService(ILogger <BotService> logger, IOptions <DiscordSettings> discordSettings,
                   DiscordSocketClient client, CommandHandlingService commandHandlingService)
 {
     _logger = logger;
     this.discordSettings        = discordSettings.Value;
     this.client                 = client;
     this.commandHandlingService = commandHandlingService;
 }
示例#2
0
        public static DiscordSettings ReadSettings(string path)
        {
            var             ser      = new XmlSerializer(typeof(DiscordSettings));
            DiscordSettings settings = null;

            if (File.Exists(path))
            {
                using (var stream = File.OpenRead(path)) settings = (DiscordSettings)ser.Deserialize(stream);
            }
            else
            {
                using (var stream = File.OpenWrite(path)) ser.Serialize(stream, settings = new DiscordSettings());
            }
            return(settings);
        }
示例#3
0
        public bool OnEnable(GameServer gameServer, bool isAfterServerLoad)
        {
            _server = gameServer;
            string configFile = "Configuration" + Path.DirectorySeparatorChar + "discordSettings.xml";

            _settings = DiscordSettings.ReadSettings(configFile);
            if (_settings.Token != "token" && _settings.Webhook != "webhook URL" && _settings.Channel != 0)
            {
                MainAsync().GetAwaiter().GetResult();
                _webhook = new DiscordWebhookClient(_settings.Webhook);
            }
            else
            {
                Console.WriteLine("Edit Discord settings in " + configFile);
                return(false);
            }
            ConnectionEvents.OnJoin.Add(OnJoin);
            ConnectionEvents.OnDisconnect.Add(OnDisconnect);
            GameEvents.OnChatMessage.Add(OnChatMessage);
            return(true);
        }