private async Task CheckNewThread(SocketMessage arg) { if (arg.Author.IsBot) { return; } if (arg.Channel.GetType() == typeof(SocketDMChannel)) { if (BlockedUsers.Any(x => x == arg.Author.Id)) { return; } if (CurrentTickets.Any(x => x.DMChannelID == arg.Channel.Id)) { var ticket = CurrentTickets.Find(x => x.DMChannelID == arg.Channel.Id); ticket.DMTyping.Typing = false; if (ticket.DMTyping.TypingObject != null) { ticket.DMTyping.TypingObject.Dispose(); } string msg = $"**[Ticketer] {arg.Author}** - {arg.Content}"; var tkchan = client.GetGuild(Global.SwissGuildId).GetTextChannel(ticket.TicketChannel); await tkchan.SendMessageAsync(msg); if (arg.Attachments.Count > 0) { foreach (var attc in arg.Attachments) { var bt = new WebClient().DownloadData(new Uri(attc.ProxyUrl)); File.WriteAllBytes(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", bt); await tkchan.SendFileAsync(Environment.CurrentDirectory + $"{Path.DirectorySeparatorChar}{attc.Filename}", $"**[Ticketer]**"); } } } else if (!Setups.ContainsKey(arg.Author.Id)) { var msg = await arg.Channel.SendMessageAsync("Hello " + arg.Author.Mention + ", if you want to open a support ticket please click the checkmark, otherwise to delete this message click the X"); await msg.AddReactionsAsync(new IEmote[] { new Emoji("✅"), new Emoji("❌") }); Setups.Add(arg.Channel.Id, new KeyValuePair <ulong, string>(msg.Id, arg.Content)); } } else if (CurrentTickets.Any(x => x.TicketChannel == arg.Channel.Id)) { //check snippets await SnippetHandler(arg); } }
public void RegisterSetup <TData>(Func <ISetupContext, TData> action) where TData : class { var dataType = typeof(TData); if (_dataTypes.Contains(dataType)) { var message = $"More than one setup action have been registered that accepts data of type '{dataType.FullName}'."; throw new CakeException(message); } _dataTypes.Add(dataType); Setups.Add(context => { _data.Add(action(context)); }); }
private async Task CheckNewThread(SocketMessage arg) { if (arg.Author.IsBot) { return; } if (arg.Channel.GetType() == typeof(SocketDMChannel)) { if (BlockedUsers.Any(x => x == arg.Author.Id)) { return; } if (CurrentTickets.Any(x => x.DMChannelID == arg.Channel.Id)) { var ticket = CurrentTickets.Find(x => x.DMChannelID == arg.Channel.Id); ticket.DmTyping.Typing = false; if (ticket.DmTyping.TypingObject != null) { ticket.DmTyping.TypingObject.Dispose(); } string msg = $"**[Ticketer] {arg.Author}** - {arg.Content}"; if (arg.Attachments.Count > 0) { foreach (var attc in arg.Attachments) { msg += $"\n**Attachment** - {attc.Url}"; } } await client.GetGuild(Global.SwissGuildId).GetTextChannel(ticket.TicketChannel).SendMessageAsync(msg); } else if (!Setups.ContainsKey(arg.Author.Id)) { var msg = await arg.Channel.SendMessageAsync("Hello " + arg.Author.Mention + ", if you want to open a support ticket please click the checkmark, otherwise to delete this message click the X"); await msg.AddReactionsAsync(new IEmote[] { new Emoji("✅"), new Emoji("❌") }); Setups.Add(arg.Channel.Id, new KeyValuePair <ulong, string>(msg.Id, arg.Content)); } } else if (CurrentTickets.Any(x => x.TicketChannel == arg.Channel.Id)) { //check snippets await SnippetHandler(arg); } }
public void AddSetup(CallChain chain) { Setups.Add(chain); }
public void RegisterSetup(Action <ISetupContext> action) { Setups.Add(action); }
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; }