Exemple #1
0
        internal async Task HandleMessage(SocketMessage msg)
        {
            int argPos = 0;
            var prefix = await _settingManager.GetSettingValue("GUILDCONFIG_PREFIX", Guild);

#if DEBUG
            prefix = "!!!";
#endif

            if (msg is IUserMessage message && !message.Author.IsBot && message.Author.Id != _client.CurrentUser.Id)
            {
                var context = new FRToolsSocketCommandContext(_client, msg as SocketUserMessage);

                if (message.HasStringPrefix(prefix, ref argPos) && !char.IsNumber(message.Content[argPos]) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
                {
                    if (message.Content.Substring(argPos) == "help")
                    {
                        await context.Channel.SendMessageAsync(embed : new EmbedBuilder().WithDescription($"Please see the following link for help. [click here]({ConfigurationManager.AppSettings["WebsiteBaseURL"]}/discord/help)").Build());

                        return;
                    }
                    var result = await _globalCommandService.ExecuteAsync(context, argPos, _serviceProvider);

                    if (!result.IsSuccess)
                    {
                        if (result.Error == CommandError.UnknownCommand)
                        {
                            await msg.Channel.SendMessageAsync($"Unknown command")
                            .ContinueWith(x => x.Result.DelayedDelete(TimeSpan.FromSeconds(10)));
                        }
                        else
                        {
                            await msg.Channel.SendMessageAsync($"```{result.ErrorReason}```").ContinueWith(x => x.Result.DelayedDelete(TimeSpan.FromSeconds(10)));
                        }
                    }
                }
                else if (message.Content.StartsWith("https://www1.flightrising.com/"))
                {
                    // Handle FR links as commands
                    if (bool.TryParse(await _settingManager.GetSettingValue("LOOKUP_AUTO_LINK", Guild), out var dragonAutoLink) && dragonAutoLink)
                    {
                        var allowedChannels = (await _settingManager.GetSettingValue("LOOKUP_AUTO_LINK_CHANNELS", context.Guild)).Split(',').Select(x => ulong.Parse(x));
                        if (!allowedChannels.Contains(message.Channel.Id))
                        {
                            return;
                        }

                        context.AutomatedCommand = true;
                        var dragonLink = Regex.Match(message.Content, @".+/dragon/(\d+)");
                        if (dragonLink.Success)
                        {
                            await _globalCommandService.ExecuteAsync(context, $"lookup dragon {dragonLink.Groups[1].Value}", _serviceProvider);

                            return;
                        }

                        var itemLink = Regex.Match(message.Content, @".+/game-database/item/(\d+)");
                        if (itemLink.Success)
                        {
                            await _globalCommandService.ExecuteAsync(context, $"lookup item {itemLink.Groups[1].Value}", _serviceProvider);

                            return;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static async Task <(EmbedBuilder Embed, IEnumerable <KeyValuePair <string, Stream> > Files)> CreateItemEmbed(FRItem item, FRToolsSocketCommandContext context, SettingManager settingManager, bool flashSale = false)
        {
            var embedResult = await CreateItemEmbed(item, context.Guild, settingManager, flashSale);

            if (context.AutomatedCommand)
            {
                embedResult.Embed.WithFooter("This command was executed automatically. Don't want this? Have an administrator change the settings.");
            }

            return(embedResult);
        }