Exemplo n.º 1
0
        public async Task ListCustReact(int page = 1)
        {
            if (page < 1 || page > 1000)
            {
                return;
            }
            CustomReaction[] customReactions;
            if (Context.Guild == null)
            {
                customReactions = GlobalReactions.Where(cr => cr != null).ToArray();
            }
            else
            {
                customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty <CustomReaction>()).Where(cr => cr != null).ToArray();
            }

            if (customReactions == null || !customReactions.Any())
            {
                await Context.Channel.SendErrorAsync("No custom reactions found").ConfigureAwait(false);
            }
            else
            {
                var lastPage = customReactions.Length / 20;
                await Context.Channel.SendPaginatedConfirmAsync(page, curPage =>
                                                                new EmbedBuilder().WithOkColor()
                                                                .WithTitle("Custom reactions")
                                                                .WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger)
                                                                                             .Skip((curPage - 1) * 20)
                                                                                             .Take(20)
                                                                                             .Select(cr => $"`#{cr.Id}`  `Trigger:` {cr.Trigger}"))), lastPage)
                .ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task ListCustReact(All x)
        {
            CustomReaction[] customReactions;
            if (Context.Guild == null)
            {
                customReactions = GlobalReactions.Where(cr => cr != null).ToArray();
            }
            else
            {
                customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[] { }).Where(cr => cr != null).ToArray();
            }

            if (customReactions == null || !customReactions.Any())
            {
                await ReplyErrorLocalized("no_found").ConfigureAwait(false);

                return;
            }

            var txtStream = await customReactions.GroupBy(cr => cr.Trigger)
                            .OrderBy(cr => cr.Key)
                            .Select(cr => new { Trigger = cr.Key, Responses = cr.Select(y => new { id = y.Id, text = y.Response }).ToList() })
                            .ToJson()
                            .ToStream()
                            .ConfigureAwait(false);

            if (Context.Guild == null) // its a private one, just send back
            {
                await Context.Channel.SendFileAsync(txtStream, "customreactions.txt", GetText("list_all")).ConfigureAwait(false);
            }
            else
            {
                await((IGuildUser)Context.User).SendFileAsync(txtStream, "customreactions.txt", GetText("list_all")).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        /***************************************************/
        /**** Private method - Extraction methods       ****/
        /***************************************************/

        private List <GlobalReactions> GetGlobalReactions()
        {
            List <GlobalReactions> globalReactions = new List <GlobalReactions>();

            int resultCount = 0;

            string[] loadcaseNames = null;
            string[] stepType = null; double[] stepNum = null;
            double[] fx = null; double[] fy = null; double[] fz = null;
            double[] mx = null; double[] my = null; double[] mz = null;
            double   gx = 0; double gy = 0; double gz = 0;

            m_model.Results.BaseReact(ref resultCount, ref loadcaseNames, ref stepType, ref stepNum, ref fx, ref fy, ref fz, ref mx, ref my, ref mz, ref gx, ref gy, ref gz);

            for (int i = 0; i < resultCount; i++)
            {
                int    mode;
                double timeStep;
                GetStepAndMode(stepType[i], stepNum[i], out timeStep, out mode);

                GlobalReactions g = new GlobalReactions("", loadcaseNames[i], mode, timeStep, fx[i], fy[i], fz[i], mx[i], my[i], mz[i]);

                globalReactions.Add(g);
            }

            return(globalReactions);
        }
Exemplo n.º 4
0
        public async Task DelCustReact(int id)
        {
            if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) || (Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
            {
                await ReplyErrorLocalized("insuff_perms").ConfigureAwait(false);

                return;
            }

            var            success = false;
            CustomReaction toDelete;

            using (var uow = DbHandler.UnitOfWork())
            {
                toDelete = uow.CustomReactions.Get(id);
                if (toDelete == null) //not found
                {
                    success = false;
                }
                else
                {
                    if ((toDelete.GuildId == null || toDelete.GuildId == 0) && Context.Guild == null)
                    {
                        uow.CustomReactions.Remove(toDelete);
                        //todo i can dramatically improve performance of this, if Ids are ordered.
                        _globalReactions = GlobalReactions.Where(cr => cr?.Id != toDelete.Id).ToArray();
                        success          = true;
                    }
                    else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && (long)Context.Guild.Id == toDelete.GuildId)
                    {
                        uow.CustomReactions.Remove(toDelete);
                        GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { }, (key, old) =>
                        {
                            return(old.Where(cr => cr?.Id != toDelete.Id).ToArray());
                        });
                        success = true;
                    }
                    if (success)
                    {
                        await uow.CompleteAsync().ConfigureAwait(false);
                    }
                }
            }

            if (success)
            {
                await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                                 .WithTitle(GetText("deleted"))
                                                 .WithDescription("#" + toDelete.Id)
                                                 .AddField(efb => efb.WithName(GetText("trigger")).WithValue(toDelete.Trigger))
                                                 .AddField(efb => efb.WithName(GetText("response")).WithValue(toDelete.Response)));
            }
            else
            {
                await ReplyErrorLocalized("no_found_id").ConfigureAwait(false);
            }
        }
