示例#1
0
        /// <summary>
        /// Merge two (non-conflicting) ItemIds into one.
        /// </summary>
        /// <returns>The merged ChatItemID.</returns>
        public static ChatItemId Merge(ChatItemId c1, ChatItemId c2)
        {
            if (c1 == null || c2 == null)
            {
                return(null);
            }
            if (c1.Conflicts(c2))
            {
                return(null);
            }

            ChatItemId id = new ChatItemId();

            foreach (KeyValuePair <string, ulong> p in c1.Ids)
            {
                id.Ids.Add(p.Key, p.Value);
            }

            foreach (KeyValuePair <string, ulong> p in c2.Ids)
            {
                if (!id.Ids.ContainsKey(p.Key))
                {
                    id.Ids.Add(p.Key, p.Value);
                }
            }

            return(id);
        }
示例#2
0
 public Message(Chat chat, User user, string text, ChatItemId id = null, MessageType type = MessageType.Unknown)
 {
     Chat = chat;
     User = user;
     Text = text;
     Id   = id;
     Type = type;
 }
示例#3
0
        public User FindUserById(ChatItemId id, Client c = null)
        {
            int i = FindUserIndexById(id);

            if (i != -1)
            {
                users[i].SetClient(c);
            }
            return(i == -1 ? null : users[i]);
        }
示例#4
0
文件: Client.cs 项目: MatanRad/Matbot
        public virtual bool SendMessage(ChatItemId id, string message)
        {
            Chat c = GetChatById(id);

            if (c == null)
            {
                c = new Chat(id, ChatType.Unknown);
            }

            return(this.SendMessage(c, message));
        }
示例#5
0
        private int FindUserIndexById(ChatItemId id, Client c = null)
        {
            foreach (KeyValuePair <string, ulong> e in id.Ids)
            {
                int i = FindUserIndexById(e.Key, e.Value);
                if (i != -1)
                {
                    users[i].SetClient(c);
                    return(i);
                }
            }

            return(-1);
        }
示例#6
0
        public override string ToString(Matbot.Client.ChatItemId chatId)
        {
            string s = base.ToString();

            if (IsChatRegistered(chatId) != ChatRegisterStatus.Empty)
            {
                s += "    *R*";
            }
            else
            {
                s += "    R";
            }

            return(s);
        }
示例#7
0
        /// <summary>
        /// Checks if there is a conflict in the ChatIds: a client in which they have different IDs.
        /// </summary>
        public bool Conflicts(ChatItemId other)
        {
            foreach (KeyValuePair <string, ulong> p in Ids)
            {
                if (other.Ids.ContainsKey(p.Key))
                {
                    if (other.Ids[p.Key] != Ids[p.Key])
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#8
0
        public bool Equals(ChatItemId obj)
        {
            ChatItemId other = obj as ChatItemId;

            foreach (KeyValuePair <string, ulong> p in Ids)
            {
                if (!other.Ids.Contains(p))
                {
                    return(false);
                }
            }

            foreach (KeyValuePair <string, ulong> p in other.Ids)
            {
                if (!Ids.Contains(p))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#9
0
        public void Start(Client.ChatItemId chatId, Client.Client client = null)
        {
            this.client = client;
            this.chatId = chatId;

            shell = new Process();
            ProcessStartInfo p = new ProcessStartInfo("cmd");

            p.CreateNoWindow         = true;
            p.UseShellExecute        = false;
            p.RedirectStandardError  = true;
            p.RedirectStandardInput  = true;
            p.RedirectStandardOutput = true;
            shell.StartInfo          = p;
            shell.Start();
            toShell           = shell.StandardInput;
            fromShell         = shell.StandardOutput;
            toShell.AutoFlush = true;
            shellThread       = new Thread(new ThreadStart(getShellInput)); //Start a thread to read output from the shell
            shellThread.Start();

            Running = true;
        }
示例#10
0
文件: Chat.cs 项目: MatanRad/Matbot
 public Chat(ChatItemId id, ChatType type)
 {
     Type = type;
     Id   = id;
 }
示例#11
0
 public bool UserExists(ChatItemId id)
 {
     return(FindUserIndexById(id) != -1);
 }
示例#12
0
文件: User.cs 项目: MatanRad/Matbot
 public User(string clientId, ulong id)
 {
     Id = new ChatItemId(clientId, id);
 }
示例#13
0
文件: Client.cs 项目: MatanRad/Matbot
 public virtual Chat GetChatById(ChatItemId id)
 {
     throw new NotImplementedException("GetChatById functionality not implemented in bot client with id: " + GetClientId());
 }
示例#14
0
文件: Client.cs 项目: MatanRad/Matbot
 public virtual User GetChatMemberByUsername(ChatItemId chatId, string username, bool exactMatch = true)
 {
     throw new NotImplementedException("GetChatMemberByUsername functionality not implemented in bot client with id: " + GetClientId());
 }
示例#15
0
文件: Client.cs 项目: MatanRad/Matbot
 public virtual User GetChatMemberById(ChatItemId chatId, ulong id)
 {
     throw new NotImplementedException("GetChatMember functionality not implemented in bot client with id: " + GetClientId());
 }
示例#16
0
文件: User.cs 项目: MatanRad/Matbot
 public User(Client c, string clientId, ulong id)
 {
     Id     = new ChatItemId(clientId, id);
     Client = c;
 }
示例#17
0
文件: Chat.cs 项目: MatanRad/Matbot
 public Chat(string clientId, ulong id, ChatType type)
 {
     Type = type;
     Id   = new ChatItemId(clientId, id);
 }