/// <inheritdoc/> public override async Task RespondAsync( string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) { if (!IsValidToken) { throw new InvalidOperationException("Interaction token is no longer valid"); } if (!InteractionHelper.CanSendResponse(this)) { throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); } embeds ??= Array.Empty <Embed>(); if (embed != null) { embeds = new[] { embed } }
/// <summary> /// Get from database all conversation related of the user /// </summary> private void BindData() { var listMessagesFrom = MessageComponent.GetMessagesFrom(UserInfo.UserID).ToList(); var usersTo = (from s in listMessagesFrom select s.ToUserId).Distinct(); var listMessagesTo = MessageComponent.GetMessagesTo(UserInfo.UserID).ToList(); var usersFrom = (from s in listMessagesTo select s.FromUserId).Distinct(); var ListUsersConversations = usersFrom.Concat(usersTo).Distinct(); List <UserProperty> list = new List <UserProperty>(); foreach (int id in ListUsersConversations) { UserPropertyComponent userProperty = new UserPropertyComponent(id); list.Add(userProperty.UserProperty); } if (list.Count <= 0) { noMessageContainer.Visible = true; } else { noMessageContainer.Visible = false; } rpConversations.DataSource = list; rpConversations.DataBind(); }
public void InitializeGameServer() { var daytimeComponent = new DaytimeComponent(this); Components.Add(daytimeComponent); var messageComponent = new MessageComponent(this); Components.Add(messageComponent); var pingComponent = new PingComponent(this); Components.Add(pingComponent); var MilethSpawner = new MonolithComponent(this); Components.Add(MilethSpawner); var objectComponent = new ObjectComponent(this); Components.Add(objectComponent); var mundaneComponent = new MundaneComponent(this); Components.Add(mundaneComponent); Console.WriteLine(Components.Count + " Server Components loaded."); }
private void ButtonNewText_Click(object sender, RoutedEventArgs e) { MessageComponent message = new MessageComponent(); message.ButtonCancel.Click += (sender1, e1) => { StackSubItems.Children.Remove(message); }; message.KeyUp += (sender2, e2) => { switch (e2.Key) { case Key.Return: AddSubItem(message.Text); StackSubItems.Children.Remove(message); break; case Key.Escape: StackSubItems.Children.Remove(message); break; } }; StackSubItems.Children.Add(message); }
public void OnNewMessageEvent(MessageComponent.Messages.Message message) { //If message is a response, handle it //Notify the delegate that task is complete throw new NotImplementedException(); }
/// <summary> /// Get from database all messages related of the user (current user and other users who have conversed with the current user) /// </summary> /// <param name="userId"></param> /// <returns></returns> private List <Message> GetListMessagesForUser(int userId) { var list1 = MessageComponent.GetMessages(UserInfo.UserID, userId).ToList(); var list2 = MessageComponent.GetMessages(userId, UserInfo.UserID).ToList(); var listFinallyMessages = list1.Concat(list2).OrderBy(p => p.DateCreated).ToList(); return(listFinallyMessages); }
/// <summary> /// Send message to the other user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSendMessage_Click(object sender, EventArgs e) { try { Button button = (Button)sender; var txtMessage = (TextBox)button.Parent.FindControl("txtMessage"); if (!string.IsNullOrEmpty(txtMessage.Text)) { var ToUserId = button.CommandArgument; Repeater rpMessages = (Repeater)button.Parent.FindControl("rpMessages"); MessageComponent messageComponent = new MessageComponent(); // verify that the message doesn't have script and styles messageComponent.Message.Message1 = ValidateSecurity.ValidateString(txtMessage.Text, false); messageComponent.Message.DateCreated = DateTime.Now; messageComponent.Message.FromUserId = UserInfo.UserID; messageComponent.Message.ToUserId = Convert.ToInt32(ValidateSecurity.ValidateString(ToUserId, false)); //Save message in the database if (messageComponent.Save() > -1) { var list = FillMessages(GetListMessagesForUser(Convert.ToInt32(ValidateSecurity.ValidateString(ToUserId, false)))); rpMessages.DataSource = list; rpMessages.DataBind(); txtMessage.Text = string.Empty; UserPropertyComponent userPropertyComponent = new UserPropertyComponent(Convert.ToInt32(ToUserId)); UserInfo userTo = UserController.GetUserById(PortalId, userPropertyComponent.UserProperty.UserId); UserPropertyComponent userProperty = new UserPropertyComponent(UserInfo.UserID); //Send message try { CultureInfo language = new CultureInfo(getUserLanguage(userPropertyComponent.UserProperty.Language.GetValueOrDefault(1))); DotNetNuke.Services.Mail.Mail.SendEmail("*****@*****.**", userTo.Email, string.Format( Localization.GetString("MessageTitle", LocalResourceFile, language.Name), userProperty.UserProperty.FirstName + " " + userProperty.UserProperty.LastName ), Localization.GetString("MessageBody", LocalResourceFile, language.Name).Replace("{MESSAGE:Body}", messageComponent.Message.Message1).Replace("{MESSAGE:ViewLink}", NexsoHelper.GetCulturedUrlByTabName("MyMessages")) ); } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } } } } catch (Exception exc) { Exceptions. ProcessModuleLoadException( this, exc); } }
public List <MessageModel> GetListFrom(int rows = 10, int page = 0) { try { var portal = PortalController.GetCurrentPortalSettings(); var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); if (currentUser.IsInRole("Registered Users")) { var result = MessageComponent.GetMessagesFrom(currentUser.UserID).OrderByDescending(p => p.DateCreated); var totalCount = result.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / rows); var prevLink = page > 0 ? string.Format("/messages/GetListFrom?rows={0}&page={1}", rows, page - 1) : ""; var nextLink = page < totalPages - 1 ? string.Format("/messages/GetListFrom?rows={0}&page={1}", rows, page + 1) : ""; List <MessageModel> MessageModel = new List <MessageModel>(); foreach (var resultTmp in result.Skip(rows * page).Take(rows).ToList()) { MessageModel.Add(new MessageModel() { MessageId = resultTmp.MessageId, Message = resultTmp.Message1, FromUserId = Convert.ToInt32(resultTmp.FromUserId), ToUserId = Convert.ToInt32(resultTmp.ToUserId), CreatedDate = Convert.ToDateTime(resultTmp.DateCreated), DateRead = Convert.ToDateTime(resultTmp.DateRead) }); } var paginationHeader = new { TotalCount = totalCount, TotalPages = totalPages, PrevPageLink = prevLink, NextPageLink = nextLink }; System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader)); return(MessageModel); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } catch (HttpResponseException e) { throw e; } catch (Exception ee) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ee); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
public static async Task <ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, IEnumerable <Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, MessageComponent components, MessageFlags flags = MessageFlags.None) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) return(await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components, flags).ConfigureAwait(false)); }
public ServiceResult <bool> DeleteMessage(DeleteMessageIM model) { bool result = new MessageComponent().DeleteMessage(model.Id, this.GetMerchantAccountId()); return(new ServiceResult <bool> { Data = result }); }
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> public static async Task <RestUserMessage> SendMessageAsync(IMessageChannel channel, BaseDiscordClient client, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, Embed[] embeds, MessageFlags flags) { embeds ??= Array.Empty <Embed>(); if (embed != null) { embeds = new[] { embed } }
internal static MessageComponent GetAndRemoveByMessageId(int messageId) { if (PairMessageComponent.ContainsKey(messageId)) { MessageComponent messageComponent = PairMessageComponent[messageId]; PairMessageComponent.Remove(messageId); return(messageComponent); } return(null); }
public void WeCanSendAMessageToAComponentOnAGameObject() { GameObject go = new GameObject(); MessageComponent comp = new MessageComponent(); go.AddComponent(comp); go.SendMessage("MessageMethod"); Assert.That(comp.messageCalled, Is.True); }
public void WeCanSendAParameterWithTheMessage() { GameObject go = new GameObject(); MessageComponent comp = new MessageComponent(); go.AddComponent(comp); go.SendMessage("SetValue", 42); Assert.That(comp.value, Is.EqualTo(42)); }
public void WeCanSendAMessageUpwards() { TestHierarchy h = new TestHierarchy(); MessageComponent comp = new MessageComponent(); h.root.AddComponent(comp); h.childOfChild.SendMessageUpwards("MessageMethod"); Assert.That(comp.messageCalled, Is.True); }
public HttpResponseMessage SendMessage(string message, int userIdTo) { try { var portal = PortalController.GetCurrentPortalSettings(); var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo(); UserInfo userTo = DotNetNuke.Entities.Users.UserController.GetUserById(portal.PortalId, userIdTo); if (currentUser.IsInRole("Registered Users") && userTo != null) { var fromUser = new UserPropertyComponent(currentUser.UserID); var toUser = new UserPropertyComponent(userIdTo); if (!string.IsNullOrEmpty(ValidateSecurity.ValidateString(message, false)) && toUser.UserProperty.UserId > 0 && currentUser.UserID > 0) { MessageComponent messageComponent = new MessageComponent(Guid.Empty); messageComponent.Message.Message1 = message; messageComponent.Message.ToUserId = userIdTo; messageComponent.Message.FromUserId = currentUser.UserID; messageComponent.Message.DateCreated = DateTime.Now; if (messageComponent.Save() > 0) { // Notification if (currentUser.UserID != Convert.ToInt32(userTo.UserID)) { if (Helper.HelperMethods.SetNotification("MESSAGE", "MESSAGE", messageComponent.Message.MessageId, toUser.UserProperty.UserId, currentUser.UserID, "") > 0) { CultureInfo culture = new CultureInfo(HelperMethods.GetUserLanguage(toUser.UserProperty.Language.GetValueOrDefault(1))); Helper.HelperMethods.SendEmailToUser("MessageTitleMessage", "MessageBodyMessage", userTo, culture, "", messageComponent.Message.Message1).ConfigureAwait(false); return(Request.CreateResponse(HttpStatusCode.OK, "Successful Operation")); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } catch (HttpResponseException e) { throw e; } catch (Exception ee) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ee); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } }
public void AddElement(Vector2 position, Vector2 size, string textureKey, TextureType textureType = TextureType.Default) { var element = new MessageComponent(position, size, textureKey, textureType) { Parent = this, ComponentType = "TextureKey" }; this.components.Add(this.elements, element); this.elements++; }
public void WeCanCallANonPublicMethodWithTheMessage() { GameObject go = new GameObject(); MessageComponent comp = new MessageComponent(); go.AddComponent(comp); go.SendMessage("NonPublicMessage"); Assert.That(comp.messageCalled, Is.True); }
private void ButtonText_Click(object sender, RoutedEventArgs e) { MessageComponent component = new MessageComponent(); component.KeyUp += (sender2, e2) => Component_KeyUp(sender2, e2, component); component.ButtonCancel.Click += (sender1, e) => { StackChat.Children.Remove(component); }; StackChat.Children.Add(component); }
public void WeCanBroadcastAMessage() { TestHierarchy h = new TestHierarchy(); MessageComponent comp = new MessageComponent(); MessageComponent comp1 = new MessageComponent(); h.child.AddComponent(comp); h.childOfChild.AddComponent(comp1); h.root.BroadcastMessage("MessageMethod"); Assert.That(comp.messageCalled, Is.True); Assert.That(comp1.messageCalled, Is.True); }
string CodeSelector(MessageComponent comp) { return(comp switch { At it => it.TargetId.ToString(), AtAll it => string.Empty, Face it => it.FaceId.ToString(), ImageBase it => $"{it.ImageId},{it.Url}", Poke it => it.Name.ToString(), Quote it => it.MessageId.ToString(), Source it => it.MessageId.ToString(), _ => throw new NotImplementedException() });
private void InitComponentCache() { Components = new Dictionary <Type, GameServerComponent>(); Components[typeof(MonolithComponent)] = new MonolithComponent(this); Components[typeof(DaytimeComponent)] = new DaytimeComponent(this); Components[typeof(MundaneComponent)] = new MundaneComponent(this); Components[typeof(MessageComponent)] = new MessageComponent(this); Components[typeof(ObjectComponent)] = new ObjectComponent(this); Components[typeof(PingComponent)] = new PingComponent(this); Components[typeof(ServerCacheComponent)] = new ServerCacheComponent(this); }
private void Component_KeyUp(object sender, KeyEventArgs e, MessageComponent component) { switch (e.Key) { case Key.Return: AddMessage(component.Text); StackChat.Children.Remove(component); break; case Key.Escape: StackChat.Children.Remove(component); break; } }
ButtonComponent getButton(MessageComponent component, string id) { foreach (var row in component.Components) { foreach (var btn in row.Components) { if (btn.CustomId == id) { return(btn); } } } return(null); }
public void NoErrorIsLoggedIfWeDontRequireAReceiver() { GameObject go = new GameObject(); MessageComponent comp = new MessageComponent(); go.AddComponent(comp); MemoryStream ms = new MemoryStream(); System.Diagnostics.TextWriterTraceListener listener = new System.Diagnostics.TextWriterTraceListener(ms); System.Diagnostics.Debug.Listeners.Clear(); System.Diagnostics.Debug.Listeners.Add(listener); go.SendMessage("NonExisting", 42, SendMessageOptions.DontRequireReceiver); listener.Flush(); Assert.That(ms.Position, Is.EqualTo(0)); }
protected override Task RespondAsync( string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null ) { return(IsDeferred ? FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, options, components, embed) : !Context.Interaction.HasResponded ? base.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, options, components, embed) : ReplyAsync(text, isTTS, embed, options, allowedMentions, components: components)); }
public ServiceResult <bool> OnekeyReadMessage() { bool result = false; try { new ArticleComponent().OnekeyRead(this.GetMerchantAccountId()); result = new MessageComponent().ReadMessage(this.GetMerchantAccountId()); } catch (Exception ex) { _log.Error(string.Format("OnekeyReadMessage:{0}", ex)); } return(new ServiceResult <bool> { Data = result }); }
/// <summary> /// Sends a followup message for this interaction. /// </summary> /// <param name="text">The text of the message to be sent.</param> /// <param name="embeds">A array of embeds to send with this response. Max 10.</param> /// <param name="isTTS"><see langword="true"/> if the message should be read out by a text-to-speech reader, otherwise <see langword="false"/>.</param> /// <param name="ephemeral"><see langword="true"/> if the response should be hidden to everyone besides the invoker of the command, otherwise <see langword="false"/>.</param> /// <param name="allowedMentions">The allowed mentions for this response.</param> /// <param name="options">The request options for this response.</param> /// <param name="component">A <see cref="MessageComponent"/> to be sent with this response.</param> /// <param name="embed">A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.</param> /// <returns> /// The sent message. /// </returns> public override async Task <RestFollowupMessage> FollowupAsync( string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent component = null, Embed embed = null, RequestOptions options = null) { if (!IsValidToken) { throw new InvalidOperationException("Interaction token is no longer valid"); } embeds ??= Array.Empty <Embed>(); if (embed != null) { embeds = new[] { embed } }
void IMessageHandler.OnNewMessageEvent(MessageComponent.Messages.Message message) { switch(message.Type) { case MessageType.ImageReceiveRequest: ImageReceiveRequestMessage requestMessage = message as ImageReceiveRequestMessage; if(requestMessage != null) { RespondImageReceiveRequestTask task = new RespondImageReceiveRequestTask(_messageManager, requestMessage.ImageSizeInBytes); task.Exectute(); } else { Log.error("MediaConsumerComponent - failed to cast ImageMessage"); } break; default: break; } }
public void Handle(MessageContext context) { bool flag = false; foreach (Channel channel in invaders.Keys) { if (channel.Match(context.User.Identity, context.Type == MessageEventType.Group ? (long?)context.Group.Identity : null)) { if (invaders[channel].Count > 0) { QueueEntry action = invaders[channel].Dequeue(); if (DateTime.Now < action.CreatedAt + action.Timeout) { action.Action(context); } else { MessageComponent[] chain = new MessageComponent[] { new Plain("❌你没能在时限内提供完整参数, 该操作已取消.") }; context.ReplyAsync(new MessageChain(chain)).Wait(); } flag = true; } else { invaders.Remove(channel); } } } if (!flag) { IEnumerable <ActionEntry> ava = GetEntries().Where(x => x.Type == context.Type); foreach (ActionEntry e in ava) { HandleOne(e, context); } } }
/// <inheritdoc /> async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags) => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds, flags).ConfigureAwait(false);
/// <inheritdoc /> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception> public virtual Task <RestUserMessage> SendFilesAsync(IEnumerable <FileAttachment> attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds, flags);