Пример #1
0
 private void LoadDefaultCommands()
 {
     _commandsList = new List <IBotCommand>()
     {
         new BotCommand("pingcmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "ping"),
                        PingCommand),
         new BotCommand("ctrlcmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "ctrl") &
                        RuleGenerator.UserByID(_superUserID),
                        CtrlCommand),
         new BotCommand("rollcmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "roll"),
                        RollCommand),
         new BotCommand("yesnocmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "yesno"),
                        BinaryChoiceCommand),
         new BotCommand("magic8ballcmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "8ball"),
                        Magic8BallCommand),
         new BotCommand("emojistatscmd",
                        RuleGenerator.PrefixatedCommand(_prefix, "emojistats") &
                        RuleGenerator.RoleByID(455287765995618304u), // VV
                        EmojiStatsCmd)
     };
 }
Пример #2
0
        protected override void GenerateUseCommands(List <ulong> perms)
        {
            // Generate base use commands from ContentModule
            base.GenerateUseCommands(perms);

            // Add verbose listing command
            List <ulong> allListPerms = new List <ulong>(_adminIds);

            allListPerms.AddRange(perms);
            Rule vlistRule = RuleGenerator.HasRoleByIds(allListPerms) & RuleGenerator.PrefixatedCommand(_prefix, "vlist");

            _useCommands.Add(new BotCommand($"{StringID}-vlistcmd", vlistRule, VerboseListCommand));
        }
Пример #3
0
        /// <summary>
        /// Generates content deletion commands from specified list of allowed role IDs.
        /// </summary>
        /// <param name="perms">List of Roles IDs which are allowed to use Delete commands.</param>
        protected virtual void GenerateDelCommands(List <ulong> perms)
        {
            List <ulong> allPerms = new List <ulong>(_adminIds);

            allPerms.AddRange(perms);
            Rule delRule = RuleGenerator.HasRoleByIds(allPerms) & RuleGenerator.PrefixatedCommand(_prefix, "del");

            IBotCommand delCmd = new BotCommand($"{StringID}-delcmd", delRule, DeleteCommand);

            _delCommands = new List <IBotCommand> {
                delCmd
            };
        }
Пример #4
0
        /// <summary>
        /// Generates content addition commands from specified list of allowed role IDs.
        /// </summary>
        /// <param name="perms">List of Roles IDs which are allowed to use Add commands.</param>
        protected virtual void GenerateAddCommands(List <ulong> perms)
        {
            List <ulong> allPerms = new List <ulong>(_adminIds);

            allPerms.AddRange(perms);
            Rule addRule = RuleGenerator.HasRoleByIds(allPerms) & RuleGenerator.PrefixatedCommand(_prefix, "add");

            IBotCommand addCmd = new BotCommand($"{StringID}-addcmd", addRule, AddCommand);

            _addCommands = new List <IBotCommand> {
                addCmd
            };
        }
Пример #5
0
        /// <summary>
        /// Generates module configuration commands from specified list of allowed role IDs.
        /// </summary>
        /// <param name="perms">List of Roles IDs which are allowed to use Config commands.</param>
        protected virtual void GenerateCfgCommands(List <ulong> perms)
        {
            List <ulong> allPerms = new List <ulong>(_adminIds);

            allPerms.AddRange(perms);
            Rule cmdRule = RuleGenerator.HasRoleByIds(allPerms) & RuleGenerator.PrefixatedCommand(_prefix, "cfg");

            IBotCommand configCmd = new BotCommand($"{StringID}-configcmd", cmdRule, ConfigCommand);

            _cfgCommands = new List <IBotCommand> {
                configCmd
            };
        }
