Exemple #1
0
        public async Task <string> TransformInput(IGuild guild, IMessageChannel channel, IUser user, string input)
        {
            await Task.Yield();

            if (guild == null || string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            if (guild != null)
            {
                input = input.ToLowerInvariant();
                if (AliasMaps.TryGetValue(guild.Id, out ConcurrentDictionary <string, string> maps))
                {
                    var keys = maps.Keys
                               .OrderByDescending(x => x.Length);

                    foreach (var k in keys)
                    {
                        string newInput;
                        if (input.StartsWith(k + " "))
                        {
                            newInput = maps[k] + input.Substring(k.Length, input.Length - k.Length);
                        }
                        else if (input == k)
                        {
                            newInput = maps[k];
                        }
                        else
                        {
                            continue;
                        }

                        _log.Info(@"--Mapping Command--
            GuildId: {0}
            Trigger: {1}
            Mapping: {2}", guild.Id, input, newInput);

                        try
                        {
                            var toDelete = await channel.SendConfirmAsync($"{input} => {newInput}").ConfigureAwait(false);

                            var _ = Task.Run(async() =>
                            {
                                await Task.Delay(1500);
                                await toDelete.DeleteAsync(new RequestOptions()
                                {
                                    RetryMode = RetryMode.AlwaysRetry
                                });
                            });
                        }
                        catch { }
                        return(newInput);
                    }
                }
            }

            return(input);
        }
        public async Task <string> TransformInput(IGuild guild, IMessageChannel channel, IUser user, string input)
        {
            await Task.Yield();

            if (guild == null || string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            if (guild != null)
            {
                if (AliasMaps.TryGetValue(guild.Id, out ConcurrentDictionary <string, string> maps))
                {
                    var keys = maps.Keys
                               .OrderByDescending(x => x.Length);

                    foreach (var k in keys)
                    {
                        string newInput;
                        if (input.StartsWith(k + " ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            newInput = maps[k] + input.Substring(k.Length, input.Length - k.Length);
                        }
                        else if (input.Equals(k, StringComparison.InvariantCultureIgnoreCase))
                        {
                            newInput = maps[k];
                        }
                        else
                        {
                            continue;
                        }

                        //try { await channel.SendConfirmAsync($"{input} => {newInput}").ConfigureAwait(false); } catch { }
                        //return newInput;
                        try
                        {
                            var toDelete = await channel.SendConfirmAsync($"{input} => {newInput}").ConfigureAwait(false);

                            var _ = Task.Run(async() =>
                            {
                                await Task.Delay(1500).ConfigureAwait(false);
                                await toDelete.DeleteAsync(new RequestOptions()
                                {
                                    RetryMode = RetryMode.AlwaysRetry
                                }).ConfigureAwait(false);
                            });
                        }
                        catch { }
                    }
                }
            }

            return(input);
        }
Exemple #3
0
        public async Task <string> TransformInput(IGuild guild, IMessageChannel channel, IUser user, string input, bool realExecution = true)
        {
            await Task.Yield();

            if (guild == null || string.IsNullOrWhiteSpace(input))
            {
                return(input);
            }

            input = input.ToLowerInvariant();
            if (!AliasMaps.TryGetValue(guild.Id, out var maps))
            {
                return(input);
            }
            var keys = maps.Keys.OrderByDescending(x => x.Length);

            foreach (var k in keys)
            {
                string newInput;
                if (input.StartsWith(k + " "))
                {
                    newInput = maps[k] + input.Substring(k.Length, input.Length - k.Length);
                }
                else if (input == k)
                {
                    newInput = maps[k];
                }
                else
                {
                    continue;
                }

                if (!realExecution)
                {
                    return(newInput);
                }

                _log.Info($"--Mapping Command--\nGuildId: {guild.Id}\nTrigger: {input}\nMapping: {newInput}");
                try { await channel.SendConfirmAsync($"{input} => {newInput}").ConfigureAwait(false); } catch { /*ignore*/ }
                return(newInput);
            }

            return(input);
        }
 private async Task <IUserMessage> EmbedAsync(string key, params object[] replacements)
 => await UserChannel.SendConfirmAsync(GetText($"{key}_text", replacements), GetText($"{key}_title")).ConfigureAwait(false);