Skip to content

Commit

Permalink
Merge pull request #36 from Amino-NET-Group/refactor/rework-objects
Browse files Browse the repository at this point in the history
Refactor/rework objects
  • Loading branch information
FabioGaming authored May 27, 2024
2 parents 67d9f22 + c08c580 commit 1e8f532
Show file tree
Hide file tree
Showing 87 changed files with 1,589 additions and 5,037 deletions.
682 changes: 266 additions & 416 deletions Amino.NET/Client.cs

Large diffs are not rendered by default.

98 changes: 68 additions & 30 deletions Amino.NET/Events/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Amino.Objects;


namespace Amino.Events
{
Expand All @@ -19,98 +16,139 @@ public class EventHandler
/// <param name="webSocketMessage"></param>
/// <param name="client"></param>
/// <returns></returns>
public Task ReceiveEvent(JObject webSocketMessage, Client client)
public Task ReceiveEvent(string webSocketMessage, Client client)
{
Client.Events eventCall = new Client.Events();
eventCall.callWebSocketMessageEvent(client, webSocketMessage);
try
{
dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(webSocketMessage.ToString());
if(jsonObj["o"]["chatMessage"]["mediaType"] != null)
JsonElement root = JsonDocument.Parse(webSocketMessage.ToString()).RootElement;
if(root.GetProperty("o").GetProperty("chatMessage").GetProperty("mediaType").ValueKind != JsonValueKind.Null)
{
switch((int)jsonObj["o"]["chatMessage"]["mediaType"])
SocketBase _socketBase = JsonSerializer.Deserialize<SocketBase>(root.GetProperty("o").GetRawText());
string element = root.GetProperty("o").GetProperty("chatMessage").GetRawText();
switch (root.GetProperty("o").GetProperty("chatMessage").GetProperty("mediaType").GetInt32())
{
case 0: //TextMessage / MessageDeleted / ChatMember Left, ChatMember Joined / ChatBackground changed / ChatTitle changed / ChatContent chaaged / ChatAnnouncementPin / ChatAnnouncementUnpin / ChatViewOnlyOn / ChatViewOnlyOff / ChatTipEnabled / ChatTipDisabled / MessageForceRemoved / ChatTip
switch((int)jsonObj["o"]["chatMessage"]["type"])
switch(root.GetProperty("o").GetProperty("chatMessage").GetProperty("type").GetInt32())
{
case 0: //Textmessage recevied
Amino.Objects.Message _message = new Amino.Objects.Message(webSocketMessage);
Objects.Message _message = JsonSerializer.Deserialize<Message>(element);
_message.Json = webSocketMessage;
_message.SocketBase = _socketBase;

eventCall.callMessageEvent(client, this, _message);
break;
case 100: // Textmessage deleted
Amino.Objects.DeletedMessage _deletedMessage = new Objects.DeletedMessage(webSocketMessage);
Amino.Objects.DeletedMessage _deletedMessage = JsonSerializer.Deserialize<DeletedMessage>(element);
_deletedMessage.SocketBase = _socketBase;
_deletedMessage.Json = webSocketMessage;
eventCall.callMessageDeletedEvent(client, _deletedMessage);
break;
case 101: // ChatMember Joined
Amino.Objects.JoinedChatMember _joinedMember = new Objects.JoinedChatMember(webSocketMessage);
Amino.Objects.JoinedChatMember _joinedMember = JsonSerializer.Deserialize<JoinedChatMember>(element);
_joinedMember.Json = webSocketMessage;
_joinedMember.SocketBase = _socketBase;
eventCall.callChatMemberJoinEvent(client, _joinedMember);
break;
case 102: // ChatMember Left
Amino.Objects.LeftChatMember _leftMember = new Objects.LeftChatMember(webSocketMessage);
Amino.Objects.LeftChatMember _leftMember = JsonSerializer.Deserialize<LeftChatMember>(element);
_leftMember.Json = webSocketMessage;
_leftMember.SocketBase = _socketBase;
eventCall.callChatMemberLeaveEvent(client, _leftMember);
break;
case 104: // ChatBackground changed
Amino.Objects.ChatEvent _chatBackgroundChanged = new Objects.ChatEvent(webSocketMessage);
Amino.Objects.ChatEvent _chatBackgroundChanged = JsonSerializer.Deserialize<ChatEvent>(element);
_chatBackgroundChanged.SocketBase = _socketBase;
_chatBackgroundChanged.Json = webSocketMessage;
eventCall.callChatBackgroundChangedEvent(client, _chatBackgroundChanged);
break;
case 105: // ChatTitle changed
Amino.Objects.ChatEvent _chatTitleChanged = new Objects.ChatEvent(webSocketMessage);
Amino.Objects.ChatEvent _chatTitleChanged = JsonSerializer.Deserialize<ChatEvent>(element);
_chatTitleChanged.SocketBase = _socketBase;
_chatTitleChanged.Json = webSocketMessage;
eventCall.callChatTitleChangedEvent(client, _chatTitleChanged);
break;
case 113: // ChatContent Changed
Amino.Objects.ChatEvent _chatContentChanged = new Objects.ChatEvent(webSocketMessage);
Amino.Objects.ChatEvent _chatContentChanged = JsonSerializer.Deserialize<ChatEvent>(element);
_chatContentChanged.Json = webSocketMessage;
_chatContentChanged.SocketBase = _socketBase;
eventCall.callChatContentChangedEvent(client, _chatContentChanged);
break;
case 119: // MessageForceRemovedByAdmin
Amino.Objects.SpecialChatEvent _messageForceRemovedByAdmin = new Objects.SpecialChatEvent(webSocketMessage);
Amino.Objects.SpecialChatEvent _messageForceRemovedByAdmin = JsonSerializer.Deserialize<SpecialChatEvent>(element);
_messageForceRemovedByAdmin.Json = webSocketMessage;
_messageForceRemovedByAdmin.SocketBase = _socketBase;
eventCall.callMessageForceRemovedByAdminEvent(client, _messageForceRemovedByAdmin);
break;
case 120: // ChatTip
Amino.Objects.ChatTip _chatTip = new Objects.ChatTip(webSocketMessage);
Amino.Objects.ChatTip _chatTip = JsonSerializer.Deserialize<ChatTip>(element);
_chatTip.Json = webSocketMessage;
_chatTip.SocketBase = _socketBase;
eventCall.callChatTipEvent(client, _chatTip);
break;
case 121: // ChatAnnouncementPin
Amino.Objects.ChatAnnouncement _chatAnnouncementPinEvent = new Objects.ChatAnnouncement(webSocketMessage);
Amino.Objects.ChatAnnouncement _chatAnnouncementPinEvent = JsonSerializer.Deserialize<ChatAnnouncement>(element);
_chatAnnouncementPinEvent.Json = webSocketMessage;
_chatAnnouncementPinEvent.SocketBase = _socketBase;
eventCall.callChatPinAnnouncementEvent(client, _chatAnnouncementPinEvent);
break;
case 125: // ChatViewModeOn
Amino.Objects.ViewMode _viewModeOn = new Objects.ViewMode(webSocketMessage);
Amino.Objects.ViewMode _viewModeOn = JsonSerializer.Deserialize<ViewMode>(element);
_viewModeOn.Json = webSocketMessage;
_viewModeOn.SocketBase = _socketBase;
eventCall.callChatViewModeOnEvent(client, _viewModeOn);
break;
case 126: // ChatViewModeOff
Amino.Objects.ViewMode _viewModeOff = new Objects.ViewMode(webSocketMessage);
Amino.Objects.ViewMode _viewModeOff = JsonSerializer.Deserialize<ViewMode>(element);
_viewModeOff.Json = webSocketMessage;
_viewModeOff.SocketBase = _socketBase;
eventCall.callChatViewModeOffEvent(client, _viewModeOff);
break;
case 127: // ChatAnnouncementUnPin
Amino.Objects.ChatEvent _chatAnnouncementUnPin = new Objects.ChatEvent(webSocketMessage);
Amino.Objects.ChatEvent _chatAnnouncementUnPin = JsonSerializer.Deserialize<ChatEvent>(element);
_chatAnnouncementUnPin.Json = webSocketMessage;
_chatAnnouncementUnPin.SocketBase = _socketBase;
eventCall.callChatUnpinAnnouncementEvent(client, _chatAnnouncementUnPin);
break;
case 128: // ChatTipEnabled
Amino.Objects.ChatTipToggle _chatTipEnabled = new Objects.ChatTipToggle(webSocketMessage);
Amino.Objects.ChatTipToggle _chatTipEnabled = JsonSerializer.Deserialize<ChatTipToggle>(element);
_chatTipEnabled.Json = webSocketMessage;
_chatTipEnabled.SocketBase = _socketBase;
eventCall.callChatTipEnabledEvent(client, _chatTipEnabled);
break;
case 129: // ChatTipDisabled
Amino.Objects.ChatTipToggle _chatTipDisabled = new Objects.ChatTipToggle(webSocketMessage);
Amino.Objects.ChatTipToggle _chatTipDisabled = JsonSerializer.Deserialize<ChatTipToggle>(element);
_chatTipDisabled.Json = webSocketMessage;
_chatTipDisabled.SocketBase = _socketBase;
eventCall.callChatTipDisabledEvent(client, _chatTipDisabled);
break;

}

break;
case 100: //ImageMessage
Amino.Objects.ImageMessage _imageMessage = new Amino.Objects.ImageMessage(webSocketMessage);
Amino.Objects.ImageMessage _imageMessage = JsonSerializer.Deserialize<ImageMessage>(element);
_imageMessage.Json = webSocketMessage;
_imageMessage.SocketBase = _socketBase;
eventCall.callImageMessageEvent(client, _imageMessage);
break;
case 103: //YouTubeMessage
Amino.Objects.YouTubeMessage _youtubeMessage = new Objects.YouTubeMessage(webSocketMessage);
Amino.Objects.YouTubeMessage _youtubeMessage = JsonSerializer.Deserialize<YouTubeMessage>(element);
_youtubeMessage.Json = webSocketMessage;
_youtubeMessage.SocketBase = _socketBase;
eventCall.callYouTubeMessageEvent(client, _youtubeMessage);
break;
case 110: //VoiceMessage
Amino.Objects.VoiceMessage _voiceMessage = new Objects.VoiceMessage(webSocketMessage);
Amino.Objects.VoiceMessage _voiceMessage = JsonSerializer.Deserialize<VoiceMessage>(element);
_voiceMessage.Json = webSocketMessage;
_voiceMessage.SocketBase = _socketBase;
eventCall.callVoiceMessageEvent(client, _voiceMessage);
break;
case 113: //StickerMessage
Amino.Objects.StickerMessage _stickerMessage = new Objects.StickerMessage(webSocketMessage);
Amino.Objects.StickerMessage _stickerMessage = JsonSerializer.Deserialize<StickerMessage>(element);
_stickerMessage.Json = webSocketMessage;
_stickerMessage.SocketBase = _socketBase;
eventCall.callStickerMessageEvent(client, _stickerMessage);
break;
}
Expand Down
9 changes: 9 additions & 0 deletions Amino.NET/Objects/AdditionalItemBenefits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace Amino.Objects
{
public class AdditionalItemBenefits
{
[JsonPropertyName("firstMonthFreeAminoPlusMembership")] public bool FirstMonthFreeAminoPlus { get; set; }
}
}
Loading

0 comments on commit 1e8f532

Please sign in to comment.