Exemplo n.º 5
0
        public async Task DelCustReact(int id)
        {
            if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) || (Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
            {
                try { await Context.Channel.SendErrorAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
                return;
            }

            var            success = false;
            CustomReaction toDelete;

            using (var uow = DbHandler.UnitOfWork())
            {
                toDelete = uow.CustomReactions.Get(id);
                if (toDelete == null) //not found
                {
                    return;
                }

                if ((toDelete.GuildId == null || toDelete.GuildId == 0) && Context.Guild == null)
                {
                    uow.CustomReactions.Remove(toDelete);
                    //todo i can dramatically improve performance of this, if Ids are ordered.
                    _globalReactions = GlobalReactions.Where(cr => cr?.Id != toDelete.Id).ToArray();
                    success          = true;
                }
                else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && Context.Guild.Id == toDelete.GuildId)
                {
                    uow.CustomReactions.Remove(toDelete);
                    GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { }, (key, old) =>
                    {
                        return(old.Where(cr => cr?.Id != toDelete.Id).ToArray());
                    });
                    success = true;
                }
                if (success)
                {
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }

            if (success)
            {
                await Context.Channel.SendConfirmAsync("Deleted custom reaction", toDelete.ToString()).ConfigureAwait(false);
            }
            else
            {
                await Context.Channel.SendErrorAsync("Failed to find that custom reaction.").ConfigureAwait(false);
            }
        }
Exemplo n.º 6
0
        public async Task AddCustReact(IUserMessage imsg, string key, [Remainder] string message)
        {
            var channel = imsg.Channel as ITextChannel;

            if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            key = key.ToLowerInvariant();

            if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
            {
                try { await imsg.Channel.SendErrorAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
                return;
            }

            var cr = new CustomReaction()
            {
                GuildId  = channel?.Guild.Id,
                IsRegex  = false,
                Trigger  = key,
                Response = message,
            };

            using (var uow = DbHandler.UnitOfWork())
            {
                uow.CustomReactions.Add(cr);

                await uow.CompleteAsync().ConfigureAwait(false);
            }

            if (channel == null)
            {
                GlobalReactions.Add(cr);
            }
            else
            {
                var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>());
                reactions.Add(cr);
            }

            await imsg.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
                                          .WithTitle("New Custom Reaction")
                                          .WithDescription($"#{cr.Id}")
                                          .AddField(efb => efb.WithName("Trigger").WithValue(key))
                                          .AddField(efb => efb.WithName("Response").WithValue(message))
                                          .Build()).ConfigureAwait(false);
        }
Exemplo n.º 7
0
        public async Task DelCustReact(IUserMessage imsg, int id)
        {
            var channel = imsg.Channel as ITextChannel;

            if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
            {
                try { await imsg.Channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
                return;
            }

            var            success = false;
            CustomReaction toDelete;

            using (var uow = DbHandler.UnitOfWork())
            {
                toDelete = uow.CustomReactions.Get(id);
                if (toDelete == null) //not found
                {
                    return;
                }

                if ((toDelete.GuildId == null || toDelete.GuildId == 0) && channel == null)
                {
                    uow.CustomReactions.Remove(toDelete);
                    GlobalReactions.RemoveWhere(cr => cr.Id == toDelete.Id);
                    success = true;
                }
                else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && channel?.Guild.Id == toDelete.GuildId)
                {
                    uow.CustomReactions.Remove(toDelete);
                    GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id);
                    success = true;
                }
                if (success)
                {
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }

            if (success)
            {
                await imsg.Channel.SendMessageAsync("**Successfully deleted custom reaction** " + toDelete.ToString()).ConfigureAwait(false);
            }
            else
            {
                await imsg.Channel.SendMessageAsync("`Failed to find that custom reaction.`").ConfigureAwait(false);
            }
        }
