Example #1
0
        public async Task <bool> TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName)
        {
            await Task.Yield();

            commandName = commandName.ToLowerInvariant();

            if (commandName != "resetglobalperms" &&
                (BlockedCommands.Contains(commandName) ||
                 BlockedModules.Contains(moduleName.ToLowerInvariant())))
            {
                return(true);
                //return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"Command or module is blocked globally by the bot owner."));
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Load the <see cref="ServerSettingsFile"/> from xml.
        /// Returns success.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public bool FromXML(string xml)
        {
            bool retVal = true;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlNode root = doc.LastChild; // FirstChild is decl

                var blockedModuleNodes = root["BlockedModules"];
                if (blockedModuleNodes != null)
                {
                    foreach (XmlElement node in blockedModuleNodes.OfType <XmlElement>())
                    {
                        BlockedModules.Add(node.InnerText);
                    }
                }
                CommandSymbol     = root["CommandSymbol"].InnerText;
                JoinQuitChannelId = (root["JoinQuitChannelId"].InnerText);
                var joinServerMessageNodes = root["JoinServerMessages"];
                if (joinServerMessageNodes != null)
                {
                    foreach (XmlElement node in joinServerMessageNodes.OfType <XmlElement>())
                    {
                        JoinServerMessages.Add(node.InnerText);
                    }
                }
                Language = root["Language"].InnerText;
                var quitServerMessageNodes = root["QuitServerMessages"];
                if (quitServerMessageNodes != null)
                {
                    foreach (XmlElement node in quitServerMessageNodes.OfType <XmlElement>())
                    {
                        QuitServerMessages.Add(node.InnerText);
                    }
                }
                var rateChannelNodes = root["RateChannels"];
                if (rateChannelNodes != null)
                {
                    foreach (XmlElement node in rateChannelNodes.OfType <XmlElement>())
                    {
                        RateChannels.Add(node.InnerText);
                    }
                }
                var scheduledMessagesNode = root["ScheduledMessages"];
                if (scheduledMessagesNode != null)
                {
                    foreach (XmlElement node in scheduledMessagesNode.OfType <XmlElement>())
                    {
                        ulong  channelId = ulong.Parse(node.GetElementsByTagName("Channel")[0].InnerText);
                        ushort id        = ushort.Parse(node.GetElementsByTagName("Id")[0].InnerText);
                        ScheduledMessages.Add(
                            new ScheduledMessageData(channelId, id)
                        {
                            enabled            = bool.Parse(node.GetElementsByTagName("Enabled")[0].InnerText),
                            message            = node.GetElementsByTagName("Message")[0].InnerText,
                            nextDue            = new DateTime(long.Parse(node.GetElementsByTagName("NextDueTicks")[0].InnerText)),
                            repetitionTimeSpan = new TimeSpan(long.Parse(node.GetElementsByTagName("RepetitionTicks")[0].InnerText)),
                        }
                            );
                    }
                }
                var splatoon2RotationChannelNodes = root["Splatoon2RotationChannels"];
                if (splatoon2RotationChannelNodes != null)
                {
                    foreach (XmlElement node in splatoon2RotationChannelNodes.OfType <XmlElement>())
                    {
                        Splatoon2RotationChannels.Add(node.InnerText);
                    }
                }
                ServerId             = (root["ServerId"].InnerText);
                TrackDeletedMessages = bool.Parse(root["TrackDeletedMessages"]?.InnerText ?? "false");
            }
            catch (Exception ex)
            {
                retVal = false;
                errorLogger.LogException(ex, ErrorSeverity.Error);
            }

            return(retVal);
        }