Beispiel #1
0
        private async Task CheckInitThread(Cacheable<IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            var usr = await arg2.GetUserAsync(arg3.UserId);
            if (usr.IsBot)
                return;

            if (Setups.ContainsKey(arg2.Id))
            {
                var msg = await arg2.GetMessageAsync(Setups[arg2.Id].Key);

                //checkmark
                if (arg3.Emote.Equals(new Emoji("✅")))
                {
                    if (client.GetGuild(Global.SwissGuildId).Users.Any(x => x.Id == usr.Id))
                    {
                        if (BlockedUsers.Any(x => x == usr.Id))
                        {
                            await arg2.SendMessageAsync("", false, new EmbedBuilder()
                            {
                                Title = "You are blocked!",
                                Description = "Looks like your blocked from creating support tickets :/",
                                Color = Color.Red
                            }.Build());
                            Setups.Remove(arg2.Id);
                            await msg.DeleteAsync();
                            return;
                        }
                        else
                        {
                            await msg.DeleteAsync();
                            var tmpmsg = await arg2.SendMessageAsync("**Creating support ticket with the staff team...**");
                            await CreateNewTicket(arg2, usr, Setups[arg2.Id].Value);
                            await tmpmsg.ModifyAsync(x => x.Embed = new EmbedBuilder()
                            {
                                Title = "Congrats! You are now talking with staff!",
                                Description = "Please note staff **Can** take moderation action for anything you say in a ticket. The same rules apply as the server.\n_This ticket may also be archived and used for training purposes._",
                                Color = Color.Green
                            }.Build());
                        }
                    }
                    else
                    {
                        await usr.SendMessageAsync("", false, new EmbedBuilder()
                        {
                            Title = "Sorry... :(",
                            Description = "The staff team does not accept tickets from users who are not in the server.",
                            Color = Color.Red
                        }.Build());
                    }

                }
                else if (arg3.Emote.Equals(new Emoji("❌"))) // xmark
                {
                    Setups.Remove(arg2.Id);
                    await msg.DeleteAsync();
                }
            }
            else if (closingState.Keys.Any(x => x.Key == arg2.Id))
            {
                var o = closingState.First(x => x.Key.Key == arg2.Id);
                var msg = await arg2.GetMessageAsync(o.Key.Value);

                if (arg3.Emote.Equals(new Emoji("❌")))
                {
                    o.Value.Stop();
                    o.Value.Dispose();
                    closingState.Remove(o.Key);
                    await msg.DeleteAsync();
                }
            }
            else if (WelcomeMessages.Contains(arg3.MessageId))
            {
                if (arg3.Emote.Equals(new Emoji("❌")))
                {
                    var msg = await arg2.GetMessageAsync(arg3.MessageId);
                    await msg.DeleteAsync();
                }
                if (arg3.Emote.Equals(new Emoji("✅")))
                {
                    var ticket = CurrentTickets.Find(x => x.TicketChannel == arg2.Id);
                    var msg = await arg2.GetMessageAsync(arg3.MessageId);
                    var dmchan = await client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();
                    var gusr = usr as SocketGuildUser;
                    await msg.DeleteAsync();
                    string tmsg = $"**[Staff] {(gusr.Nickname == null ? usr.ToString() : gusr.Nickname)}** - Hello! Swiss001 Support! How May I help you?";
                    await arg2.SendMessageAsync(tmsg);
                    await dmchan.SendMessageAsync(tmsg);
                }
            }
        }
Beispiel #2
0
        public void ApplySetupReturns <T, TReturn>(Expression <Func <T, TReturn> > expression, TReturn returnValue)
        {
            // we already know we're not null here. courtesy of the caller.
            var methodCallExpression = expression.Body as MethodCallExpression;

            var methodName = methodCallExpression.Method.Name;
            var arguments  = methodCallExpression.Arguments.ToArray();

            if (this.IsApplySetupReturnsInProgess)
            {
                throw new InvalidOperationException("There is already an evaluation of the arguments pending for a property set. There might be a bug in Moqingbirt. Were you using multithreading by any chance ?");
            }

            this.IsApplySetupReturnsInProgess = true;

            // build a list of predicated of all the available parameters.
            MatchIt.RecordMatches = true;
            foreach (var argument in arguments)
            {
                var recordedMatches  = MatchIt.LastMatch.Count;
                var compiledArgument = Expression.Lambda(argument).Compile();
                var specifiedValue   = compiledArgument.DynamicInvoke();
                if (recordedMatches == MatchIt.LastMatch.Count)
                {
                    // Nothing has been added in MatchIt by It.IsAny or It.Is : It was not a predicate, but a real value : handle accordingly.
                    MatchIt.LastMatch.Add(o => o.Equals(specifiedValue));
                }
            }
            MatchIt.RecordMatches = false;

            //IEnumerable<Func<object, bool>> evaluatedArgs = arguments.ForEach()
            //    arg =>
            //        {
            //            var c = Expression.Lambda(arg).Compile();
            //            var specifiedValue = c.DynamicInvoke();
            //            return new Func<object, bool>(o => o.Equals(specifiedValue));
            //            //return specifiedValue;
            //        });

            var oldSetups = this.Setups.ToArray();

            var c = expression.Compile();

            c.DynamicInvoke(new object[] { this });

            var addedSetups = this.Setups.Except(oldSetups);

            var addedSetup = addedSetups.Single();

            // addedSetup.Item3 = returnValue;

            // FIXME : replace this dodgy implementation with a proper class which is not immutable.
            var setupWithReturnValue = new Tuple <string, Func <object, bool>[], object>(addedSetup.Item1, addedSetup.Item2, returnValue);

            Setups.Remove(addedSetup);
            Setups.Add(setupWithReturnValue);

            //var evargs = evaluatedArgs.ToArray();

            // FIXME : use IEnumerable instead of arrays if arrays are not needed.
            //var configEntry = new Tuple<string, Func<object, bool>[], object>(methodName,/* evaluatedArgs.ToArray()*/ evargs, returnValue);
            //this.Setups.Add(configEntry);
            MatchIt.LastMatch.Clear();
            this.IsApplySetupReturnsInProgess = false;
        }