Exemplo n.º 8
0
        public static async Task <bool> TryExecuteCustomReaction(IUserMessage umsg)
        {
            var channel = umsg.Channel as ITextChannel;

            if (channel == null)
            {
                return(false);
            }

            var content = umsg.Content.Trim().ToLowerInvariant();
            ConcurrentHashSet <CustomReaction> reactions;

            GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
            if (reactions != null && reactions.Any())
            {
                var reaction = reactions.Where(cr =>
                {
                    var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                    var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                    return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
                }).Shuffle().FirstOrDefault();
                if (reaction != null)
                {
                    if (reaction.Response != "-")
                    {
                        try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
                    }

                    ReactionStats.AddOrUpdate(reaction.Trigger, 1, (k, old) => ++ old);
                    return(true);
                }
            }
            var greaction = GlobalReactions.Where(cr =>
            {
                var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
            }).Shuffle().FirstOrDefault();

            if (greaction != null)
            {
                try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
                ReactionStats.AddOrUpdate(greaction.Trigger, 1, (k, old) => ++ old);
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public async Task DelCustReact(int id)
        {
            if ((Context.Guild == null && !NadekoBot.Credentials.IsOwner(Context.User)) || (Context.Guild != null && !((IGuildUser)Context.User).GuildPermissions.Administrator))
            {
                try { await Context.Channel.SendErrorAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
                return;
            }

            var            success = false;
            CustomReaction toDelete;

            using (var uow = DbHandler.UnitOfWork())
            {
                toDelete = uow.CustomReactions.Get(id);
                if (toDelete == null) //not found
                {
                    return;
                }

                if ((toDelete.GuildId == null || toDelete.GuildId == 0) && Context.Guild == null)
                {
                    uow.CustomReactions.Remove(toDelete);
                    GlobalReactions.RemoveWhere(cr => cr.Id == toDelete.Id);
                    success = true;
                }
                else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && Context.Guild.Id == toDelete.GuildId)
                {
                    uow.CustomReactions.Remove(toDelete);
                    GuildReactions.GetOrAdd(Context.Guild.Id, new ConcurrentHashSet <CustomReaction>()).RemoveWhere(cr => cr.Id == toDelete.Id);
                    success = true;
                }
                if (success)
                {
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }

            if (success)
            {
                await Context.Channel.SendConfirmAsync("Deleted custom reaction", toDelete.ToString()).ConfigureAwait(false);
            }
            else
            {
                await Context.Channel.SendErrorAsync("Failed to find that custom reaction.").ConfigureAwait(false);
            }
        }
Exemplo n.º 10
0
        public static List<GlobalReactions> GetGlobalReactions(cSapModel model, IList cases = null)
        {
            List<string> loadcaseIds = new List<string>();
            List<GlobalReactions> globalReactions = new List<GlobalReactions>();

            int resultCount = 0;
            string[] loadcaseNames = null;
            string[] stepType = null; double[] stepNum = null;
            double[] fx = null; double[] fy = null; double[] fz = null;
            double[] mx = null; double[] my = null; double[] mz = null;
            double gx = 0; double gy = 0; double gz = 0;

            //Get out loadcases, get all for null list
            loadcaseIds = CheckAndGetCases(model, cases);

            model.Results.Setup.DeselectAllCasesAndCombosForOutput();

            for (int loadcase = 0; loadcase < loadcaseIds.Count; loadcase++)
            {
                if (model.Results.Setup.SetCaseSelectedForOutput(loadcaseIds[loadcase]) != 0)
                {
                    model.Results.Setup.SetComboSelectedForOutput(loadcaseIds[loadcase]);
                }
            }

            model.Results.BaseReact(ref resultCount, ref loadcaseNames, ref stepType, ref stepNum, ref fx, ref fy, ref fz, ref mx, ref my, ref mz, ref gx, ref gy, ref gz);

            for (int i = 0; i < resultCount; i++)
            {
                GlobalReactions g = new GlobalReactions()
                {
                    ResultCase = loadcaseNames[i],
                    FX = fx[i],
                    FY = fy[i],
                    FZ = fz[i],
                    MX = mx[i],
                    MY = my[i],
                    MZ = mz[i],
                    TimeStep = stepNum[i]
                };

                globalReactions.Add(g);
            }

            return globalReactions;
        }
Exemplo n.º 11
0
        public async Task ListCustReact(int page = 1)
        {
            if (page < 1 || page > 1000)
            {
                return;
            }
            CustomReaction[] customReactions;
            if (Context.Guild == null)
            {
                customReactions = GlobalReactions.Where(cr => cr != null).ToArray();
            }
            else
            {
                customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty <CustomReaction>()).Where(cr => cr != null).ToArray();
            }

            if (customReactions == null || !customReactions.Any())
            {
                await ReplyErrorLocalized("no_found").ConfigureAwait(false);

                return;
            }

            var lastPage = customReactions.Length / 20;
            await Context.Channel.SendPaginatedConfirmAsync(page, curPage =>
                                                            new EmbedBuilder().WithOkColor()
                                                            .WithTitle(GetText("name"))
                                                            .WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger)
                                                                                         .Skip((curPage - 1) * 20)
                                                                                         .Take(20)
                                                                                         .Select(cr =>
            {
                var str = $"`#{cr.Id}` {cr.Trigger}";
                if (cr.AutoDeleteTrigger)
                {
                    str = "🗑" + str;
                }
                if (cr.DmResponse)
                {
                    str = "📪" + str;
                }
                return(str);
            }))), lastPage)
            .ConfigureAwait(false);
        }