Пример #6
0
        /// <summary>
        /// Generates content usage commands from specified list of allowed role IDs.
        /// </summary>
        /// <param name="perms">List of Roles IDs which are allowed to use Use commands.</param>
        protected virtual void GenerateUseCommands(List <ulong> perms)
        {
            List <IBotCommand> useCommands = new List <IBotCommand>();

            var stringKeys = RPKeyListGenerator(_moduleConfig.Root, String.Empty, true);

            List <ulong> allUsePerms = new List <ulong>(_adminIds);

            allUsePerms.AddRange(perms);
            Rule useRule;

            foreach (var strKey in stringKeys)
            {
                useRule = RuleGenerator.HasRoleByIds(allUsePerms) &
                          RuleGenerator.PrefixatedCommand(_prefix, strKey) &
                          !RuleGenerator.UserByID(_clientId); // prevent bot triggering on itself

                useCommands.Add(new BotCommand($"{StringID}-{strKey}-usecmd", useRule, UseCommandGenerator(strKey)));
            }

            useRule = RuleGenerator.HasRoleByIds(allUsePerms) &
                      RuleGenerator.TextIdentity(_prefix) &
                      !RuleGenerator.UserByID(_clientId);

            // to support empty prefix commands e.g. c! or i!
            useCommands.Add(new BotCommand($"{StringID}-usecmd", useRule, UseCommandGenerator(String.Empty)));

            List <ulong> allHelpPerms = new List <ulong>(_adminIds);

            allHelpPerms.AddRange(perms);
            Rule helpRule = RuleGenerator.HasRoleByIds(allHelpPerms) & RuleGenerator.PrefixatedCommand(_prefix, "help");

            useCommands.Add(new BotCommand($"{StringID}-helpcmd", helpRule, HelpCommand));

            List <ulong> allListPerms = new List <ulong>(_adminIds);

            allListPerms.AddRange(perms);
            Rule listRule = RuleGenerator.HasRoleByIds(allListPerms) & RuleGenerator.PrefixatedCommand(_prefix, "list");

            useCommands.Add(new BotCommand($"{StringID}-listcmd", listRule, ListCommand));

            List <ulong> allSearchPerms = new List <ulong>(_adminIds);

            allSearchPerms.AddRange(perms);
            Rule searchRule = RuleGenerator.HasRoleByIds(allSearchPerms) & RuleGenerator.PrefixatedCommand(_prefix, "search");

            useCommands.Add(new BotCommand($"{StringID}-searchcmd", searchRule, SearchCommand));

            _useCommands = useCommands;
        }
Пример #7
0
        protected override async Task AddCommand(SocketMessage msg)
        {
            string cmdPrefix = $"[{LogPref}][ADD]";
            await msg.DeleteAsyncSafe(cmdPrefix).ConfigureAwait(false);

            if (!Regex.IsMatch(msg.Content, AddCommandRegex))
            {
                return;
            }

            var regexMatch = Regex.Match(msg.Content, AddCommandRegex);

            string[] keys = regexMatch.Groups["key"].Value.Split('.');

            if (_blacklistedKeys.Any(blKey => blKey.ExactAs(keys[0])))
            {
                return;
            }

            XElement newItem;

            try
            {
                Attachment att = msg.Attachments.FirstOrDefault(att => RuleGenerator.IsImage(att));
                if (att == null)
                {
                    return;
                }

                string newItemGuidString = $"{Guid.NewGuid()}";
                string newItemFileName   = $"{newItemGuidString}{Path.GetExtension(att.Filename)}";

                newItem = new XElement("item",
                                       new XAttribute("name", newItemGuidString),
                                       newItemFileName);

                string filepath = Path.Combine(_guildPath, ModuleFolder, newItemFileName);

                await DownloadFile(att, msg.Channel, filepath).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ex.LogToConsole($"{cmdPrefix} File download failed: {regexMatch.Groups["key"].Value}");
                throw;
            }

            XElement currentEl = _moduleConfig.Root;

            foreach (var key in keys)
            {
                XElement newEl = currentEl.Elements("key").FirstOrDefault(
                    el => el.Attribute("name") != null && key.ExactAs(el.Attribute("name").Value));

                if (newEl == null)
                {
                    newEl = new XElement("key", new XAttribute("name", key));
                    currentEl.Add(newEl);
                }
                currentEl = newEl;
            }
            currentEl.Add(newItem);

            try
            {
                await ModuleConfigChanged().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                ex.LogToConsole($"{cmdPrefix} Config save failed.");
                throw;
            }

            Reconfigure(_configEl);
            await msg.Channel.SendMessageAsyncSafe("Зберіг пікчу " + EmojiCodes.DankPepe).ConfigureAwait(false);
        }