async Task <bool> IPermissionConfig.AddSpecialUser(ITextChannel channel, IGuildUser user) { var cu = QuerySpecialUsers().SingleOrDefault(s => s.Channel.ChannelId == channel.Id && s.User.UserId == user.Id); if (cu == null) { var ch = QueryChannel(channel); var sp = QueryUser(user) ?? await AddUserInternal(user).ConfigureAwait(false); cu = new ChannelUser <TChannel, TUser> { Channel = ch, User = sp }; ChannelUsers.Add(cu); await SaveChangesAsync().ConfigureAwait(false); return(true); } return(false); }
/// <summary> /// BnetConnection dispatches a message to us on every Bnet Event. /// </summary> /// <param name="msg">BnetEvent sent to us by BnetConnection</param> public void BnetEventReceived(BnetEvent[] messages) { DispatcherHelper.CheckBeginInvokeOnUI(() => { foreach (var msg in messages) { if (ChatMessages.Count > 120) { var cache = new ObservableCollection <BnetEvent>(); for (int i = 100; i < ChatMessages.Count; i++) { cache.Add(ChatMessages[i]); } ChatMessages = new ObservableCollection <BnetEvent>(cache); } if (msg.EventId != 0x01 || msg.EventId != 0x09 || msg.EventId != 0x21 || msg.EventId != 0x22) { ChatMessages.Add(msg); Messenger.Default.Send <ScrollDownMessage>(new ScrollDownMessage() { Source = this }); } if (msg.EventId == 0x21) { ChannelUsers.Clear(); ChannelList.Clear(); FriendsList.Clear(); ChattingStatus = "disconnected"; Connect(); } if (msg.EventId == 0x22) // EID_CHANNELUSER { // We use a List<> because ChannelList is only requested once per connection .. ChannelList.Add(new BnetUser() { Username = msg.Username }); } if (msg.EventId == 0x07) { ChattingStatus = string.Format("chatting in {0}", msg.Message.ToLower()); ChannelUsers.Clear(); } if (msg.EventId == 0x03) { foreach (var user in ChannelUsers) { if (user.Username == msg.Username) { ChannelUsers.Remove(user); break; } } } if (msg.EventId == 0x01 || msg.EventId == 0x02) { BnetProduct p; if (msg.Message.Length == 0) { return; } switch (msg.Message.Substring(0, 4)) { case "RATS": p = BnetProduct.Starcraft; break; case "PXES": p = BnetProduct.BroodWar; break; case "NB2W": p = BnetProduct.Warcraft2; break; case "VD2D": p = BnetProduct.Diablo2; break; case "PX2D": p = BnetProduct.LordOfDest; break; case "3RAW": p = BnetProduct.Warcraft3; break; case "PX3W": p = BnetProduct.FrozenThrone; break; default: p = BnetProduct.BroodWar; break; } BnetUser usr = new BnetUser(); usr.Username = msg.Username; usr.DisplayName = msg.Username.Split('@')[0]; usr.Product = p; usr.Flags = msg.Flags; ChannelUsers.Add(usr); } if (msg.EventId == 0x09) { // Process flag update foreach (var user in ChannelUsers) { if (user.Username == msg.Username) { user.Flags = msg.Flags; break; } } } } }); }