Example #1
0
 public async Task OnUpdateRecieve(IUpdates message)
 {
     if (RecieveUpdates != null)
     {
         await RecieveUpdates.Invoke(message).ConfigureAwait(false);
     }
 }
Example #2
0
        protected override async Task HandleUpdate(IUpdates update, IClientApi clientApi, int index)
        {
            switch (update)
            {
            case TUpdateShortMessage updateShortMessage:
                if (updateShortMessage.Message.StartsWith("Test_"))
                {
                    var stat = _statistics.First(s => s.FromUserId == updateShortMessage.UserId && s.ToUserId == clientApi.AuthService.CurrentUserId.Value);
                    stat.RecieveCount++;

                    await Task.Delay(1500).ConfigureAwait(false);
                    await SendMessage(clientApi, index).ConfigureAwait(false);
                }

                break;

            case TUpdates updates:
                break;

            case TUpdatesCombined updatesCombined:
                break;

            case TUpdateShortChatMessage updateShortChatMessage:
                break;

            case TUpdateShortSentMessage updateShortSentMessage:
                break;

            case TUpdatesTooLong updatesTooLong:
                break;
            }
        }
Example #3
0
        protected override async Task HandleUpdate(IUpdates update, IClientApi clientApi, int index)
        {
            switch (update)
            {
            case TUpdateShortMessage updateShortMessage:
                if (updateShortMessage.Message.StartsWith("Test_"))
                {
                    var stat = _statistics.First(s => s.FromUserId == updateShortMessage.UserId && s.ToUserId == clientApi.AuthService.CurrentUserId.Value);
                    stat.ReceiveCount++;

                    await Task.Delay(1500).ConfigureAwait(false);
                    await SendMessage(clientApi, index).ConfigureAwait(false);
                }
                break;

            case TUpdates _:
                break;

            case TUpdatesCombined _:
                break;

            case TUpdateShortChatMessage _:
                break;

            case TUpdateShortSentMessage _:
                break;

            case TUpdatesTooLong _:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(update));
            }
        }
Example #4
0
        private void UpdatesService_AutoReceiveUpdates(IUpdates update)
        {
            switch (update)
            {
            case TUpdates updates:
                var channels = updates.Chats.OfType <TChannel>().ToList();

                break;

            case TUpdatesCombined updatesCombined:
                break;

            case TUpdateShort updateShort:
                break;

            case TUpdateShortChatMessage updateShortChatMessage:
                break;

            case TUpdateShortMessage updateShortMessage:
                break;

            case TUpdateShortSentMessage updateShortSentMessage:
                break;

            case TUpdatesTooLong updatesTooLong:

                break;

            default:

                break;
            }
        }
 public void HandleAutoUpdates(IUpdates update)
 {
     try
     {
         AutoReceiveUpdates?.Invoke(update);
     }
     catch (Exception e)
     {
         Log.Error("Error processing updates", e);
     }
 }
        private async Task CheckUpdate(IUpdates update)
        {
            if (!(update is TUpdateShortMessage))
            {
                return;
            }

            var message = update as TUpdateShortMessage;

            if (IsMessageRight(message.Message))
            {
                await ForwardMessage(message);
            }
        }
Example #7
0
        public async Task CheckUpdates(IUpdates x)
        {
            if (x is TUpdateShortMessage)
            {
                var TMessage = x as TUpdateShortMessage;

                //await client.MessagesService.ForwardMessageAsync(new TInputPeerUser() { UserId = _user.Id, AccessHash = _user.AccessHash}, TMessage.Id);
                var messages = new TVector <int>();
                messages.Items.Add(TMessage.Id);

                await client.MessagesService.ForwardMessagesAsync(new TInputPeerUser()
                {
                    UserId = TMessage.UserId
                }, new TInputPeerUser()
                {
                    UserId = _user.Id
                }, messages, true, true);
            }
        }
