Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private async Task ChannelDestroyed(SocketChannel channel)
        {
            SocketGuildChannel guildChannel = (SocketGuildChannel)channel;

            if (guildChannel != null)
            {
                _guildSettingsTracker.RemoveAllFiltersForGuildChannel(guildChannel.Guild.Id, channel.Id);
            }

            await _guildSettingsTracker.FlushSettingsAsync();
        }