Exemplo n.º 12
0
        public async Task AddCustReact(IUserMessage imsg, string key, [Remainder] string message)
        {
            var channel = imsg.Channel as ITextChannel;

            if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            key = key.ToLowerInvariant();

            if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
            {
                try { await imsg.Channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
                return;
            }

            var cr = new CustomReaction()
            {
                GuildId  = channel?.Guild.Id,
                IsRegex  = false,
                Trigger  = key,
                Response = message,
            };

            using (var uow = DbHandler.UnitOfWork())
            {
                uow.CustomReactions.Add(cr);

                await uow.CompleteAsync().ConfigureAwait(false);
            }

            if (channel == null)
            {
                GlobalReactions.Add(cr);
            }
            else
            {
                var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <CustomReaction>());
                reactions.Add(cr);
            }

            await imsg.Channel.SendMessageAsync($"`Added new custom reaction {cr.Id}:`\n\t`Trigger:` {key}\n\t`Response:` {message}").ConfigureAwait(false);
        }
Exemplo n.º 13
0
        public async Task ListCustReactG(int page = 1)
        {
            if (page < 1 || page > 10000)
            {
                return;
            }
            CustomReaction[] customReactions;
            if (Context.Guild == null)
            {
                customReactions = GlobalReactions.Where(cr => cr != null).ToArray();
            }
            else
            {
                customReactions = GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[] { }).Where(cr => cr != null).ToArray();
            }

            if (customReactions == null || !customReactions.Any())
            {
                await ReplyErrorLocalized("no_found").ConfigureAwait(false);
            }
            else
            {
                var ordered = customReactions
                              .GroupBy(cr => cr.Trigger)
                              .OrderBy(cr => cr.Key)
                              .ToList();

                var lastPage = ordered.Count / 20;
                await Context.Channel.SendPaginatedConfirmAsync(page, (curPage) =>
                                                                new EmbedBuilder().WithOkColor()
                                                                .WithTitle(GetText("name"))
                                                                .WithDescription(string.Join("\r\n", ordered
                                                                                             .Skip((curPage - 1) * 20)
                                                                                             .Take(20)
                                                                                             .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage)
                .ConfigureAwait(false);
            }
        }
        public CustomReaction TryGetCustomReaction(IUserMessage umsg)
        {
            if (umsg.Channel is SocketTextChannel channel)
            {
                var content   = umsg.Content.Trim();
                var reactions = ReactionsForGuild(channel.Guild.Id);

                if (reactions.Any())
                {
                    var rs = reactions.Where(cr => {
                        var trigger = cr.TriggerWithContext(umsg, _client).Trim();
                        return(cr.ContainsAnywhere && content.GetWordPosition(trigger) != WordPosition.None ||
                               cr.Response.Contains("%target%", StringComparison.OrdinalIgnoreCase) && content.StartsWith($"{trigger} ", StringComparison.OrdinalIgnoreCase) ||
                               _bc.BotConfig.CustomReactionsStartWith && content.StartsWith($"{trigger} ", StringComparison.OrdinalIgnoreCase) ||
                               content.Equals(trigger, StringComparison.OrdinalIgnoreCase));
                    }).ToArray();

                    if (rs.Any())
                    {
                        var reaction = rs.RandomSubset(1).First();
                        return(reaction.Response == "-" ? null : reaction);
                    }
                }

                var grs = GlobalReactions.Where(cr => {
                    var hasTarget = cr.Response.Contains("%target%", StringComparison.OrdinalIgnoreCase);
                    var trigger   = cr.TriggerWithContext(umsg, _client).Trim();
                    return(hasTarget && content.StartsWith($"{trigger} ", StringComparison.OrdinalIgnoreCase) || _bc.BotConfig.CustomReactionsStartWith && content.StartsWith($"{trigger} ", StringComparison.OrdinalIgnoreCase) || content.Equals(trigger, StringComparison.OrdinalIgnoreCase));
                }).ToArray();

                return(grs.Any() ? grs.RandomSubset(1).First() : null);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 15
0
        public static async Task <bool> TryExecuteCustomReaction(SocketUserMessage umsg)
        {
            var channel = umsg.Channel as SocketTextChannel;

            if (channel == null)
            {
                return(false);
            }

            var content = umsg.Content.Trim().ToLowerInvariant();

            CustomReaction[] reactions;

            GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
            if (reactions != null && reactions.Any())
            {
                var rs = reactions.Where(cr =>
                {
                    if (cr == null)
                    {
                        return(false);
                    }

                    var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                    var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                    return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
                }).ToArray();

                if (rs.Length != 0)
                {
                    var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
                    if (reaction != null)
                    {
                        if (reaction.Response != "-")
                        {
                            CREmbed crembed;
                            if (CREmbed.TryParse(reaction.Response, out crembed))
                            {
                                try { await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); }
                                catch (Exception ex)
                                {
                                    _log.Warn("Sending CREmbed failed");
                                    _log.Warn(ex);
                                }
                            }
                            else
                            {
                                try { await channel.SendMessageAsync(reaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
                            }
                        }

                        ReactionStats.AddOrUpdate(reaction.Trigger, 1, (k, old) => ++ old);
                        return(true);
                    }
                }
            }

            var grs = GlobalReactions.Where(cr =>
            {
                if (cr == null)
                {
                    return(false);
                }
                var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
            }).ToArray();

            if (grs.Length == 0)
            {
                return(false);
            }
            var greaction = grs[new NadekoRandom().Next(0, grs.Length)];

            if (greaction != null)
            {
                CREmbed crembed;
                if (CREmbed.TryParse(greaction.Response, out crembed))
                {
                    try { await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); }
                    catch (Exception ex)
                    {
                        _log.Warn("Sending CREmbed failed");
                        _log.Warn(ex);
                    }
                }
                else
                {
                    try { await channel.SendMessageAsync(greaction.ResponseWithContext(umsg)).ConfigureAwait(false); } catch { }
                }
                ReactionStats.AddOrUpdate(greaction.Trigger, 1, (k, old) => ++ old);
                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        /***************************************************/

        public static double MTotal(this GlobalReactions reaction)
        {
            return(Math.Sqrt(reaction.MX * reaction.MX + reaction.MY * reaction.MY + reaction.MZ * reaction.MZ));
        }
Exemplo n.º 17
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static double FTotal(this GlobalReactions reaction)
        {
            return(Math.Sqrt(reaction.FX * reaction.FX + reaction.FY * reaction.FY + reaction.FZ * reaction.FZ));
        }
Exemplo n.º 18
0
        public static CustomReaction TryGetCustomReaction(IUserMessage umsg)
        {
            var channel = umsg.Channel as SocketTextChannel;

            if (channel == null)
            {
                return(null);
            }

            var content = umsg.Content.Trim().ToLowerInvariant();

            CustomReaction[] reactions;

            GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
            if (reactions != null && reactions.Any())
            {
                var rs = reactions.Where(cr =>
                {
                    if (cr == null)
                    {
                        return(false);
                    }

                    var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                    var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                    return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
                }).ToArray();

                if (rs.Length != 0)
                {
                    var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
                    if (reaction != null)
                    {
                        if (reaction.Response == "-")
                        {
                            return(null);
                        }
                        return(reaction);
                    }
                }
            }

            var grs = GlobalReactions.Where(cr =>
            {
                if (cr == null)
                {
                    return(false);
                }
                var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
                var trigger   = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
                return((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
            }).ToArray();

            if (grs.Length == 0)
            {
                return(null);
            }
            var greaction = grs[new NadekoRandom().Next(0, grs.Length)];

            return(greaction);
        }