Example #1
0
        private async Task CommandClearFilters(IMessageChannel channel)
        {
            StringBuilder stringBuilder = new StringBuilder();

            ulong guildId = ((SocketGuildChannel)channel).Guild.Id;

            GuildSettingsTracker.ActionResult result = _settingsTracker.ClearFiltersForGuild(guildId);

            switch (result)
            {
            case GuildSettingsTracker.ActionResult.GuildNotFound:
                stringBuilder.Append("Nothing happend, internal error: Guild Not Found.");
                break;

            case GuildSettingsTracker.ActionResult.TrackedMessageNotFound:
                stringBuilder.Append("You don't have any filters active, but I cleared them anyway... just to be sure ;)");
                break;

            case GuildSettingsTracker.ActionResult.Succesful:
            {
                stringBuilder.Append("All your filters have been removed!");
                Task flushTask = _settingsTracker.FlushSettingsAsync().ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
            }
            break;
            }

            Task msgTask = channel.SendMessageAsync(stringBuilder.ToString()).ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
        }
Example #2
0
        private async Task CommandAddFilter(IMessageChannel channel, string rawMessage)
        {
            StringBuilder stringBuilder = new StringBuilder();

            string[] rawMessageWordsArray = rawMessage.Split(' ');

            if (rawMessageWordsArray.Length != _numCommandParams[(int)CommandId.AddFilter])
            {
                stringBuilder.Append(rawMessageWordsArray.Length < _numCommandParams[(int)CommandId.AddFilter] ? "Too **few** arguments in the command." : "Too **many** arguments in the command.");
                stringBuilder.Append("\nType \"!tr help\" for instructions of how to use all the commands.");
            }
            else
            {
                ulong       channelId;
                SocketGuild guild = ((SocketGuildChannel)channel).Guild;
                if (ChannelHelper.GetChannelIdFromName(guild, rawMessageWordsArray[0], out channelId))
                {
                    GuildSettingsTracker.ActionResult result = _settingsTracker.AddFilterToGuild(guild.Id, channelId, rawMessageWordsArray[1]);

                    switch (result)
                    {
                    case GuildSettingsTracker.ActionResult.GuildNotFound:
                        stringBuilder.Append("Nothing happend, internal error: Guild Not Found.");
                        break;

                    case GuildSettingsTracker.ActionResult.ChannelNotFound:
                        stringBuilder.Append("I can't find the channel you're trying to reroute to, are you sure it's spelled correctly? \"" + rawMessageWordsArray[0] + "\". If it is spelled correctly, I might not have permissions for that channel :(");
                        break;

                    case GuildSettingsTracker.ActionResult.FilterAlreadyExists:
                        stringBuilder.Append("It already exists a filter for the message that you're trying to add.");
                        break;

                    case GuildSettingsTracker.ActionResult.Succesful:
                    {
                        stringBuilder.Append("Filter added for *" + rawMessageWordsArray[1] + "* which will be rerouted to *#" + rawMessageWordsArray[0] + "*.");
                        Task flushTask = _settingsTracker.FlushSettingsAsync().ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);;
                    }
                    break;
                    }
                }
                else
                {
                    stringBuilder.Append("I can't find the channel you're trying to reroute to, are you sure it's spelled correctly? \"" + rawMessageWordsArray[0] + "\". If it is spelled correctly, I might not have permissions for that channel :(");
                }
            }

            Task msgTask = channel.SendMessageAsync(stringBuilder.ToString()).ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
        }
Example #3
0
        private async Task CommandRemoveFilter(IMessageChannel channel, string rawMessage)
        {
            StringBuilder stringBuilder = new StringBuilder();
            ulong         guildId       = ((SocketGuildChannel)channel).Guild.Id;

            string[] rawMessageWordsArray = rawMessage.Split(' ');

            if (rawMessageWordsArray.Length != _numCommandParams[(int)CommandId.RemoveFilter])
            {
                stringBuilder.Append(rawMessageWordsArray.Length < _numCommandParams[(int)CommandId.RemoveFilter] ? "Too **few** arguments in the command." : "Too **many** arguments in the command.");
                stringBuilder.Append("\nType \"!tr help\" for instructions of how to use all the commands.");
            }
            else if (string.IsNullOrEmpty(rawMessage))
            {
                stringBuilder.Append("Too **few** arguments in the command.");
                stringBuilder.Append("\nType \"!tr help\" for instructions of how to use all the commands.");
            }
            else
            {
                GuildSettingsTracker.ActionResult result = _settingsTracker.RemoveFilterFromGuild(guildId, rawMessageWordsArray[0]);

                switch (result)
                {
                case GuildSettingsTracker.ActionResult.GuildNotFound:
                    stringBuilder.Append("Nothing happend, internal error: Guild Not Found.");
                    break;

                case GuildSettingsTracker.ActionResult.TrackedMessageNotFound:
                    stringBuilder.Append("I couldn't find any filter for the message *" + rawMessageWordsArray[0] + "* :( Make sure it's an exact match.");
                    break;

                case GuildSettingsTracker.ActionResult.Succesful:
                {
                    stringBuilder.Append("The filter for *" + rawMessageWordsArray[0] + "* has been removed!");
                    Task flushTask = _settingsTracker.FlushSettingsAsync().ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);;
                }
                break;
                }
            }

            Task msgTask = channel.SendMessageAsync(stringBuilder.ToString()).ContinueWith(t => Console.WriteLine(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
        }