Example #8
0
        private static Task UpdatesService_RecieveUpdates(IUpdates update)
        {
            //Log.WriteLine($"Update recieved: {update}");
            // handle updates
            switch (update)
            {
            case TUpdates updates:
                var enumerator = updates.Updates.ToList().GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current is TUpdateNewChannelMessage msg)
                        {
                            if (msg.Message is TMessage m)
                            {
                                if (m.ToId is TPeerChannel c)
                                {
                                    var conns = Program.Connections.Where(x => x.TelegramChannelId == c.ChannelId && x.Enabled);
                                    if (!conns.Any())
                                    {
                                        continue;
                                    }
                                    //-1001288603754
                                    //c.ChannelId == 1288603754
                                    if (SentMessages.Contains(m.Id))
                                    {
                                        continue;
                                    }

                                    conns.All(x => { x.Posts++; x.LastPost = DateTime.Now; return(true); });
                                    Program.SaveConnections();
                                    Log.WriteLine("Channel message posted in " + conns.FirstOrDefault().TelegramChannelName);

                                    SentMessages.Add(m.Id);
                                    //get the channel
                                    var chan = updates.Chats.Where(x => x is TChannel).Cast <TChannel>().FirstOrDefault(x => x.Id == c.ChannelId);
                                    //forward the message to discord
                                    //445308465850613763
                                    //foreach (var conn in conns)
                                    Discord.SendMessage(m, conns.ToList(), chan);
                                }
                            }
                        }
                    }
                }
                catch (AggregateException e)
                {
                    Log.WriteLine($"Error: {e.InnerException.Message}\r\n{e.InnerException.StackTrace}");
                }
                catch (Exception e)
                {
                    Log.WriteLine($"Error: {e.Message}\r\n{e.StackTrace}");
                }
                break;

            case TUpdatesCombined updatesCombined:
                break;

            case TUpdateShort updateShort:
                break;

            case TUpdateShortChatMessage updateShortChatMessage:
                break;

            case TUpdateShortMessage updateShortMessage:
                break;

            case TUpdateShortSentMessage updateShortSentMessage:
                break;

            case TUpdatesTooLong updatesTooLong:
                break;
            }
            return(Task.CompletedTask);
        }
Example #9
0
 public void OnUpdateRecieve(IUpdates message)
 {
     RecieveUpdates?.Invoke(message);
 }
Example #10
0
 void SendToResponseDispatcher(IUpdates iUpdate,TelegramClient client)
 {
         var mtProtoClientConnection = client.Connection as MTProtoClientConnection;
         if (mtProtoClientConnection != null)
         {
             var responseDispatcher = mtProtoClientConnection.ResponseDispatcher as ResponseDispatcher;
             if (responseDispatcher != null)
             {
                 SharpMTProto.Schema.IMessage tempMessage = new SharpMTProto.Schema.Message(0,0,iUpdate);
                 responseDispatcher.DispatchAsync(tempMessage).Wait();
             }
         }
 }
Example #11
0
 private string GetMessageId(IUpdates iUpdates)
 {
     DebugPrint(">>>> Get message id updates " + ObjectDumper.Dump(iUpdates));
     var updates = iUpdates as Updates;
     if (updates != null)
     {
         foreach (var update in updates.UpdatesProperty)
         {
             var updateNewMessage = update as UpdateNewMessage;
             var updateNewChannelMessage = update as UpdateNewChannelMessage;
             var updateMessageId = update as UpdateMessageID;
             if (updateNewMessage != null)
             {
                 var message = updateNewMessage.Message as Message;
                 return message?.Id.ToString(CultureInfo.InvariantCulture);
             }
             if (updateNewChannelMessage != null)
             {
                 var message = updateNewChannelMessage.Message as Message;
                 return message?.Id.ToString(CultureInfo.InvariantCulture);
             }
         }
     }
     return null;
 }
 protected abstract Task HandleUpdate(IUpdates update, IClientApi clientApi, int index);