void ReceivePart(IrcMessage message) { string user = message.ExtractUser(); users.Remove(user); UserLeft?.Invoke(this, user); }
private async Task DiscordShardedClientOnUserLeft(SocketGuildUser arg) { if (UserLeft != null) { await UserLeft.Invoke(this, arg).ConfigureAwait(false); } }
public void LoadEvents() { Client.UserJoined += async(u) => { Task.Run(() => UserJoin?.Invoke(new RuntimeUser(u))); }; Client.UserLeft += async(u) => { Task.Run(() => UserLeft?.Invoke(new RuntimeUser(u))); }; Client.UserUpdated += async(u, unew) => { RuntimeUser userOld = new RuntimeUser(u); RuntimeUser userNew = new RuntimeUser(unew); Task.Run(() => UserUpdated?.Invoke(userOld, userNew)); }; Client.MessageReceived += async(m) => { RuntimeMessage newMessage = new RuntimeMessage(m); if (MessageReceived != null) { await MessageReceived.Invoke(newMessage); } }; Client.JoinedGuild += async(g) => { Task.Run(async() => { RuntimeGuild guild = new RuntimeGuild(g); await GuildJoin?.Invoke(guild); }); }; Client.LeftGuild += async(g) => { RuntimeGuild guild = new RuntimeGuild(g); await GuildLeave?.Invoke(guild); }; foreach (var shard in Client.Shards) { shard.Disconnected += async(ex) => { await OnShardDisconnect?.Invoke(ex, shard.ShardId); }; shard.Connected += async() => { if (OnShardConnect != null) { await OnShardConnect.Invoke(shard.ShardId); } }; } }
public void RemoveUser(string sid) { var user = joinedUsers.FirstOrDefault(x => x.Id == sid); if (user != null) { joinedUsers.Remove(user); UserLeft?.Invoke(user); } }
private void _TwitchClient_OnUserLeft(object sender, OnUserLeftArgs e) { UserLeft?.Invoke(this, new ChatUserInfoEventArgs { ChannelId = 0, ServiceName = "Twitch", UserId = 0, UserName = e.Username }); }
public void RemoveUser(string sid) { var findedUser = _joinedUsersList.SingleOrDefault(item => item.Id == sid); if (findedUser != null) { _joinedUsersList.Remove(findedUser); UserLeft?.Invoke(findedUser); } }
public void OnUserLeft(string userName) { if (users.Remove(userName)) { if (notifyOnUserListChange) { AddMessage(new ChatMessage(userName + " has left from " + UIName + ".")); } UserLeft?.Invoke(this, new UserNameEventArgs(userName)); } }
void OnUserLeft(ChatChannel twitchchannel, string user) { try { UserLeft?.Invoke(this, new UserInformation { Service = Service, Username = user }); } catch (Exception e) { Logger.Error(this, "Error triggering UserLeft event", e); } }
public void OnUserLeft(string userName) { int index = users.FindIndex(u => u.IRCUser.Name == userName); if (index == -1) { return; } if (notifyOnUserListChange) { AddMessage(new ChatMessage(userName + " has left from " + UIName + ".")); } users.RemoveAt(index); UserLeft?.Invoke(this, new UserNameIndexEventArgs(index, userName)); }
public void LoadEvents() { Client.UserJoined += async(u) => { await MeruUtils.TryAsync(async() => { Task.Run(() => UserJoin?.Invoke(new RuntimeUser(u))); }); }; Client.UserLeft += async(u) => { await MeruUtils.TryAsync(async() => { Task.Run(() => UserLeft?.Invoke(new RuntimeUser(u))); }); }; Client.UserUpdated += async(u, unew) => { RuntimeUser userOld = new RuntimeUser(u); RuntimeUser userNew = new RuntimeUser(unew); Task.Run(() => UserUpdated?.Invoke(userOld, userNew)); }; Client.MessageReceived += async(m) => { Task.Run(async() => { await MeruUtils.TryAsync(async() => { RuntimeMessage newMessage = new RuntimeMessage(m); await MessageReceived?.Invoke(newMessage); }); }); }; }
internal async Task OnUserLeft(SocketGuildUser user) => await(UserLeft?.Invoke(user) ?? Task.CompletedTask);
protected void OnUserLeft(UserInfo userInfo, string channel) { UserLeft?.Invoke(userInfo, channel); }
public static void ProcessResponse(string Json) { if (!active) { return; } RequestObject req = JsonConvert.DeserializeObject <RequestObject>(Json); switch (req.Module) { case "admin": switch (req.Cmd) { case "ban": string msg = "You got banned "; if (req.Args != null) { msg += "till " + req.Args.ToString(); } else { msg += "permanently"; } Banned?.Invoke(msg); break; case "unban": msg = "You got Unbanned"; Unbanned?.Invoke(msg); break; } break; case "info": if (req.Cmd == "all") { RoomObj[] rooms = JsonConvert.DeserializeObject <RoomObj[]>(req.Args.ToString()); if (rooms.Length > 0) { roomDataReceived(rooms); } } break; case "login": switch (req.Cmd) { case "user": loginSuccessfull?.Invoke((string)req.Args); break; case "admin": loggedAsAdmin?.Invoke((string)req.Args); break; case "banned": loggedBanned?.Invoke((string)req.Args); break; default: loginFail?.Invoke((string)req.Args); break; } break; case "msg": switch (req.Cmd) { case "msg": object[] args = JsonConvert.DeserializeObject <object[]>(req.Args.ToString()); ChatMessage m = JsonConvert.DeserializeObject <ChatMessage>(args[1].ToString()); m.TimeStamp = m.TimeStamp.ToLocalTime(); messageRecieived?.Invoke((string)args[0], m); break; case "active": args = JsonConvert.DeserializeObject <object[]>(req.Args.ToString()); RoomHistoryReceived?.Invoke((string)args[0], JsonConvert.DeserializeObject <ChatMessage[]>(args[1].ToString())); break; case "notify": notificationReceived?.Invoke((string)req.Args); break; case "entered": args = JsonConvert.DeserializeObject <string[]>(req.Args.ToString()); UserEntered?.Invoke((string)args[0], (string)args[1]); break; case "left": args = JsonConvert.DeserializeObject <string[]>(req.Args.ToString()); UserLeft?.Invoke((string)args[0], (string)args[1]); break; } break; case "private": privateMessageReceived?.Invoke(JsonConvert.DeserializeObject <ChatMessage>(req.Args.ToString())); break; case "room": switch (req.Cmd) { case "created": Dictionary <string, string> kv_args = JsonConvert.DeserializeObject <Dictionary <string, string> >(req.Args.ToString()); string roomname = kv_args["Name"]; string creator = kv_args["creator"]; roomCreated?.Invoke(roomname, creator); break; case "removed": roomRemoved?.Invoke((string)req.Args); break; default: roomError?.Invoke((string)req.Args); break; } break; case "history": switch (req.Cmd) { case "room": object[] args = JsonConvert.DeserializeObject <object[]>(req.Args.ToString()); ChatMessage[] history = JsonConvert.DeserializeObject <ChatMessage[]>(args[1].ToString()); foreach (ChatMessage msg in history) { msg.TimeStamp = msg.TimeStamp.ToLocalTime(); } RoomHistoryReceived?.Invoke((string)args[0], history); break; case "private": args = JsonConvert.DeserializeObject <object[]>(req.Args.ToString()); string user = args[0].ToString(); history = JsonConvert.DeserializeObject <ChatMessage[]>(args[1].ToString()); foreach (ChatMessage msg in history) { msg.TimeStamp = msg.TimeStamp.ToLocalTime(); } PrivateHistoryReceived?.Invoke(user, history); break; default: break; } break; } }
/// <summary> /// Raises the <see cref="UserLeft"/> event. /// </summary> /// <param name="e">The <see cref="EventArgs"/> instance holding the event data.</param> internal void OnUserLeft(IrcUserEventArgs e) { UserLeft?.Invoke(this, e); }
private void HandleUserData(string sender, string[] content, string data) { var username = sender.Substring(0, sender.IndexOf('!')); if (!_cachedUsers.TryGetValue(username, out var user)) { user = new User(this) { Username = username }; _cachedUsers.TryAdd(username, user); } switch (content[0]) { case "JOIN": { if (!_cachedChannels.TryGetValue(content[1], out var channel)) { channel = new Channel(this) { Name = content[1] }; _cachedChannels.TryAdd(content[1], channel); Send($"MODE {channel.Name}"); Send($"NAMES {channel.Name}"); Send($"MODE {channel.Name} +b"); } var channelUser = new ChannelUser(this, user, channel); if (channel._users.All(x => x != user)) { channel._users.Add(channelUser); } if (user._channels.All(x => x != channel)) { user._channels.Add(channel); } UserJoined?.Invoke(new UserJoinedEventArgs { Client = this, CurrentUser = CurrentUser, Channel = channel, User = channelUser }); return; } case "PART": { var channelName = content[1]; if (channelName.StartsWith(':')) { channelName = channelName.Substring(1); } if (!_cachedChannels.TryGetValue(channelName, out var channel)) { channel = new Channel(this) { Name = channelName }; _cachedChannels.TryAdd(channelName, channel); } if (user._channels.Any(x => x == channel)) { user._channels.Remove(channel); } if (channel._users.Any(x => x == user)) { channel._users.RemoveAll(x => x == user); } UserLeft?.Invoke(new UserLeftEventArgs { Client = this, CurrentUser = CurrentUser, Channel = channel, User = user, Reason = content.Length > 2 ? data.Substring(data.IndexOf(':') + 1) : "" }); return; } case "QUIT": { _cachedUsers.TryRemove(user.Username, out _); foreach (var channel in _cachedChannels.Values) { channel._users.RemoveAll(x => x == user); } var reason = ""; var idof = data.IndexOf(':'); if (idof != -1) { reason = data.Substring(idof + 1); } UserQuit?.Invoke(new UserQuitEventArgs { Client = this, CurrentUser = CurrentUser, User = user, Reason = reason }); return; } case "NICK": { _cachedUsers.TryRemove(user.Username, out var oldUser); user.Username = content[1].Substring(1); _cachedUsers.TryRemove(user.Username, out _); _cachedUsers.TryAdd(user.Username, user); NicknameChanged?.Invoke(new NicknameChangedEventArgs { Client = this, CurrentUser = CurrentUser, User = user, OldUsername = oldUser.Username, NewUsername = user.Username }); return; } case "PRIVMSG": { var cnt = data.Substring(1); var message = cnt.Substring(cnt.IndexOf(':') + 1); if (!user._channelMessages.TryGetValue(content[1], out var list)) { list = new List <string> { message }; user._channelMessages.TryAdd(content[1], list); } else { list.Add(message); } if (content[1][0] == '#') { if (!_cachedChannels.TryGetValue(content[1], out var channel)) { channel = new Channel(this) { Name = content[1] }; _cachedChannels.TryAdd(content[1], channel); } channel._messages.Add((user, message)); MessageReceived?.Invoke(new MessageReceivedEventArgs { Client = this, Channel = channel, CurrentUser = CurrentUser, Message = message, User = channel.Users.FirstOrDefault(x => x == user) ?? user }); return; } MessageReceived?.Invoke(new MessageReceivedEventArgs { Client = this, Channel = null, CurrentUser = CurrentUser, Message = message, User = user }); return; } case "NOTICE": { var message = data.Substring(data.IndexOf(':') + 1); if (!user._channelMessages.TryGetValue(content[1], out var list)) { list = new List <string> { message }; user._channelMessages.TryAdd(content[1], list); } else { list.Add(message); } NoticeReceived?.Invoke(new NoticeReceivedEventArgs { Client = this, CurrentUser = CurrentUser, Message = message, User = user }); return; } case "MODE": { if (!_cachedChannels.TryGetValue(content[1], out var channel)) { channel = new Channel(this) { Name = content[1] }; _cachedChannels.TryAdd(content[1], channel); } var iofplus = content[2].IndexOf('+'); var iofminus = content[2].IndexOf('-'); var modesPlus = Array.Empty <char>(); var modesMinus = Array.Empty <char>(); if (iofplus != -1) { modesPlus = content[2].Substring(iofplus + 1).ToCharArray(); } if (iofminus != -1) { modesMinus = iofplus != -1 ? content[2].Substring(iofminus + 1, content[2].Length - iofplus - 1).ToCharArray() : content[2].Substring(iofminus + 1).ToCharArray(); } for (var i = 0; i < modesPlus.Length; i++) { if (!channel._modes.Contains(modesPlus[i]) && modesPlus[i] != 'b') { channel._modes.Add(modesPlus[i]); } } for (var i = 0; i < modesMinus.Length; i++) { if (!channel._modes.Contains(modesMinus[i]) && modesMinus[i] != 'b') { channel._modes.Add(modesMinus[i]); } } var complexModes = modesMinus.Where(x => _configuration.ComplexChanModes.Any(y => y == x && x != 'l')).ToList(); complexModes.AddRange(modesPlus.Where(x => _configuration.ComplexChanModes.Any(y => y == x))); var extraArgs = content.Skip(3).ToList(); var modesArgs = new Dictionary <char, (char, string)>(); for (var i = 0; i < complexModes.Count && i < extraArgs.Count; i++) { modesArgs.Add(complexModes[i], (modesMinus.Contains(complexModes[i]) ? '-' : '+', extraArgs[i])); } foreach (var complexMod in modesArgs) { switch (complexMod.Key) { case 'b': if (complexMod.Value.Item1 == '-') { channel._banList.RemoveWhere(x => x.Host == complexMod.Value.Item2); } else { channel._banList.Add(new ChannelBan { IssuedBy = user.Username, Host = complexMod.Value.Item2, IssuedOn = DateTimeOffset.UtcNow }); } break; case 'l': channel.Limit = int.Parse(complexMod.Value.Item2); break; case 'k': channel.Key = complexMod.Value.Item1 == '+' ? complexMod.Value.Item2 : ""; break; } } ChannelModeUpdated?.Invoke(new ChannelModesUpdatedEventArgs { Client = this, CurrentUser = CurrentUser, Channel = channel, ModesAdded = new ReadOnlyCollection <char>(modesPlus), ModesRemoved = new ReadOnlyCollection <char>(modesMinus), ModesArgs = new ReadOnlyDictionary <char, (char, string)>(modesArgs), User = channel.Users.FirstOrDefault(x => x == user) }); return; }
public override void Update(IEnumerable <Body> bodies) { base.Update(bodies); var trackingIds = new HashSet <ulong>(); foreach (var body in bodies) { if (body.IsTracked) { trackingIds.Add(body.TrackingId); } } var currentCount = trackingIds.Count; var previousCount = _trackingIds.Count; if (currentCount != previousCount) { _consecutiveFrames++; if (_consecutiveFrames >= WindowSize) { // The users that entered or left. var users = new HashSet <ulong>(); if (currentCount > previousCount) { // ONE OR MORE USERS ENTERED foreach (var id in trackingIds) { if (!_trackingIds.Contains(id)) { users.Add(id); } } _args.Users = users; UserEntered?.Invoke(this, _args); } else { // ONE OR MORE USERS LEFT foreach (var id in _trackingIds) { if (!trackingIds.Contains(id)) { users.Add(id); } } _args.Users = users; UserLeft?.Invoke(this, _args); } _trackingIds = trackingIds; _consecutiveFrames = 0; } } }
void OnChannelUserLeft(IChatChannel channel, UserInformation information) { UserLeft?.Invoke(information); }
private void DataReceived(object o, MessageEventArgs e) { string originNick; var commands = e.message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Servers like to send commands split in separate messages if (lastMessage != null) { commands[0] = lastMessage + commands[0]; } if (!e.message.EndsWith("\n")) { lastMessage = commands[commands.Length - 1]; commands = commands.Take(commands.Length - 1).ToArray(); } else { lastMessage = null; } foreach (var command in commands) { Console.WriteLine(command); var message = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (message[0].Contains('!')) { originNick = message[0].Substring(1, message[0].IndexOf('!') - 1); } else { originNick = message[0].Substring(1); } if (message.Length > 1) { if (message[0].Equals("PING")) { MsgPong(message[1]); } switch (message[1][0]) { //Successful connection case '0': Connected?.Invoke(this, new EventArgs()); break; //ERR message case '4': Error?.Invoke(this, new MessageEventArgs(command.Substring(command.LastIndexOf(':') + 1))); break; } switch (message[1]) { case "353": AddUsers(command); break; //End of names list, guaranteed to get after joining channel case "366": JoinChannel(command); break; case "PART": if (originNick.Equals(nick)) { LeftChannel?.Invoke(this, new MessageEventArgs(command.Substring(command.IndexOf('#')))); } else { UserLeft?.Invoke(this, new ChannelEventArgs(command.Substring(command.IndexOf('#') + 1), originNick)); } break; case "JOIN": if (originNick != nick) { UserJoined?.Invoke(this, new ChannelEventArgs(command.Substring(command.IndexOf('#')), originNick)); } break; case "PRIVMSG": ReceivedMessage?.Invoke(this, new PrivateMessageEventArgs(message[2], originNick, command.Substring(1 + command.IndexOf(':', command.IndexOf("PRIVMSG"))))); break; } } } }